File indexing completed on 2026-05-10 08:44:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_IR_INTRINSICS_H
0016 #define LLVM_IR_INTRINSICS_H
0017
0018 #include "llvm/ADT/ArrayRef.h"
0019 #include "llvm/Support/TypeSize.h"
0020 #include <optional>
0021 #include <string>
0022
0023 namespace llvm {
0024
0025 class Type;
0026 class FunctionType;
0027 class Function;
0028 class LLVMContext;
0029 class Module;
0030 class AttributeList;
0031
0032
0033
0034
0035 namespace Intrinsic {
0036
0037 static const int NoAliasScopeDeclScopeArg = 0;
0038
0039
0040
0041 typedef unsigned ID;
0042
0043 enum IndependentIntrinsics : unsigned {
0044 not_intrinsic = 0,
0045
0046
0047 #define GET_INTRINSIC_ENUM_VALUES
0048 #include "llvm/IR/IntrinsicEnums.inc"
0049 #undef GET_INTRINSIC_ENUM_VALUES
0050 };
0051
0052
0053
0054
0055 StringRef getName(ID id);
0056
0057
0058
0059 StringRef getBaseName(ID id);
0060
0061
0062
0063
0064
0065
0066
0067 std::string getName(ID Id, ArrayRef<Type *> Tys, Module *M,
0068 FunctionType *FT = nullptr);
0069
0070
0071
0072
0073 std::string getNameNoUnnamedTypes(ID Id, ArrayRef<Type *> Tys);
0074
0075
0076 FunctionType *getType(LLVMContext &Context, ID id, ArrayRef<Type *> Tys = {});
0077
0078
0079 bool isOverloaded(ID id);
0080
0081
0082
0083 bool isTargetIntrinsic(ID IID);
0084
0085 ID lookupIntrinsicID(StringRef Name);
0086
0087
0088 AttributeList getAttributes(LLVMContext &C, ID id);
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 Function *getOrInsertDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {});
0099
0100 LLVM_DEPRECATED("Use getOrInsertDeclaration instead",
0101 "getOrInsertDeclaration")
0102 inline Function *getDeclaration(Module *M, ID id, ArrayRef<Type *> Tys = {}) {
0103 return getOrInsertDeclaration(M, id, Tys);
0104 }
0105
0106
0107
0108
0109 Function *getDeclarationIfExists(const Module *M, ID id);
0110
0111
0112 Function *getDeclarationIfExists(Module *M, ID id, ArrayRef<Type *> Tys,
0113 FunctionType *FT = nullptr);
0114
0115
0116 ID getIntrinsicForClangBuiltin(StringRef TargetPrefix, StringRef BuiltinName);
0117
0118
0119 ID getIntrinsicForMSBuiltin(StringRef TargetPrefix, StringRef BuiltinName);
0120
0121
0122
0123 bool isConstrainedFPIntrinsic(ID QID);
0124
0125
0126
0127 bool hasConstrainedFPRoundingModeOperand(ID QID);
0128
0129
0130
0131 struct IITDescriptor {
0132 enum IITDescriptorKind {
0133 Void,
0134 VarArg,
0135 MMX,
0136 Token,
0137 Metadata,
0138 Half,
0139 BFloat,
0140 Float,
0141 Double,
0142 Quad,
0143 Integer,
0144 Vector,
0145 Pointer,
0146 Struct,
0147 Argument,
0148 ExtendArgument,
0149 TruncArgument,
0150 HalfVecArgument,
0151 SameVecWidthArgument,
0152 VecOfAnyPtrsToElt,
0153 VecElementArgument,
0154 Subdivide2Argument,
0155 Subdivide4Argument,
0156 VecOfBitcastsToInt,
0157 AMX,
0158 PPCQuad,
0159 AArch64Svcount,
0160 } Kind;
0161
0162 union {
0163 unsigned Integer_Width;
0164 unsigned Float_Width;
0165 unsigned Pointer_AddressSpace;
0166 unsigned Struct_NumElements;
0167 unsigned Argument_Info;
0168 ElementCount Vector_Width;
0169 };
0170
0171
0172 enum ArgKind {
0173 #define GET_INTRINSIC_ARGKIND
0174 #include "llvm/IR/IntrinsicEnums.inc"
0175 #undef GET_INTRINSIC_ARGKIND
0176 };
0177
0178 unsigned getArgumentNumber() const {
0179 assert(Kind == Argument || Kind == ExtendArgument ||
0180 Kind == TruncArgument || Kind == HalfVecArgument ||
0181 Kind == SameVecWidthArgument || Kind == VecElementArgument ||
0182 Kind == Subdivide2Argument || Kind == Subdivide4Argument ||
0183 Kind == VecOfBitcastsToInt);
0184 return Argument_Info >> 3;
0185 }
0186 ArgKind getArgumentKind() const {
0187 assert(Kind == Argument || Kind == ExtendArgument ||
0188 Kind == TruncArgument || Kind == HalfVecArgument ||
0189 Kind == SameVecWidthArgument ||
0190 Kind == VecElementArgument || Kind == Subdivide2Argument ||
0191 Kind == Subdivide4Argument || Kind == VecOfBitcastsToInt);
0192 return (ArgKind)(Argument_Info & 7);
0193 }
0194
0195
0196
0197 unsigned getOverloadArgNumber() const {
0198 assert(Kind == VecOfAnyPtrsToElt);
0199 return Argument_Info >> 16;
0200 }
0201 unsigned getRefArgNumber() const {
0202 assert(Kind == VecOfAnyPtrsToElt);
0203 return Argument_Info & 0xFFFF;
0204 }
0205
0206 static IITDescriptor get(IITDescriptorKind K, unsigned Field) {
0207 IITDescriptor Result = { K, { Field } };
0208 return Result;
0209 }
0210
0211 static IITDescriptor get(IITDescriptorKind K, unsigned short Hi,
0212 unsigned short Lo) {
0213 unsigned Field = Hi << 16 | Lo;
0214 IITDescriptor Result = {K, {Field}};
0215 return Result;
0216 }
0217
0218 static IITDescriptor getVector(unsigned Width, bool IsScalable) {
0219 IITDescriptor Result = {Vector, {0}};
0220 Result.Vector_Width = ElementCount::get(Width, IsScalable);
0221 return Result;
0222 }
0223 };
0224
0225
0226
0227 void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl<IITDescriptor> &T);
0228
0229 enum MatchIntrinsicTypesResult {
0230 MatchIntrinsicTypes_Match = 0,
0231 MatchIntrinsicTypes_NoMatchRet = 1,
0232 MatchIntrinsicTypes_NoMatchArg = 2,
0233 };
0234
0235
0236
0237
0238
0239
0240
0241 MatchIntrinsicTypesResult
0242 matchIntrinsicSignature(FunctionType *FTy, ArrayRef<IITDescriptor> &Infos,
0243 SmallVectorImpl<Type *> &ArgTys);
0244
0245
0246
0247
0248
0249 bool matchIntrinsicVarArg(bool isVarArg, ArrayRef<IITDescriptor> &Infos);
0250
0251
0252
0253
0254
0255
0256
0257 bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT,
0258 SmallVectorImpl<Type *> &ArgTys);
0259
0260
0261 bool getIntrinsicSignature(Function *F, SmallVectorImpl<Type *> &ArgTys);
0262
0263
0264
0265
0266
0267 std::optional<Function *> remangleIntrinsicFunction(Function *F);
0268
0269 }
0270
0271 }
0272
0273 #endif