@@ -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 }
@@ -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 ;
@@ -471,7 +474,8 @@ void Intrinsic::getIntrinsicInfoTableEntries(
471474}
472475
473476static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
474- ArrayRef<Type *> Tys, LLVMContext &Context) {
477+ ArrayRef<Type *> Tys, LLVMContext &Context,
478+ const DataLayout &DL) {
475479 using namespace Intrinsic ;
476480
477481 IITDescriptor D = Infos.front ();
@@ -480,6 +484,8 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
480484 switch (D.Kind ) {
481485 case IITDescriptor::Void:
482486 return Type::getVoidTy (Context);
487+ case IITDescriptor::Byte:
488+ return Type::getIntNTy (Context, DL.getByteWidth ());
483489 case IITDescriptor::VarArg:
484490 return Type::getVoidTy (Context);
485491 case IITDescriptor::MMX:
@@ -508,14 +514,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
508514 case IITDescriptor::Integer:
509515 return IntegerType::get (Context, D.Integer_Width );
510516 case IITDescriptor::Vector:
511- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
517+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
512518 D.Vector_Width );
513519 case IITDescriptor::Pointer:
514520 return PointerType::get (Context, D.Pointer_AddressSpace );
515521 case IITDescriptor::Struct: {
516522 SmallVector<Type *, 8 > Elts;
517523 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
518- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
524+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
519525 return StructType::get (Context, Elts);
520526 }
521527 case IITDescriptor::Argument:
@@ -548,7 +554,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
548554 return VectorType::getOneNthElementsVectorType (
549555 cast<VectorType>(Tys[D.getRefArgNumber ()]), D.getVectorDivisor ());
550556 case IITDescriptor::SameVecWidthArgument: {
551- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
557+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
552558 Type *Ty = Tys[D.getArgumentNumber ()];
553559 if (auto *VTy = dyn_cast<VectorType>(Ty))
554560 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -573,17 +579,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
573579 llvm_unreachable (" unhandled" );
574580}
575581
576- FunctionType *Intrinsic::getType (LLVMContext &Context, ID id,
577- ArrayRef<Type *> Tys) {
582+ FunctionType *Intrinsic::getType (const Module *M, ID id, ArrayRef<Type *> Tys) {
578583 SmallVector<IITDescriptor, 8 > Table;
579584 getIntrinsicInfoTableEntries (id, Table);
580585
581586 ArrayRef<IITDescriptor> TableRef = Table;
582- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
587+ Type *ResultTy =
588+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
583589
584590 SmallVector<Type *, 8 > ArgTys;
585591 while (!TableRef.empty ())
586- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
592+ ArgTys.push_back (
593+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
587594
588595 // DecodeFixedType returns Void for IITDescriptor::Void and
589596 // IITDescriptor::VarArg If we see void type as the type of the last argument,
@@ -724,7 +731,7 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
724731 ArrayRef<Type *> Tys) {
725732 // There can never be multiple globals with the same name of different types,
726733 // because intrinsics must be a specific type.
727- auto *FT = getType (M-> getContext () , id, Tys);
734+ auto *FT = getType (M, id, Tys);
728735 Function *F = cast<Function>(
729736 M->getOrInsertFunction (
730737 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -792,7 +799,8 @@ using DeferredIntrinsicMatchPair =
792799 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
793800
794801static bool
795- matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
802+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
803+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
796804 SmallVectorImpl<Type *> &ArgTys,
797805 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
798806 bool IsDeferredCheck) {
@@ -815,6 +823,8 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
815823 switch (D.Kind ) {
816824 case IITDescriptor::Void:
817825 return !Ty->isVoidTy ();
826+ case IITDescriptor::Byte:
827+ return !Ty->isIntegerTy (DL.getByteWidth ());
818828 case IITDescriptor::VarArg:
819829 return true ;
820830 case IITDescriptor::MMX: {
@@ -848,7 +858,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
848858 case IITDescriptor::Vector: {
849859 VectorType *VT = dyn_cast<VectorType>(Ty);
850860 return !VT || VT->getElementCount () != D.Vector_Width ||
851- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
861+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
852862 DeferredChecks, IsDeferredCheck);
853863 }
854864 case IITDescriptor::Pointer: {
@@ -863,7 +873,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
863873 return true ;
864874
865875 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
866- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
876+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
867877 DeferredChecks, IsDeferredCheck))
868878 return true ;
869879 return false ;
@@ -954,7 +964,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
954964 return true ;
955965 EltTy = ThisArgType->getElementType ();
956966 }
957- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
967+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
958968 IsDeferredCheck);
959969 }
960970 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -1018,24 +1028,24 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
10181028}
10191029
10201030Intrinsic::MatchIntrinsicTypesResult
1021- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1031+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
10221032 ArrayRef<Intrinsic::IITDescriptor> &Infos,
10231033 SmallVectorImpl<Type *> &ArgTys) {
10241034 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1025- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1026- false ))
1035+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1036+ DeferredChecks, false ))
10271037 return MatchIntrinsicTypes_NoMatchRet;
10281038
10291039 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
10301040
10311041 for (auto *Ty : FTy->params ())
1032- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1042+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
10331043 return MatchIntrinsicTypes_NoMatchArg;
10341044
10351045 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
10361046 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1037- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1038- true ))
1047+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1048+ DeferredChecks, true ))
10391049 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
10401050 : MatchIntrinsicTypes_NoMatchArg;
10411051 }
@@ -1062,7 +1072,8 @@ bool Intrinsic::matchIntrinsicVarArg(
10621072 return true ;
10631073}
10641074
1065- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1075+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1076+ FunctionType *FT,
10661077 SmallVectorImpl<Type *> &ArgTys) {
10671078 if (!ID)
10681079 return false ;
@@ -1071,7 +1082,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10711082 getIntrinsicInfoTableEntries (ID, Table);
10721083 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
10731084
1074- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1085+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
10751086 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
10761087 return false ;
10771088 }
@@ -1082,8 +1093,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10821093
10831094bool Intrinsic::getIntrinsicSignature (Function *F,
10841095 SmallVectorImpl<Type *> &ArgTys) {
1085- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1086- ArgTys);
1096+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1097+ F-> getFunctionType (), ArgTys);
10871098}
10881099
10891100std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments