@@ -167,9 +167,9 @@ static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
167167 if (HasUnnamedType) {
168168 assert (M && " unnamed types need a module" );
169169 if (!FT)
170- FT = Intrinsic::getType (M-> getContext () , Id, Tys);
170+ FT = Intrinsic::getType (M, Id, Tys);
171171 else
172- assert ((FT == Intrinsic::getType (M-> getContext () , Id, Tys)) &&
172+ assert ((FT == Intrinsic::getType (M, Id, Tys)) &&
173173 " Provided FunctionType must match arguments" );
174174 return M->getUniqueIntrinsicName (Result, Id, FT);
175175 }
@@ -211,6 +211,9 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
211211 case IIT_Done:
212212 OutputTable.push_back (IITDescriptor::get (IITDescriptor::Void, 0 ));
213213 return ;
214+ case IIT_BYTE:
215+ OutputTable.push_back (IITDescriptor::get (IITDescriptor::Byte, 0 ));
216+ return ;
214217 case IIT_VARARG:
215218 OutputTable.push_back (IITDescriptor::get (IITDescriptor::VarArg, 0 ));
216219 return ;
@@ -480,7 +483,8 @@ void Intrinsic::getIntrinsicInfoTableEntries(
480483}
481484
482485static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
483- ArrayRef<Type *> Tys, LLVMContext &Context) {
486+ ArrayRef<Type *> Tys, LLVMContext &Context,
487+ const DataLayout &DL) {
484488 using namespace Intrinsic ;
485489
486490 IITDescriptor D = Infos.front ();
@@ -489,6 +493,8 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
489493 switch (D.Kind ) {
490494 case IITDescriptor::Void:
491495 return Type::getVoidTy (Context);
496+ case IITDescriptor::Byte:
497+ return Type::getIntNTy (Context, DL.getByteWidth ());
492498 case IITDescriptor::VarArg:
493499 return Type::getVoidTy (Context);
494500 case IITDescriptor::MMX:
@@ -517,14 +523,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
517523 case IITDescriptor::Integer:
518524 return IntegerType::get (Context, D.Integer_Width );
519525 case IITDescriptor::Vector:
520- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
526+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
521527 D.Vector_Width );
522528 case IITDescriptor::Pointer:
523529 return PointerType::get (Context, D.Pointer_AddressSpace );
524530 case IITDescriptor::Struct: {
525531 SmallVector<Type *, 8 > Elts;
526532 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
527- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
533+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
528534 return StructType::get (Context, Elts);
529535 }
530536 case IITDescriptor::Argument:
@@ -557,7 +563,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
557563 return VectorType::getHalfElementsVectorType (
558564 cast<VectorType>(Tys[D.getArgumentNumber ()]));
559565 case IITDescriptor::SameVecWidthArgument: {
560- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
566+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
561567 Type *Ty = Tys[D.getArgumentNumber ()];
562568 if (auto *VTy = dyn_cast<VectorType>(Ty))
563569 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -582,17 +588,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
582588 llvm_unreachable (" unhandled" );
583589}
584590
585- FunctionType *Intrinsic::getType (LLVMContext &Context, ID id,
586- ArrayRef<Type *> Tys) {
591+ FunctionType *Intrinsic::getType (Module *M, ID id, ArrayRef<Type *> Tys) {
587592 SmallVector<IITDescriptor, 8 > Table;
588593 getIntrinsicInfoTableEntries (id, Table);
589594
590595 ArrayRef<IITDescriptor> TableRef = Table;
591- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
596+ Type *ResultTy =
597+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
592598
593599 SmallVector<Type *, 8 > ArgTys;
594600 while (!TableRef.empty ())
595- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
601+ ArgTys.push_back (
602+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
596603
597604 // DecodeFixedType returns Void for IITDescriptor::Void and
598605 // IITDescriptor::VarArg If we see void type as the type of the last argument,
@@ -733,7 +740,7 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
733740 ArrayRef<Type *> Tys) {
734741 // There can never be multiple globals with the same name of different types,
735742 // because intrinsics must be a specific type.
736- auto *FT = getType (M-> getContext () , id, Tys);
743+ auto *FT = getType (M, id, Tys);
737744 return cast<Function>(
738745 M->getOrInsertFunction (
739746 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -788,7 +795,8 @@ using DeferredIntrinsicMatchPair =
788795 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
789796
790797static bool
791- matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
798+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
799+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
792800 SmallVectorImpl<Type *> &ArgTys,
793801 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
794802 bool IsDeferredCheck) {
@@ -811,6 +819,8 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
811819 switch (D.Kind ) {
812820 case IITDescriptor::Void:
813821 return !Ty->isVoidTy ();
822+ case IITDescriptor::Byte:
823+ return !Ty->isIntegerTy (DL.getByteWidth ());
814824 case IITDescriptor::VarArg:
815825 return true ;
816826 case IITDescriptor::MMX: {
@@ -844,7 +854,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
844854 case IITDescriptor::Vector: {
845855 VectorType *VT = dyn_cast<VectorType>(Ty);
846856 return !VT || VT->getElementCount () != D.Vector_Width ||
847- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
857+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
848858 DeferredChecks, IsDeferredCheck);
849859 }
850860 case IITDescriptor::Pointer: {
@@ -859,7 +869,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
859869 return true ;
860870
861871 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
862- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
872+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
863873 DeferredChecks, IsDeferredCheck))
864874 return true ;
865875 return false ;
@@ -949,7 +959,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
949959 return true ;
950960 EltTy = ThisArgType->getElementType ();
951961 }
952- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
962+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
953963 IsDeferredCheck);
954964 }
955965 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -1013,24 +1023,24 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
10131023}
10141024
10151025Intrinsic::MatchIntrinsicTypesResult
1016- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1026+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
10171027 ArrayRef<Intrinsic::IITDescriptor> &Infos,
10181028 SmallVectorImpl<Type *> &ArgTys) {
10191029 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1020- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1021- false ))
1030+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1031+ DeferredChecks, false ))
10221032 return MatchIntrinsicTypes_NoMatchRet;
10231033
10241034 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
10251035
10261036 for (auto *Ty : FTy->params ())
1027- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1037+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
10281038 return MatchIntrinsicTypes_NoMatchArg;
10291039
10301040 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
10311041 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1032- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1033- true ))
1042+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1043+ DeferredChecks, true ))
10341044 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
10351045 : MatchIntrinsicTypes_NoMatchArg;
10361046 }
@@ -1057,7 +1067,8 @@ bool Intrinsic::matchIntrinsicVarArg(
10571067 return true ;
10581068}
10591069
1060- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1070+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1071+ FunctionType *FT,
10611072 SmallVectorImpl<Type *> &ArgTys) {
10621073 if (!ID)
10631074 return false ;
@@ -1066,7 +1077,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10661077 getIntrinsicInfoTableEntries (ID, Table);
10671078 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
10681079
1069- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1080+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
10701081 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
10711082 return false ;
10721083 }
@@ -1077,8 +1088,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10771088
10781089bool Intrinsic::getIntrinsicSignature (Function *F,
10791090 SmallVectorImpl<Type *> &ArgTys) {
1080- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1081- ArgTys);
1091+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1092+ F-> getFunctionType (), ArgTys);
10821093}
10831094
10841095std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments