@@ -168,9 +168,9 @@ static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
168168 if (HasUnnamedType) {
169169 assert (M && " unnamed types need a module" );
170170 if (!FT)
171- FT = Intrinsic::getType (M-> getContext () , Id, Tys);
171+ FT = Intrinsic::getType (M, Id, Tys);
172172 else
173- assert ((FT == Intrinsic::getType (M-> getContext () , Id, Tys)) &&
173+ assert ((FT == Intrinsic::getType (M, Id, Tys)) &&
174174 " Provided FunctionType must match arguments" );
175175 return M->getUniqueIntrinsicName (Result, Id, FT);
176176 }
@@ -212,6 +212,9 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
212212 case IIT_Done:
213213 OutputTable.push_back (IITDescriptor::get (IITDescriptor::Void, 0 ));
214214 return ;
215+ case IIT_BYTE:
216+ OutputTable.push_back (IITDescriptor::get (IITDescriptor::Byte, 0 ));
217+ return ;
215218 case IIT_VARARG:
216219 OutputTable.push_back (IITDescriptor::get (IITDescriptor::VarArg, 0 ));
217220 return ;
@@ -499,7 +502,8 @@ void Intrinsic::getIntrinsicInfoTableEntries(
499502}
500503
501504static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
502- ArrayRef<Type *> Tys, LLVMContext &Context) {
505+ ArrayRef<Type *> Tys, LLVMContext &Context,
506+ const DataLayout &DL) {
503507 using namespace Intrinsic ;
504508
505509 IITDescriptor D = Infos.front ();
@@ -508,6 +512,8 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
508512 switch (D.Kind ) {
509513 case IITDescriptor::Void:
510514 return Type::getVoidTy (Context);
515+ case IITDescriptor::Byte:
516+ return Type::getIntNTy (Context, DL.getByteWidth ());
511517 case IITDescriptor::VarArg:
512518 return Type::getVoidTy (Context);
513519 case IITDescriptor::MMX:
@@ -536,14 +542,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
536542 case IITDescriptor::Integer:
537543 return IntegerType::get (Context, D.Integer_Width );
538544 case IITDescriptor::Vector:
539- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
545+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
540546 D.Vector_Width );
541547 case IITDescriptor::Pointer:
542548 return PointerType::get (Context, D.Pointer_AddressSpace );
543549 case IITDescriptor::Struct: {
544550 SmallVector<Type *, 8 > Elts;
545551 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
546- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
552+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
547553 return StructType::get (Context, Elts);
548554 }
549555 case IITDescriptor::Argument:
@@ -582,7 +588,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
582588 cast<VectorType>(Tys[D.getArgumentNumber ()]),
583589 3 + (D.Kind - IITDescriptor::OneThirdVecArgument) * 2 );
584590 case IITDescriptor::SameVecWidthArgument: {
585- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
591+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
586592 Type *Ty = Tys[D.getArgumentNumber ()];
587593 if (auto *VTy = dyn_cast<VectorType>(Ty))
588594 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -607,17 +613,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
607613 llvm_unreachable (" unhandled" );
608614}
609615
610- FunctionType *Intrinsic::getType (LLVMContext &Context, ID id,
611- ArrayRef<Type *> Tys) {
616+ FunctionType *Intrinsic::getType (Module *M, ID id, ArrayRef<Type *> Tys) {
612617 SmallVector<IITDescriptor, 8 > Table;
613618 getIntrinsicInfoTableEntries (id, Table);
614619
615620 ArrayRef<IITDescriptor> TableRef = Table;
616- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
621+ Type *ResultTy =
622+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
617623
618624 SmallVector<Type *, 8 > ArgTys;
619625 while (!TableRef.empty ())
620- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
626+ ArgTys.push_back (
627+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
621628
622629 // DecodeFixedType returns Void for IITDescriptor::Void and
623630 // IITDescriptor::VarArg If we see void type as the type of the last argument,
@@ -766,7 +773,7 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
766773 ArrayRef<Type *> Tys) {
767774 // There can never be multiple globals with the same name of different types,
768775 // because intrinsics must be a specific type.
769- auto *FT = getType (M-> getContext () , id, Tys);
776+ auto *FT = getType (M, id, Tys);
770777 return cast<Function>(
771778 M->getOrInsertFunction (
772779 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -821,7 +828,8 @@ using DeferredIntrinsicMatchPair =
821828 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
822829
823830static bool
824- matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
831+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
832+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
825833 SmallVectorImpl<Type *> &ArgTys,
826834 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
827835 bool IsDeferredCheck) {
@@ -844,6 +852,8 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
844852 switch (D.Kind ) {
845853 case IITDescriptor::Void:
846854 return !Ty->isVoidTy ();
855+ case IITDescriptor::Byte:
856+ return !Ty->isIntegerTy (DL.getByteWidth ());
847857 case IITDescriptor::VarArg:
848858 return true ;
849859 case IITDescriptor::MMX: {
@@ -877,7 +887,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
877887 case IITDescriptor::Vector: {
878888 VectorType *VT = dyn_cast<VectorType>(Ty);
879889 return !VT || VT->getElementCount () != D.Vector_Width ||
880- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
890+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
881891 DeferredChecks, IsDeferredCheck);
882892 }
883893 case IITDescriptor::Pointer: {
@@ -892,7 +902,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
892902 return true ;
893903
894904 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
895- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
905+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
896906 DeferredChecks, IsDeferredCheck))
897907 return true ;
898908 return false ;
@@ -992,7 +1002,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
9921002 return true ;
9931003 EltTy = ThisArgType->getElementType ();
9941004 }
995- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
1005+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
9961006 IsDeferredCheck);
9971007 }
9981008 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -1056,24 +1066,24 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
10561066}
10571067
10581068Intrinsic::MatchIntrinsicTypesResult
1059- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1069+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
10601070 ArrayRef<Intrinsic::IITDescriptor> &Infos,
10611071 SmallVectorImpl<Type *> &ArgTys) {
10621072 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1063- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1064- false ))
1073+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1074+ DeferredChecks, false ))
10651075 return MatchIntrinsicTypes_NoMatchRet;
10661076
10671077 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
10681078
10691079 for (auto *Ty : FTy->params ())
1070- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1080+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
10711081 return MatchIntrinsicTypes_NoMatchArg;
10721082
10731083 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
10741084 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1075- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1076- true ))
1085+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1086+ DeferredChecks, true ))
10771087 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
10781088 : MatchIntrinsicTypes_NoMatchArg;
10791089 }
@@ -1100,7 +1110,8 @@ bool Intrinsic::matchIntrinsicVarArg(
11001110 return true ;
11011111}
11021112
1103- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1113+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1114+ FunctionType *FT,
11041115 SmallVectorImpl<Type *> &ArgTys) {
11051116 if (!ID)
11061117 return false ;
@@ -1109,7 +1120,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
11091120 getIntrinsicInfoTableEntries (ID, Table);
11101121 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
11111122
1112- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1123+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
11131124 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
11141125 return false ;
11151126 }
@@ -1120,8 +1131,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
11201131
11211132bool Intrinsic::getIntrinsicSignature (Function *F,
11221133 SmallVectorImpl<Type *> &ArgTys) {
1123- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1124- ArgTys);
1134+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1135+ F-> getFunctionType (), ArgTys);
11251136}
11261137
11271138std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments