@@ -1118,9 +1118,9 @@ static std::string getIntrinsicNameImpl(Intrinsic::ID Id, ArrayRef<Type *> Tys,
11181118 if (HasUnnamedType) {
11191119 assert (M && " unnamed types need a module" );
11201120 if (!FT)
1121- FT = Intrinsic::getType (M-> getContext () , Id, Tys);
1121+ FT = Intrinsic::getType (M, Id, Tys);
11221122 else
1123- assert ((FT == Intrinsic::getType (M-> getContext () , Id, Tys)) &&
1123+ assert ((FT == Intrinsic::getType (M, Id, Tys)) &&
11241124 " Provided FunctionType must match arguments" );
11251125 return M->getUniqueIntrinsicName (Result, Id, FT);
11261126 }
@@ -1161,6 +1161,9 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos,
11611161 case IIT_Done:
11621162 OutputTable.push_back (IITDescriptor::get (IITDescriptor::Void, 0 ));
11631163 return ;
1164+ case IIT_BYTE:
1165+ OutputTable.push_back (IITDescriptor::get (IITDescriptor::Byte, 0 ));
1166+ return ;
11641167 case IIT_VARARG:
11651168 OutputTable.push_back (IITDescriptor::get (IITDescriptor::VarArg, 0 ));
11661169 return ;
@@ -1413,14 +1416,17 @@ void Intrinsic::getIntrinsicInfoTableEntries(ID id,
14131416}
14141417
14151418static Type *DecodeFixedType (ArrayRef<Intrinsic::IITDescriptor> &Infos,
1416- ArrayRef<Type*> Tys, LLVMContext &Context) {
1419+ ArrayRef<Type *> Tys, LLVMContext &Context,
1420+ const DataLayout &DL) {
14171421 using namespace Intrinsic ;
14181422
14191423 IITDescriptor D = Infos.front ();
14201424 Infos = Infos.slice (1 );
14211425
14221426 switch (D.Kind ) {
14231427 case IITDescriptor::Void: return Type::getVoidTy (Context);
1428+ case IITDescriptor::Byte:
1429+ return Type::getIntNTy (Context, DL.getByteWidth ());
14241430 case IITDescriptor::VarArg: return Type::getVoidTy (Context);
14251431 case IITDescriptor::MMX:
14261432 return llvm::FixedVectorType::get (llvm::IntegerType::get (Context, 64 ), 1 );
@@ -1439,14 +1445,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
14391445 case IITDescriptor::Integer:
14401446 return IntegerType::get (Context, D.Integer_Width );
14411447 case IITDescriptor::Vector:
1442- return VectorType::get (DecodeFixedType (Infos, Tys, Context),
1448+ return VectorType::get (DecodeFixedType (Infos, Tys, Context, DL ),
14431449 D.Vector_Width );
14441450 case IITDescriptor::Pointer:
14451451 return PointerType::get (Context, D.Pointer_AddressSpace );
14461452 case IITDescriptor::Struct: {
14471453 SmallVector<Type *, 8 > Elts;
14481454 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
1449- Elts.push_back (DecodeFixedType (Infos, Tys, Context));
1455+ Elts.push_back (DecodeFixedType (Infos, Tys, Context, DL ));
14501456 return StructType::get (Context, Elts);
14511457 }
14521458 case IITDescriptor::Argument:
@@ -1479,7 +1485,7 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
14791485 return VectorType::getHalfElementsVectorType (cast<VectorType>(
14801486 Tys[D.getArgumentNumber ()]));
14811487 case IITDescriptor::SameVecWidthArgument: {
1482- Type *EltTy = DecodeFixedType (Infos, Tys, Context);
1488+ Type *EltTy = DecodeFixedType (Infos, Tys, Context, DL );
14831489 Type *Ty = Tys[D.getArgumentNumber ()];
14841490 if (auto *VTy = dyn_cast<VectorType>(Ty))
14851491 return VectorType::get (EltTy, VTy->getElementCount ());
@@ -1504,17 +1510,18 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos,
15041510 llvm_unreachable (" unhandled" );
15051511}
15061512
1507- FunctionType *Intrinsic::getType (LLVMContext &Context,
1508- ID id, ArrayRef<Type*> Tys) {
1513+ FunctionType *Intrinsic::getType (Module *M, ID id, ArrayRef<Type *> Tys) {
15091514 SmallVector<IITDescriptor, 8 > Table;
15101515 getIntrinsicInfoTableEntries (id, Table);
15111516
15121517 ArrayRef<IITDescriptor> TableRef = Table;
1513- Type *ResultTy = DecodeFixedType (TableRef, Tys, Context);
1518+ Type *ResultTy =
1519+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ());
15141520
15151521 SmallVector<Type*, 8 > ArgTys;
15161522 while (!TableRef.empty ())
1517- ArgTys.push_back (DecodeFixedType (TableRef, Tys, Context));
1523+ ArgTys.push_back (
1524+ DecodeFixedType (TableRef, Tys, M->getContext (), M->getDataLayout ()));
15181525
15191526 // DecodeFixedType returns Void for IITDescriptor::Void and IITDescriptor::VarArg
15201527 // If we see void type as the type of the last argument, it is vararg intrinsic
@@ -1539,7 +1546,7 @@ bool Intrinsic::isOverloaded(ID id) {
15391546Function *Intrinsic::getDeclaration (Module *M, ID id, ArrayRef<Type*> Tys) {
15401547 // There can never be multiple globals with the same name of different types,
15411548 // because intrinsics must be a specific type.
1542- auto *FT = getType (M-> getContext () , id, Tys);
1549+ auto *FT = getType (M, id, Tys);
15431550 return cast<Function>(
15441551 M->getOrInsertFunction (
15451552 Tys.empty () ? getName (id) : getName (id, Tys, M, FT), FT)
@@ -1583,11 +1590,12 @@ bool Intrinsic::hasConstrainedFPRoundingModeOperand(Intrinsic::ID QID) {
15831590using DeferredIntrinsicMatchPair =
15841591 std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
15851592
1586- static bool matchIntrinsicType (
1587- Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
1588- SmallVectorImpl<Type *> &ArgTys,
1589- SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
1590- bool IsDeferredCheck) {
1593+ static bool
1594+ matchIntrinsicType (const DataLayout &DL, Type *Ty,
1595+ ArrayRef<Intrinsic::IITDescriptor> &Infos,
1596+ SmallVectorImpl<Type *> &ArgTys,
1597+ SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
1598+ bool IsDeferredCheck) {
15911599 using namespace Intrinsic ;
15921600
15931601 // If we ran out of descriptors, there are too many arguments.
@@ -1605,6 +1613,8 @@ static bool matchIntrinsicType(
16051613
16061614 switch (D.Kind ) {
16071615 case IITDescriptor::Void: return !Ty->isVoidTy ();
1616+ case IITDescriptor::Byte:
1617+ return !Ty->isIntegerTy (DL.getByteWidth ());
16081618 case IITDescriptor::VarArg: return true ;
16091619 case IITDescriptor::MMX: {
16101620 FixedVectorType *VT = dyn_cast<FixedVectorType>(Ty);
@@ -1627,7 +1637,7 @@ static bool matchIntrinsicType(
16271637 case IITDescriptor::Vector: {
16281638 VectorType *VT = dyn_cast<VectorType>(Ty);
16291639 return !VT || VT->getElementCount () != D.Vector_Width ||
1630- matchIntrinsicType (VT->getElementType (), Infos, ArgTys,
1640+ matchIntrinsicType (DL, VT->getElementType (), Infos, ArgTys,
16311641 DeferredChecks, IsDeferredCheck);
16321642 }
16331643 case IITDescriptor::Pointer: {
@@ -1642,7 +1652,7 @@ static bool matchIntrinsicType(
16421652 return true ;
16431653
16441654 for (unsigned i = 0 , e = D.Struct_NumElements ; i != e; ++i)
1645- if (matchIntrinsicType (ST->getElementType (i), Infos, ArgTys,
1655+ if (matchIntrinsicType (DL, ST->getElementType (i), Infos, ArgTys,
16461656 DeferredChecks, IsDeferredCheck))
16471657 return true ;
16481658 return false ;
@@ -1727,7 +1737,7 @@ static bool matchIntrinsicType(
17271737 return true ;
17281738 EltTy = ThisArgType->getElementType ();
17291739 }
1730- return matchIntrinsicType (EltTy, Infos, ArgTys, DeferredChecks,
1740+ return matchIntrinsicType (DL, EltTy, Infos, ArgTys, DeferredChecks,
17311741 IsDeferredCheck);
17321742 }
17331743 case IITDescriptor::VecOfAnyPtrsToElt: {
@@ -1791,24 +1801,24 @@ static bool matchIntrinsicType(
17911801}
17921802
17931803Intrinsic::MatchIntrinsicTypesResult
1794- Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
1804+ Intrinsic::matchIntrinsicSignature (const DataLayout &DL, FunctionType *FTy,
17951805 ArrayRef<Intrinsic::IITDescriptor> &Infos,
17961806 SmallVectorImpl<Type *> &ArgTys) {
17971807 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
1798- if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks ,
1799- false ))
1808+ if (matchIntrinsicType (DL, FTy->getReturnType (), Infos, ArgTys,
1809+ DeferredChecks, false ))
18001810 return MatchIntrinsicTypes_NoMatchRet;
18011811
18021812 unsigned NumDeferredReturnChecks = DeferredChecks.size ();
18031813
18041814 for (auto *Ty : FTy->params ())
1805- if (matchIntrinsicType (Ty, Infos, ArgTys, DeferredChecks, false ))
1815+ if (matchIntrinsicType (DL, Ty, Infos, ArgTys, DeferredChecks, false ))
18061816 return MatchIntrinsicTypes_NoMatchArg;
18071817
18081818 for (unsigned I = 0 , E = DeferredChecks.size (); I != E; ++I) {
18091819 DeferredIntrinsicMatchPair &Check = DeferredChecks[I];
1810- if (matchIntrinsicType (Check.first , Check.second , ArgTys, DeferredChecks ,
1811- true ))
1820+ if (matchIntrinsicType (DL, Check.first , Check.second , ArgTys,
1821+ DeferredChecks, true ))
18121822 return I < NumDeferredReturnChecks ? MatchIntrinsicTypes_NoMatchRet
18131823 : MatchIntrinsicTypes_NoMatchArg;
18141824 }
@@ -1836,7 +1846,8 @@ Intrinsic::matchIntrinsicVarArg(bool isVarArg,
18361846 return true ;
18371847}
18381848
1839- bool Intrinsic::getIntrinsicSignature (Intrinsic::ID ID, FunctionType *FT,
1849+ bool Intrinsic::getIntrinsicSignature (const DataLayout &DL, Intrinsic::ID ID,
1850+ FunctionType *FT,
18401851 SmallVectorImpl<Type *> &ArgTys) {
18411852 if (!ID)
18421853 return false ;
@@ -1845,7 +1856,7 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
18451856 getIntrinsicInfoTableEntries (ID, Table);
18461857 ArrayRef<Intrinsic::IITDescriptor> TableRef = Table;
18471858
1848- if (Intrinsic::matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1859+ if (Intrinsic::matchIntrinsicSignature (DL, FT, TableRef, ArgTys) !=
18491860 Intrinsic::MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
18501861 return false ;
18511862 }
@@ -1856,8 +1867,8 @@ bool Intrinsic::getIntrinsicSignature(Intrinsic::ID ID, FunctionType *FT,
18561867
18571868bool Intrinsic::getIntrinsicSignature (Function *F,
18581869 SmallVectorImpl<Type *> &ArgTys) {
1859- return getIntrinsicSignature (F->getIntrinsicID (), F->getFunctionType (),
1860- ArgTys);
1870+ return getIntrinsicSignature (F->getDataLayout (), F->getIntrinsicID (),
1871+ F-> getFunctionType (), ArgTys);
18611872}
18621873
18631874std::optional<Function *> Intrinsic::remangleIntrinsicFunction (Function *F) {
0 commit comments