3232#include " llvm/IR/Type.h"
3333
3434using namespace llvm ;
35- using namespace Intrinsic ;
3635
3736// / Table of string intrinsic names indexed by enum value.
3837static constexpr const char *const IntrinsicNameTable[] = {
@@ -49,7 +48,7 @@ StringRef Intrinsic::getBaseName(ID id) {
4948
5049StringRef Intrinsic::getName (ID id) {
5150 assert (id < num_intrinsics && " Invalid intrinsic ID!" );
52- assert (!isOverloaded (id) &&
51+ assert (!Intrinsic:: isOverloaded (id) &&
5352 " This version of getName does not support overloading" );
5453 return getBaseName (id);
5554}
@@ -152,27 +151,27 @@ static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
152151 return Result;
153152}
154153
155- static std::string getIntrinsicNameImpl (ID Id, ArrayRef<Type *> Tys, Module *M ,
156- FunctionType *FT,
154+ static std::string getIntrinsicNameImpl (Intrinsic:: ID Id, ArrayRef<Type *> Tys,
155+ Module *M, FunctionType *FT,
157156 bool EarlyModuleCheck) {
158157
159- assert (Id < num_intrinsics && " Invalid intrinsic ID!" );
160- assert ((Tys.empty () || isOverloaded (Id)) &&
158+ assert (Id < Intrinsic:: num_intrinsics && " Invalid intrinsic ID!" );
159+ assert ((Tys.empty () || Intrinsic:: isOverloaded (Id)) &&
161160 " This version of getName is for overloaded intrinsics only" );
162161 (void )EarlyModuleCheck;
163162 assert ((!EarlyModuleCheck || M ||
164163 !any_of (Tys, [](Type *T) { return isa<PointerType>(T); })) &&
165164 " Intrinsic overloading on pointer types need to provide a Module" );
166165 bool HasUnnamedType = false ;
167- std::string Result (getBaseName (Id));
166+ std::string Result (Intrinsic:: getBaseName (Id));
168167 for (Type *Ty : Tys)
169168 Result += " ." + getMangledTypeStr (Ty, HasUnnamedType);
170169 if (HasUnnamedType) {
171170 assert (M && " unnamed types need a module" );
172171 if (!FT)
173- FT = getType (M->getContext (), Id, Tys);
172+ FT = Intrinsic:: getType (M->getContext (), Id, Tys);
174173 else
175- assert ((FT == getType (M->getContext (), Id, Tys)) &&
174+ assert ((FT == Intrinsic:: getType (M->getContext (), Id, Tys)) &&
176175 " Provided FunctionType must match arguments" );
177176 return M->getUniqueIntrinsicName (Result, Id, FT);
178177 }
@@ -199,10 +198,13 @@ enum IIT_Info {
199198#undef GET_INTRINSIC_IITINFO
200199};
201200
202- static void DecodeIITType (unsigned &NextElt, ArrayRef<unsigned char > Infos,
203- IIT_Info LastInfo,
204- SmallVectorImpl<IITDescriptor> &OutputTable) {
205- bool IsScalableVector = LastInfo == IIT_SCALABLE_VEC;
201+ static void
202+ DecodeIITType (unsigned &NextElt, ArrayRef<unsigned char > Infos,
203+ IIT_Info LastInfo,
204+ SmallVectorImpl<Intrinsic::IITDescriptor> &OutputTable) {
205+ using namespace Intrinsic ;
206+
207+ bool IsScalableVector = (LastInfo == IIT_SCALABLE_VEC);
206208
207209 IIT_Info Info = IIT_Info (Infos[NextElt++]);
208210 unsigned StructElts = 2 ;
@@ -479,8 +481,10 @@ void Intrinsic::getIntrinsicInfoTableEntries(
479481 DecodeIITType (NextElt, IITEntries, IIT_Done, T);
480482}
481483
482- static Type *DecodeFixedType (ArrayRef<IITDescriptor> &Infos,
484+ static Type *DecodeFixedType (ArrayRef<Intrinsic:: IITDescriptor> &Infos,
483485 ArrayRef<Type *> Tys, LLVMContext &Context) {
486+ using namespace Intrinsic ;
487+
484488 IITDescriptor D = Infos.front ();
485489 Infos = Infos.slice (1 );
486490
@@ -613,10 +617,13 @@ bool Intrinsic::isOverloaded(ID id) {
613617#include " llvm/IR/IntrinsicImpl.inc"
614618#undef GET_INTRINSIC_TARGET_DATA
615619
616- bool Intrinsic::isTargetIntrinsic (ID IID) { return IID > TargetInfos[0 ].Count ; }
620+ bool Intrinsic::isTargetIntrinsic (Intrinsic::ID IID) {
621+ return IID > TargetInfos[0 ].Count ;
622+ }
617623
618- int Intrinsic::lookupLLVMIntrinsicByName (ArrayRef<const char *> NameTable,
619- StringRef Name, StringRef Target) {
624+ int llvm::Intrinsic::lookupLLVMIntrinsicByName (ArrayRef<const char *> NameTable,
625+ StringRef Name,
626+ StringRef Target) {
620627 assert (Name.starts_with (" llvm." ) && " Unexpected intrinsic prefix" );
621628 assert (Name.drop_front (5 ).starts_with (Target) && " Unexpected target" );
622629
@@ -678,23 +685,24 @@ findTargetSubtable(StringRef Name) {
678685
679686// / This does the actual lookup of an intrinsic ID which matches the given
680687// / function name.
681- ID Intrinsic::lookupIntrinsicID (StringRef Name) {
688+ Intrinsic:: ID Intrinsic::lookupIntrinsicID (StringRef Name) {
682689 auto [NameTable, Target] = findTargetSubtable (Name);
683- int Idx = lookupLLVMIntrinsicByName (NameTable, Name, Target);
690+ int Idx = Intrinsic:: lookupLLVMIntrinsicByName (NameTable, Name, Target);
684691 if (Idx == -1 )
685- return not_intrinsic;
692+ return Intrinsic:: not_intrinsic;
686693
687694 // Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
688695 // an index into a sub-table.
689696 int Adjust = NameTable.data () - IntrinsicNameTable;
690- ID Id = static_cast <ID>(Idx + Adjust);
697+ Intrinsic:: ID ID = static_cast <Intrinsic:: ID>(Idx + Adjust);
691698
692699 // If the intrinsic is not overloaded, require an exact match. If it is
693700 // overloaded, require either exact or prefix match.
694701 const auto MatchSize = strlen (NameTable[Idx]);
695702 assert (Name.size () >= MatchSize && " Expected either exact or prefix match" );
696703 bool IsExactMatch = Name.size () == MatchSize;
697- return IsExactMatch || isOverloaded (Id) ? Id : not_intrinsic;
704+ return IsExactMatch || Intrinsic::isOverloaded (ID) ? ID
705+ : Intrinsic::not_intrinsic;
698706}
699707
700708// / This defines the "Intrinsic::getAttributes(ID id)" method.
@@ -735,7 +743,8 @@ Function *Intrinsic::getDeclarationIfExists(Module *M, ID id,
735743
736744bool Intrinsic::isConstrainedFPIntrinsic (ID QID) {
737745 switch (QID) {
738- #define INSTRUCTION (NAME, NARG, ROUND_MODE, INTRINSIC ) case INTRINSIC:
746+ #define INSTRUCTION (NAME, NARG, ROUND_MODE, INTRINSIC ) \
747+ case Intrinsic::INTRINSIC:
739748#include " llvm/IR/ConstrainedOps.def"
740749#undef INSTRUCTION
741750 return true ;
@@ -744,10 +753,10 @@ bool Intrinsic::isConstrainedFPIntrinsic(ID QID) {
744753 }
745754}
746755
747- bool Intrinsic::hasConstrainedFPRoundingModeOperand (ID QID) {
756+ bool Intrinsic::hasConstrainedFPRoundingModeOperand (Intrinsic:: ID QID) {
748757 switch (QID) {
749758#define INSTRUCTION (NAME, NARG, ROUND_MODE, INTRINSIC ) \
750- case INTRINSIC: \
759+ case Intrinsic:: INTRINSIC: \
751760 return ROUND_MODE == 1 ;
752761#include " llvm/IR/ConstrainedOps.def"
753762#undef INSTRUCTION
@@ -756,13 +765,16 @@ bool Intrinsic::hasConstrainedFPRoundingModeOperand(ID QID) {
756765 }
757766}
758767
759- using DeferredIntrinsicMatchPair = std::pair<Type *, ArrayRef<IITDescriptor>>;
768+ using DeferredIntrinsicMatchPair =
769+ std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
760770
761771static bool
762- matchIntrinsicType (Type *Ty, ArrayRef<IITDescriptor> &Infos,
772+ matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic:: IITDescriptor> &Infos,
763773 SmallVectorImpl<Type *> &ArgTys,
764774 SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
765775 bool IsDeferredCheck) {
776+ using namespace Intrinsic ;
777+
766778 // If we ran out of descriptors, there are too many arguments.
767779 if (Infos.empty ())
768780 return true ;
@@ -981,9 +993,9 @@ matchIntrinsicType(Type *Ty, ArrayRef<IITDescriptor> &Infos,
981993 llvm_unreachable (" unhandled" );
982994}
983995
984- MatchIntrinsicTypesResult
996+ Intrinsic:: MatchIntrinsicTypesResult
985997Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
986- ArrayRef<IITDescriptor> &Infos,
998+ ArrayRef<Intrinsic:: IITDescriptor> &Infos,
987999 SmallVectorImpl<Type *> &ArgTys) {
9881000 SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
9891001 if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks,
@@ -1007,8 +1019,8 @@ Intrinsic::matchIntrinsicSignature(FunctionType *FTy,
10071019 return MatchIntrinsicTypes_Match;
10081020}
10091021
1010- bool Intrinsic::matchIntrinsicVarArg (bool isVarArg,
1011- ArrayRef<IITDescriptor> &Infos) {
1022+ bool Intrinsic::matchIntrinsicVarArg (
1023+ bool isVarArg, ArrayRef<Intrinsic:: IITDescriptor> &Infos) {
10121024 // If there are no descriptors left, then it can't be a vararg.
10131025 if (Infos.empty ())
10141026 return isVarArg;
@@ -1026,20 +1038,20 @@ bool Intrinsic::matchIntrinsicVarArg(bool isVarArg,
10261038 return true ;
10271039}
10281040
1029- bool Intrinsic::getIntrinsicSignature (ID ID, FunctionType *FT,
1041+ bool Intrinsic::getIntrinsicSignature (Intrinsic:: ID ID, FunctionType *FT,
10301042 SmallVectorImpl<Type *> &ArgTys) {
10311043 if (!ID)
10321044 return false ;
10331045
1034- SmallVector<IITDescriptor, 8 > Table;
1046+ SmallVector<Intrinsic:: IITDescriptor, 8 > Table;
10351047 getIntrinsicInfoTableEntries (ID, Table);
1036- ArrayRef<IITDescriptor> TableRef = Table;
1048+ ArrayRef<Intrinsic:: IITDescriptor> TableRef = Table;
10371049
1038- if (matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1039- MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
1050+ if (Intrinsic:: matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1051+ Intrinsic:: MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
10401052 return false ;
10411053 }
1042- if (matchIntrinsicVarArg (FT->isVarArg (), TableRef))
1054+ if (Intrinsic:: matchIntrinsicVarArg (FT->isVarArg (), TableRef))
10431055 return false ;
10441056 return true ;
10451057}
@@ -1055,10 +1067,10 @@ std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
10551067 if (!getIntrinsicSignature (F, ArgTys))
10561068 return std::nullopt ;
10571069
1058- ID ID = F->getIntrinsicID ();
1070+ Intrinsic:: ID ID = F->getIntrinsicID ();
10591071 StringRef Name = F->getName ();
10601072 std::string WantedName =
1061- getName (ID, ArgTys, F->getParent (), F->getFunctionType ());
1073+ Intrinsic:: getName (ID, ArgTys, F->getParent (), F->getFunctionType ());
10621074 if (Name == WantedName)
10631075 return std::nullopt ;
10641076
@@ -1074,7 +1086,7 @@ std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
10741086 // invalid and we'll get an error.
10751087 ExistingGV->setName (WantedName + " .renamed" );
10761088 }
1077- return getOrInsertDeclaration (F->getParent (), ID, ArgTys);
1089+ return Intrinsic:: getOrInsertDeclaration (F->getParent (), ID, ArgTys);
10781090 }();
10791091
10801092 NewDecl->setCallingConv (F->getCallingConv ());
0 commit comments