@@ -169,9 +169,9 @@ static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
169169 if (HasUnnamedType) {
170170 assert (M && " unnamed types need a module" );
171171 if (!FT)
172- FT = Intrinsic::getType (M-> getContext () , Id, Tys);
172+ FT = Intrinsic::getType (M, Id, Tys);
173173 else
174- assert ((FT == Intrinsic::getType (M-> getContext () , Id, Tys)) &&
174+ assert ((FT == Intrinsic::getType (M, Id, Tys)) &&
175175 " Provided FunctionType must match arguments" );
176176 return M->getUniqueIntrinsicName (Result, Id, FT);
177177 }
@@ -213,6 +213,9 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
213213 case IIT_Done:
214214 OutputTable.push_back (IITDescriptor::get (IITDescriptor::Void, 0 ));
215215 return ;
216+ case IIT_BYTE:
217+ OutputTable.push_back (IITDescriptor::get (IITDescriptor::Byte, 0 ));
218+ return ;
216219 case IIT_VARARG:
217220 OutputTable.push_back (IITDescriptor::get (IITDescriptor::VarArg, 0 ));
218221 return ;
@@ -491,7 +494,8 @@ void Intrinsic::getIntrinsicInfoTableEntries(
491494}
492495
493496static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
494- ArrayRef<Type *> Tys, LLVMContext &Context) {
497+ ArrayRef<Type *> Tys, LLVMContext &Context,
498+ const DataLayout &DL) {
495499 using namespace Intrinsic ;
496500
497501 IITDescriptor D = Infos.front ();
@@ -500,6 +504,8 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
500504 switch (D.Kind ) {
501505 case IITDescriptor::Void:
502506 return Type::getVoidTy (Context);
507+ case IITDescriptor::Byte:
508+ return Type::getIntNTy (Context, DL.getByteWidth ());
503509 case IITDescriptor::VarArg:
504510 return Type::getVoidTy (Context);
505511 case IITDescriptor::MMX:
@@ -528,14 +534,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
528534 case IITDescriptor::Integer:
529535 return IntegerType::get (Context, D.Integer_Width );
530536 case IITDescriptor::Vector:
531- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
537+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
532538 D.Vector_Width );
533539 case IITDescriptor::Pointer:
534540 return PointerType::get (Context, D.Pointer_AddressSpace );
535541 case IITDescriptor::Struct: {
536542 SmallVector<Type *, 8 > Elts;
537543 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
538- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
544+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
539545 return StructType::get (Context, Elts);
540546 }
541547 case IITDescriptor::Argument:
@@ -568,7 +574,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
568574 return VectorType::getOneNthElementsVectorType (
569575 cast<VectorType>(Tys[D.getRefArgNumber ()]), D.getVectorDivisor ());
570576 case IITDescriptor::SameVecWidthArgument: {
571- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
577+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
572578 Type *Ty = Tys[D.getArgumentNumber ()];
573579 if (auto *VTy = dyn_cast<VectorType>(Ty))
574580 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -593,17 +599,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
593599 llvm_unreachable (" unhandled" );
594600}
595601
596- FunctionType *Intrinsic::getType (LLVMContext &Context, ID id,
597- ArrayRef<Type *> Tys) {
602+ FunctionType *Intrinsic::getType (const Module *M, ID id, ArrayRef<Type *> Tys) {
598603 SmallVector<IITDescriptor, 8 > Table;
599604 getIntrinsicInfoTableEntries (id, Table);
600605
601606 ArrayRef<IITDescriptor> TableRef = Table;
602- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
607+ Type *ResultTy =
608+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
603609
604610 SmallVector<Type *, 8 > ArgTys;
605611 while (!TableRef.empty ())
606- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
612+ ArgTys.push_back (
613+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
607614
608615 // DecodeFixedType returns Void for IITDescriptor::Void and
609616 // IITDescriptor::VarArg If we see void type as the type of the last argument,
@@ -752,7 +759,7 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
752759 ArrayRef<Type *> Tys) {
753760 // There can never be multiple globals with the same name of different types,
754761 // because intrinsics must be a specific type.
755- auto *FT = getType (M-> getContext () , id, Tys);
762+ auto *FT = getType (M, id, Tys);
756763 return cast<Function>(
757764 M->getOrInsertFunction (
758765 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -807,7 +814,8 @@ using DeferredIntrinsicMatchPair =
807814 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
808815
809816static bool
810- matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
817+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
818+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
811819 SmallVectorImpl<Type *> &ArgTys,
812820 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
813821 bool IsDeferredCheck) {
@@ -830,6 +838,8 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
830838 switch (D.Kind ) {
831839 case IITDescriptor::Void:
832840 return !Ty->isVoidTy ();
841+ case IITDescriptor::Byte:
842+ return !Ty->isIntegerTy (DL.getByteWidth ());
833843 case IITDescriptor::VarArg:
834844 return true ;
835845 case IITDescriptor::MMX: {
@@ -863,7 +873,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
863873 case IITDescriptor::Vector: {
864874 VectorType *VT = dyn_cast<VectorType>(Ty);
865875 return !VT || VT->getElementCount () != D.Vector_Width ||
866- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
876+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
867877 DeferredChecks, IsDeferredCheck);
868878 }
869879 case IITDescriptor::Pointer: {
@@ -878,7 +888,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
878888 return true ;
879889
880890 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
881- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
891+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
882892 DeferredChecks, IsDeferredCheck))
883893 return true ;
884894 return false ;
@@ -969,7 +979,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
969979 return true ;
970980 EltTy = ThisArgType->getElementType ();
971981 }
972- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
982+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
973983 IsDeferredCheck);
974984 }
975985 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -1033,24 +1043,24 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
10331043}
10341044
10351045Intrinsic::MatchIntrinsicTypesResult
1036- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1046+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
10371047 ArrayRef<Intrinsic::IITDescriptor> &Infos,
10381048 SmallVectorImpl<Type *> &ArgTys) {
10391049 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1040- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1041- false ))
1050+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1051+ DeferredChecks, false ))
10421052 return MatchIntrinsicTypes_NoMatchRet;
10431053
10441054 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
10451055
10461056 for (auto *Ty : FTy->params ())
1047- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1057+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
10481058 return MatchIntrinsicTypes_NoMatchArg;
10491059
10501060 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
10511061 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1052- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1053- true ))
1062+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1063+ DeferredChecks, true ))
10541064 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
10551065 : MatchIntrinsicTypes_NoMatchArg;
10561066 }
@@ -1077,7 +1087,8 @@ bool Intrinsic::matchIntrinsicVarArg(
10771087 return true ;
10781088}
10791089
1080- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1090+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1091+ FunctionType *FT,
10811092 SmallVectorImpl<Type *> &ArgTys) {
10821093 if (!ID)
10831094 return false ;
@@ -1086,7 +1097,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10861097 getIntrinsicInfoTableEntries (ID, Table);
10871098 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
10881099
1089- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1100+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
10901101 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
10911102 return false ;
10921103 }
@@ -1097,8 +1108,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10971108
10981109bool Intrinsic::getIntrinsicSignature (Function *F,
10991110 SmallVectorImpl<Type *> &ArgTys) {
1100- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1101- ArgTys);
1111+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1112+ F-> getFunctionType (), ArgTys);
11021113}
11031114
11041115std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments