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