@@ -172,9 +172,9 @@ static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
172172 if (HasUnnamedType) {
173173 assert (M && " unnamed types need a module" );
174174 if (!FT)
175- FT = Intrinsic::getType (M-> getContext () , Id, Tys);
175+ FT = Intrinsic::getType (M, Id, Tys);
176176 else
177- assert ((FT == Intrinsic::getType (M-> getContext () , Id, Tys)) &&
177+ assert ((FT == Intrinsic::getType (M, Id, Tys)) &&
178178 " Provided FunctionType must match arguments" );
179179 return M->getUniqueIntrinsicName (Result, Id, FT);
180180 }
@@ -216,6 +216,9 @@ DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
216216 case IIT_Done:
217217 OutputTable.push_back (IITDescriptor::get (IITDescriptor::Void, 0 ));
218218 return ;
219+ case IIT_BYTE:
220+ OutputTable.push_back (IITDescriptor::get (IITDescriptor::Byte, 0 ));
221+ return ;
219222 case IIT_VARARG:
220223 OutputTable.push_back (IITDescriptor::get (IITDescriptor::VarArg, 0 ));
221224 return ;
@@ -485,7 +488,8 @@ void Intrinsic::getIntrinsicInfoTableEntries(
485488}
486489
487490static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
488- ArrayRef<Type *> Tys, LLVMContext &Context) {
491+ ArrayRef<Type *> Tys, LLVMContext &Context,
492+ const DataLayout &DL) {
489493 using namespace Intrinsic ;
490494
491495 IITDescriptor D = Infos.front ();
@@ -494,6 +498,8 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
494498 switch (D.Kind ) {
495499 case IITDescriptor::Void:
496500 return Type::getVoidTy (Context);
501+ case IITDescriptor::Byte:
502+ return Type::getIntNTy (Context, DL.getByteWidth ());
497503 case IITDescriptor::VarArg:
498504 return Type::getVoidTy (Context);
499505 case IITDescriptor::MMX:
@@ -522,14 +528,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
522528 case IITDescriptor::Integer:
523529 return IntegerType::get (Context, D.Integer_Width );
524530 case IITDescriptor::Vector:
525- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
531+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
526532 D.Vector_Width );
527533 case IITDescriptor::Pointer:
528534 return PointerType::get (Context, D.Pointer_AddressSpace );
529535 case IITDescriptor::Struct: {
530536 SmallVector<Type *, 8 > Elts;
531537 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
532- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
538+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
533539 return StructType::get (Context, Elts);
534540 }
535541 case IITDescriptor::Argument:
@@ -562,7 +568,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
562568 return VectorType::getHalfElementsVectorType (
563569 cast<VectorType>(Tys[D.getArgumentNumber ()]));
564570 case IITDescriptor::SameVecWidthArgument: {
565- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
571+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
566572 Type *Ty = Tys[D.getArgumentNumber ()];
567573 if (auto *VTy = dyn_cast<VectorType>(Ty))
568574 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -587,17 +593,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
587593 llvm_unreachable (" unhandled" );
588594}
589595
590- FunctionType *Intrinsic::getType (LLVMContext &Context, ID id,
591- ArrayRef<Type *> Tys) {
596+ FunctionType *Intrinsic::getType (Module *M, ID id, ArrayRef<Type *> Tys) {
592597 SmallVector<IITDescriptor, 8 > Table;
593598 getIntrinsicInfoTableEntries (id, Table);
594599
595600 ArrayRef<IITDescriptor> TableRef = Table;
596- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
601+ Type *ResultTy =
602+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
597603
598604 SmallVector<Type *, 8 > ArgTys;
599605 while (!TableRef.empty ())
600- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
606+ ArgTys.push_back (
607+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
601608
602609 // DecodeFixedType returns Void for IITDescriptor::Void and
603610 // IITDescriptor::VarArg If we see void type as the type of the last argument,
@@ -717,7 +724,7 @@ Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
717724 ArrayRef<Type *> Tys) {
718725 // There can never be multiple globals with the same name of different types,
719726 // because intrinsics must be a specific type.
720- auto *FT = getType (M-> getContext () , id, Tys);
727+ auto *FT = getType (M, id, Tys);
721728 return cast<Function>(
722729 M->getOrInsertFunction (
723730 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -772,7 +779,8 @@ using DeferredIntrinsicMatchPair =
772779 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
773780
774781static bool
775- matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
782+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
783+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
776784 SmallVectorImpl<Type *> &ArgTys,
777785 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
778786 bool IsDeferredCheck) {
@@ -795,6 +803,8 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
795803 switch (D.Kind ) {
796804 case IITDescriptor::Void:
797805 return !Ty->isVoidTy ();
806+ case IITDescriptor::Byte:
807+ return !Ty->isIntegerTy (DL.getByteWidth ());
798808 case IITDescriptor::VarArg:
799809 return true ;
800810 case IITDescriptor::MMX: {
@@ -828,7 +838,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
828838 case IITDescriptor::Vector: {
829839 VectorType *VT = dyn_cast<VectorType>(Ty);
830840 return !VT || VT->getElementCount () != D.Vector_Width ||
831- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
841+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
832842 DeferredChecks, IsDeferredCheck);
833843 }
834844 case IITDescriptor::Pointer: {
@@ -843,7 +853,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
843853 return true ;
844854
845855 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
846- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
856+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
847857 DeferredChecks, IsDeferredCheck))
848858 return true ;
849859 return false ;
@@ -933,7 +943,7 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
933943 return true ;
934944 EltTy = ThisArgType->getElementType ();
935945 }
936- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
946+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
937947 IsDeferredCheck);
938948 }
939949 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -997,24 +1007,24 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
9971007}
9981008
9991009Intrinsic::MatchIntrinsicTypesResult
1000- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1010+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
10011011 ArrayRef<Intrinsic::IITDescriptor> &Infos,
10021012 SmallVectorImpl<Type *> &ArgTys) {
10031013 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1004- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1005- false ))
1014+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1015+ DeferredChecks, false ))
10061016 return MatchIntrinsicTypes_NoMatchRet;
10071017
10081018 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
10091019
10101020 for (auto *Ty : FTy->params ())
1011- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1021+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
10121022 return MatchIntrinsicTypes_NoMatchArg;
10131023
10141024 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
10151025 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1016- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1017- true ))
1026+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1027+ DeferredChecks, true ))
10181028 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
10191029 : MatchIntrinsicTypes_NoMatchArg;
10201030 }
@@ -1041,7 +1051,8 @@ bool Intrinsic::matchIntrinsicVarArg(
10411051 return true ;
10421052}
10431053
1044- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1054+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1055+ FunctionType *FT,
10451056 SmallVectorImpl<Type *> &ArgTys) {
10461057 if (!ID)
10471058 return false ;
@@ -1050,7 +1061,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10501061 getIntrinsicInfoTableEntries (ID, Table);
10511062 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
10521063
1053- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1064+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
10541065 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
10551066 return false ;
10561067 }
@@ -1061,8 +1072,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
10611072
10621073bool Intrinsic::getIntrinsicSignature (Function *F,
10631074 SmallVectorImpl<Type *> &ArgTys) {
1064- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1065- ArgTys);
1075+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1076+ F-> getFunctionType (), ArgTys);
10661077}
10671078
10681079std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments