@@ -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 ;
@@ -498,7 +501,8 @@ void Intrinsic::getIntrinsicInfoTableEntries(
498501}
499502
500503static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
501- ArrayRef<Type *> Tys, LLVMContext &Context) {
504+ ArrayRef<Type *> Tys, LLVMContext &Context,
505+ const DataLayout &DL) {
502506 using namespace Intrinsic ;
503507
504508 IITDescriptor D = Infos.front ();
@@ -507,6 +511,8 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
507511 switch (D.Kind ) {
508512 case IITDescriptor::Void:
509513 return Type::getVoidTy (Context);
514+ case IITDescriptor::Byte:
515+ return Type::getIntNTy (Context, DL.getByteWidth ());
510516 case IITDescriptor::VarArg:
511517 return Type::getVoidTy (Context);
512518 case IITDescriptor::MMX:
@@ -535,14 +541,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
535541 case IITDescriptor::Integer:
536542 return IntegerType::get (Context, D.Integer_Width );
537543 case IITDescriptor::Vector:
538- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
544+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
539545 D.Vector_Width );
540546 case IITDescriptor::Pointer:
541547 return PointerType::get (Context, D.Pointer_AddressSpace );
542548 case IITDescriptor::Struct: {
543549 SmallVector<Type *, 8 > Elts;
544550 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
545- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
551+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
546552 return StructType::get (Context, Elts);
547553 }
548554 case IITDescriptor::Argument:
@@ -581,7 +587,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
581587 cast<VectorType>(Tys[D.getArgumentNumber ()]),
582588 3 + (D.Kind - IITDescriptor::OneThirdVecArgument) * 2 );
583589 case IITDescriptor::SameVecWidthArgument: {
584- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
590+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
585591 Type *Ty = Tys[D.getArgumentNumber ()];
586592 if (auto *VTy = dyn_cast<VectorType>(Ty))
587593 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -606,17 +612,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
606612 llvm_unreachable (" unhandled" );
607613}
608614
609- FunctionType *Intrinsic::getType (LLVMContext &Context, ID id,
610- ArrayRef<Type *> Tys) {
615+ FunctionType *Intrinsic::getType (Module *M, ID id, ArrayRef<Type *> Tys) {
611616 SmallVector<IITDescriptor, 8 > Table;
612617 getIntrinsicInfoTableEntries (id, Table);
613618
614619 ArrayRef<IITDescriptor> TableRef = Table;
615- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
620+ Type *ResultTy =
621+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
616622
617623 SmallVector<Type *, 8 > ArgTys;
618624 while (!TableRef.empty ())
619- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
625+ ArgTys.push_back (
626+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
620627
621628 // DecodeFixedType returns Void for IITDescriptor::Void and
622629 // IITDescriptor::VarArg If we see void type as the type of the last argument,
@@ -765,7 +772,7 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
765772 ArrayRef<Type *> Tys) {
766773 // There can never be multiple globals with the same name of different types,
767774 // because intrinsics must be a specific type.
768- auto *FT = getType (M-> getContext () , id, Tys);
775+ auto *FT = getType (M, id, Tys);
769776 return cast<Function>(
770777 M->getOrInsertFunction (
771778 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -820,7 +827,8 @@ using DeferredIntrinsicMatchPair =
820827 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
821828
822829static bool
823- matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
830+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
831+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
824832 SmallVectorImpl<Type *> &ArgTys,
825833 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
826834 bool IsDeferredCheck) {
@@ -843,6 +851,8 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
843851 switch (D.Kind ) {
844852 case IITDescriptor::Void:
845853 return !Ty->isVoidTy ();
854+ case IITDescriptor::Byte:
855+ return !Ty->isIntegerTy (DL.getByteWidth ());
846856 case IITDescriptor::VarArg:
847857 return true ;
848858 case IITDescriptor::MMX: {
@@ -876,7 +886,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
876886 case IITDescriptor::Vector: {
877887 VectorType *VT = dyn_cast<VectorType>(Ty);
878888 return !VT || VT->getElementCount () != D.Vector_Width ||
879- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
889+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
880890 DeferredChecks, IsDeferredCheck);
881891 }
882892 case IITDescriptor::Pointer: {
@@ -891,7 +901,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
891901 return true ;
892902
893903 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
894- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
904+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
895905 DeferredChecks, IsDeferredCheck))
896906 return true ;
897907 return false ;
@@ -991,7 +1001,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
9911001 return true ;
9921002 EltTy = ThisArgType->getElementType ();
9931003 }
994- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
1004+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
9951005 IsDeferredCheck);
9961006 }
9971007 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -1055,24 +1065,24 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
10551065}
10561066
10571067Intrinsic::MatchIntrinsicTypesResult
1058- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1068+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
10591069 ArrayRef<Intrinsic::IITDescriptor> &Infos,
10601070 SmallVectorImpl<Type *> &ArgTys) {
10611071 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1062- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1063- false ))
1072+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1073+ DeferredChecks, false ))
10641074 return MatchIntrinsicTypes_NoMatchRet;
10651075
10661076 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
10671077
10681078 for (auto *Ty : FTy->params ())
1069- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1079+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
10701080 return MatchIntrinsicTypes_NoMatchArg;
10711081
10721082 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
10731083 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1074- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1075- true ))
1084+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1085+ DeferredChecks, true ))
10761086 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
10771087 : MatchIntrinsicTypes_NoMatchArg;
10781088 }
@@ -1099,7 +1109,8 @@ bool Intrinsic::matchIntrinsicVarArg(
10991109 return true ;
11001110}
11011111
1102- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1112+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1113+ FunctionType *FT,
11031114 SmallVectorImpl<Type *> &ArgTys) {
11041115 if (!ID)
11051116 return false ;
@@ -1108,7 +1119,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
11081119 getIntrinsicInfoTableEntries (ID, Table);
11091120 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
11101121
1111- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1122+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
11121123 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
11131124 return false ;
11141125 }
@@ -1119,8 +1130,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
11191130
11201131bool Intrinsic::getIntrinsicSignature (Function *F,
11211132 SmallVectorImpl<Type *> &ArgTys) {
1122- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1123- ArgTys);
1133+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1134+ F-> getFunctionType (), ArgTys);
11241135}
11251136
11261137std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments