32
32
#include " llvm/IR/Type.h"
33
33
34
34
using namespace llvm ;
35
- using namespace Intrinsic ;
36
35
37
36
// / Table of string intrinsic names indexed by enum value.
38
37
static constexpr const char *const IntrinsicNameTable[] = {
@@ -49,7 +48,7 @@ StringRef Intrinsic::getBaseName(ID id) {
49
48
50
49
StringRef Intrinsic::getName (ID id) {
51
50
assert (id < num_intrinsics && " Invalid intrinsic ID!" );
52
- assert (!isOverloaded (id) &&
51
+ assert (!Intrinsic:: isOverloaded (id) &&
53
52
" This version of getName does not support overloading" );
54
53
return getBaseName (id);
55
54
}
@@ -152,27 +151,27 @@ static std::string getMangledTypeStr(Type *Ty, bool &HasUnnamedType) {
152
151
return Result;
153
152
}
154
153
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,
157
156
bool EarlyModuleCheck) {
158
157
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)) &&
161
160
" This version of getName is for overloaded intrinsics only" );
162
161
(void )EarlyModuleCheck;
163
162
assert ((!EarlyModuleCheck || M ||
164
163
!any_of (Tys, [](Type *T) { return isa<PointerType>(T); })) &&
165
164
" Intrinsic overloading on pointer types need to provide a Module" );
166
165
bool HasUnnamedType = false ;
167
- std::string Result (getBaseName (Id));
166
+ std::string Result (Intrinsic:: getBaseName (Id));
168
167
for (Type *Ty : Tys)
169
168
Result += " ." + getMangledTypeStr (Ty, HasUnnamedType);
170
169
if (HasUnnamedType) {
171
170
assert (M && " unnamed types need a module" );
172
171
if (!FT)
173
- FT = getType (M->getContext (), Id, Tys);
172
+ FT = Intrinsic:: getType (M->getContext (), Id, Tys);
174
173
else
175
- assert ((FT == getType (M->getContext (), Id, Tys)) &&
174
+ assert ((FT == Intrinsic:: getType (M->getContext (), Id, Tys)) &&
176
175
" Provided FunctionType must match arguments" );
177
176
return M->getUniqueIntrinsicName (Result, Id, FT);
178
177
}
@@ -199,10 +198,13 @@ enum IIT_Info {
199
198
#undef GET_INTRINSIC_IITINFO
200
199
};
201
200
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);
206
208
207
209
IIT_Info Info = IIT_Info (Infos[NextElt++]);
208
210
unsigned StructElts = 2 ;
@@ -479,8 +481,10 @@ void Intrinsic::getIntrinsicInfoTableEntries(
479
481
DecodeIITType (NextElt, IITEntries, IIT_Done, T);
480
482
}
481
483
482
- static Type *DecodeFixedType (ArrayRef<IITDescriptor> &Infos,
484
+ static Type *DecodeFixedType (ArrayRef<Intrinsic:: IITDescriptor> &Infos,
483
485
ArrayRef<Type *> Tys, LLVMContext &Context) {
486
+ using namespace Intrinsic ;
487
+
484
488
IITDescriptor D = Infos.front ();
485
489
Infos = Infos.slice (1 );
486
490
@@ -613,10 +617,13 @@ bool Intrinsic::isOverloaded(ID id) {
613
617
#include " llvm/IR/IntrinsicImpl.inc"
614
618
#undef GET_INTRINSIC_TARGET_DATA
615
619
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
+ }
617
623
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) {
620
627
assert (Name.starts_with (" llvm." ) && " Unexpected intrinsic prefix" );
621
628
assert (Name.drop_front (5 ).starts_with (Target) && " Unexpected target" );
622
629
@@ -678,23 +685,24 @@ findTargetSubtable(StringRef Name) {
678
685
679
686
// / This does the actual lookup of an intrinsic ID which matches the given
680
687
// / function name.
681
- ID Intrinsic::lookupIntrinsicID (StringRef Name) {
688
+ Intrinsic:: ID Intrinsic::lookupIntrinsicID (StringRef Name) {
682
689
auto [NameTable, Target] = findTargetSubtable (Name);
683
- int Idx = lookupLLVMIntrinsicByName (NameTable, Name, Target);
690
+ int Idx = Intrinsic:: lookupLLVMIntrinsicByName (NameTable, Name, Target);
684
691
if (Idx == -1 )
685
- return not_intrinsic;
692
+ return Intrinsic:: not_intrinsic;
686
693
687
694
// Intrinsic IDs correspond to the location in IntrinsicNameTable, but we have
688
695
// an index into a sub-table.
689
696
int Adjust = NameTable.data () - IntrinsicNameTable;
690
- ID Id = static_cast <ID>(Idx + Adjust);
697
+ Intrinsic:: ID ID = static_cast <Intrinsic:: ID>(Idx + Adjust);
691
698
692
699
// If the intrinsic is not overloaded, require an exact match. If it is
693
700
// overloaded, require either exact or prefix match.
694
701
const auto MatchSize = strlen (NameTable[Idx]);
695
702
assert (Name.size () >= MatchSize && " Expected either exact or prefix match" );
696
703
bool IsExactMatch = Name.size () == MatchSize;
697
- return IsExactMatch || isOverloaded (Id) ? Id : not_intrinsic;
704
+ return IsExactMatch || Intrinsic::isOverloaded (ID) ? ID
705
+ : Intrinsic::not_intrinsic;
698
706
}
699
707
700
708
// / This defines the "Intrinsic::getAttributes(ID id)" method.
@@ -735,7 +743,8 @@ Function *Intrinsic::getDeclarationIfExists(Module *M, ID id,
735
743
736
744
bool Intrinsic::isConstrainedFPIntrinsic (ID QID) {
737
745
switch (QID) {
738
- #define INSTRUCTION (NAME, NARG, ROUND_MODE, INTRINSIC ) case INTRINSIC:
746
+ #define INSTRUCTION (NAME, NARG, ROUND_MODE, INTRINSIC ) \
747
+ case Intrinsic::INTRINSIC:
739
748
#include " llvm/IR/ConstrainedOps.def"
740
749
#undef INSTRUCTION
741
750
return true ;
@@ -744,10 +753,10 @@ bool Intrinsic::isConstrainedFPIntrinsic(ID QID) {
744
753
}
745
754
}
746
755
747
- bool Intrinsic::hasConstrainedFPRoundingModeOperand (ID QID) {
756
+ bool Intrinsic::hasConstrainedFPRoundingModeOperand (Intrinsic:: ID QID) {
748
757
switch (QID) {
749
758
#define INSTRUCTION (NAME, NARG, ROUND_MODE, INTRINSIC ) \
750
- case INTRINSIC: \
759
+ case Intrinsic:: INTRINSIC: \
751
760
return ROUND_MODE == 1 ;
752
761
#include " llvm/IR/ConstrainedOps.def"
753
762
#undef INSTRUCTION
@@ -756,13 +765,16 @@ bool Intrinsic::hasConstrainedFPRoundingModeOperand(ID QID) {
756
765
}
757
766
}
758
767
759
- using DeferredIntrinsicMatchPair = std::pair<Type *, ArrayRef<IITDescriptor>>;
768
+ using DeferredIntrinsicMatchPair =
769
+ std::pair<Type *, ArrayRef<Intrinsic::IITDescriptor>>;
760
770
761
771
static bool
762
- matchIntrinsicType (Type *Ty, ArrayRef<IITDescriptor> &Infos,
772
+ matchIntrinsicType (Type *Ty, ArrayRef<Intrinsic:: IITDescriptor> &Infos,
763
773
SmallVectorImpl<Type *> &ArgTys,
764
774
SmallVectorImpl<DeferredIntrinsicMatchPair> &DeferredChecks,
765
775
bool IsDeferredCheck) {
776
+ using namespace Intrinsic ;
777
+
766
778
// If we ran out of descriptors, there are too many arguments.
767
779
if (Infos.empty ())
768
780
return true ;
@@ -981,9 +993,9 @@ matchIntrinsicType(Type *Ty, ArrayRef<IITDescriptor> &Infos,
981
993
llvm_unreachable (" unhandled" );
982
994
}
983
995
984
- MatchIntrinsicTypesResult
996
+ Intrinsic:: MatchIntrinsicTypesResult
985
997
Intrinsic::matchIntrinsicSignature (FunctionType *FTy,
986
- ArrayRef<IITDescriptor> &Infos,
998
+ ArrayRef<Intrinsic:: IITDescriptor> &Infos,
987
999
SmallVectorImpl<Type *> &ArgTys) {
988
1000
SmallVector<DeferredIntrinsicMatchPair, 2 > DeferredChecks;
989
1001
if (matchIntrinsicType (FTy->getReturnType (), Infos, ArgTys, DeferredChecks,
@@ -1007,8 +1019,8 @@ Intrinsic::matchIntrinsicSignature(FunctionType *FTy,
1007
1019
return MatchIntrinsicTypes_Match;
1008
1020
}
1009
1021
1010
- bool Intrinsic::matchIntrinsicVarArg (bool isVarArg,
1011
- ArrayRef<IITDescriptor> &Infos) {
1022
+ bool Intrinsic::matchIntrinsicVarArg (
1023
+ bool isVarArg, ArrayRef<Intrinsic:: IITDescriptor> &Infos) {
1012
1024
// If there are no descriptors left, then it can't be a vararg.
1013
1025
if (Infos.empty ())
1014
1026
return isVarArg;
@@ -1026,20 +1038,20 @@ bool Intrinsic::matchIntrinsicVarArg(bool isVarArg,
1026
1038
return true ;
1027
1039
}
1028
1040
1029
- bool Intrinsic::getIntrinsicSignature (ID ID, FunctionType *FT,
1041
+ bool Intrinsic::getIntrinsicSignature (Intrinsic:: ID ID, FunctionType *FT,
1030
1042
SmallVectorImpl<Type *> &ArgTys) {
1031
1043
if (!ID)
1032
1044
return false ;
1033
1045
1034
- SmallVector<IITDescriptor, 8 > Table;
1046
+ SmallVector<Intrinsic:: IITDescriptor, 8 > Table;
1035
1047
getIntrinsicInfoTableEntries (ID, Table);
1036
- ArrayRef<IITDescriptor> TableRef = Table;
1048
+ ArrayRef<Intrinsic:: IITDescriptor> TableRef = Table;
1037
1049
1038
- if (matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1039
- MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
1050
+ if (Intrinsic:: matchIntrinsicSignature (FT, TableRef, ArgTys) !=
1051
+ Intrinsic:: MatchIntrinsicTypesResult::MatchIntrinsicTypes_Match) {
1040
1052
return false ;
1041
1053
}
1042
- if (matchIntrinsicVarArg (FT->isVarArg (), TableRef))
1054
+ if (Intrinsic:: matchIntrinsicVarArg (FT->isVarArg (), TableRef))
1043
1055
return false ;
1044
1056
return true ;
1045
1057
}
@@ -1055,10 +1067,10 @@ std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
1055
1067
if (!getIntrinsicSignature (F, ArgTys))
1056
1068
return std::nullopt;
1057
1069
1058
- ID ID = F->getIntrinsicID ();
1070
+ Intrinsic:: ID ID = F->getIntrinsicID ();
1059
1071
StringRef Name = F->getName ();
1060
1072
std::string WantedName =
1061
- getName (ID, ArgTys, F->getParent (), F->getFunctionType ());
1073
+ Intrinsic:: getName (ID, ArgTys, F->getParent (), F->getFunctionType ());
1062
1074
if (Name == WantedName)
1063
1075
return std::nullopt;
1064
1076
@@ -1074,7 +1086,7 @@ std::optional<Function *> Intrinsic::remangleIntrinsicFunction(Function *F) {
1074
1086
// invalid and we'll get an error.
1075
1087
ExistingGV->setName (WantedName + " .renamed" );
1076
1088
}
1077
- return getOrInsertDeclaration (F->getParent (), ID, ArgTys);
1089
+ return Intrinsic:: getOrInsertDeclaration (F->getParent (), ID, ArgTys);
1078
1090
}();
1079
1091
1080
1092
NewDecl->setCallingConv (F->getCallingConv ());
0 commit comments