@@ -50,7 +50,7 @@ class LLVMIntrinsicCallOp;
50
50
class FuncOp ;
51
51
// FIXME: Unsure if we need a proper function type
52
52
53
- namespace Intrinsic {
53
+ namespace CIRIntrinsic {
54
54
55
55
// Abstraction for the arguments of the noalias intrinsics
56
56
static const int NoAliasScopeDeclScopeArg = 0 ;
@@ -68,6 +68,26 @@ enum IndependentIntrinsics : unsigned {
68
68
#undef GET_INTRINSIC_ENUM_VALUES
69
69
};
70
70
71
+ // Simple descriptor struct that holds essential intrinsic information
72
+ // In order to build CIRIntrinsicCallOp
73
+ struct IntrinsicDescriptor {
74
+ mlir::StringAttr name; // Mangled name attribute
75
+ mlir::Type resultType; // Return type for the intrinsic
76
+ ID id; // Original intrinsic ID (optional)
77
+
78
+ // Basic constructor
79
+ IntrinsicDescriptor (mlir::StringAttr name, mlir::Type resultType,
80
+ ID id = not_intrinsic)
81
+ : name(name), resultType(resultType), id(id) {}
82
+
83
+ // Default constructor for empty/invalid descriptors
84
+ IntrinsicDescriptor ()
85
+ : name(nullptr ), resultType(nullptr ), id(not_intrinsic) {}
86
+
87
+ // Check if descriptor is valid
88
+ bool isValid () const { return name && resultType; }
89
+ };
90
+
71
91
// / Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
72
92
// / Note, this version is for intrinsics with no overloads. Use the other
73
93
// / version of getName if overloads are required.
@@ -92,11 +112,15 @@ std::string getName(ID Id, llvm::ArrayRef<mlir::Type> Tys, mlir::ModuleOp M,
92
112
std::string getNameNoUnnamedTypes (ID Id, llvm::ArrayRef<mlir::Type> Tys);
93
113
94
114
// / Return the function type for an intrinsic.
95
- mlir::Type *getType (mlir::MLIRContext& Context, ID id,
96
- llvm::ArrayRef<mlir::Type> Tys = {});
115
+ // mlir::Type getType(mlir::MLIRContext &Context, ID id,
116
+ // llvm::ArrayRef<mlir::Type> Tys = {});
117
+
118
+ // Get both return type and parameter types in one call
119
+ mlir::Type getType (mlir::MLIRContext &Context, ID id,
120
+ llvm::ArrayRef<mlir::Type> Tys);
97
121
98
122
// / Returns true if the intrinsic can be overloaded.
99
- bool isOverloaded (ID id);
123
+ bool isOverloaded (ID id); // NYI
100
124
101
125
ID lookupIntrinsicID (llvm::StringRef Name);
102
126
@@ -117,18 +141,18 @@ ID lookupIntrinsicID(llvm::StringRef Name);
117
141
// / using iAny, fAny, vAny, or pAny). For a declaration of an overloaded
118
142
// / intrinsic, Tys must provide exactly one type for each overloaded type in
119
143
// / the intrinsic.
120
- LLVMIntrinsicCallOp getOrInsertDeclaration (mlir::ModuleOp M, ID id,
121
- llvm::ArrayRef<mlir::Type> Tys = {});
144
+ IntrinsicDescriptor getOrInsertDeclaration (mlir::ModuleOp M, ID id,
145
+ llvm::ArrayRef<mlir::Type> Tys = {});
122
146
123
147
// / Look up the Function declaration of the intrinsic \p id in the Module
124
148
// / \p M and return it if it exists. Otherwise, return nullptr. This version
125
149
// / supports non-overloaded intrinsics.
126
- LLVMIntrinsicCallOp getDeclarationIfExists (const mlir::ModuleOp *M, ID id);
150
+ IntrinsicDescriptor getDeclarationIfExists (const mlir::ModuleOp *M, ID id);
127
151
128
152
// / This version supports overloaded intrinsics.
129
- LLVMIntrinsicCallOp getDeclarationIfExists (mlir::ModuleOp M, ID id,
130
- llvm::ArrayRef<mlir::Type> Tys,
131
- mlir::Type FT = nullptr );
153
+ IntrinsicDescriptor getDeclarationIfExists (mlir::ModuleOp M, ID id,
154
+ llvm::ArrayRef<mlir::Type> Tys,
155
+ mlir::Type FT = nullptr );
132
156
133
157
// / Map a Clang builtin name to an intrinsic ID.
134
158
ID getIntrinsicForClangBuiltin (llvm::StringRef TargetPrefix,
@@ -182,7 +206,7 @@ bool matchIntrinsicVarArg(
182
206
// /
183
207
// / Returns false if the given ID and function type combination is not a
184
208
// / valid intrinsic call.
185
- bool getIntrinsicSignature (Intrinsic:: ID, mlir::Type FT,
209
+ bool getIntrinsicSignature (ID, mlir::Type FT,
186
210
llvm::SmallVectorImpl<mlir::Type> &ArgTys);
187
211
188
212
// / Same as previous, but accepts a Function instead of ID and FunctionType.
@@ -194,7 +218,7 @@ bool getIntrinsicSignature(FuncOp F, llvm::SmallVectorImpl<mlir::Type> &ArgTys);
194
218
// or of the wrong kind will be renamed by adding ".renamed" to the name.
195
219
std::optional<LLVMIntrinsicCallOp> remangleIntrinsicFunction (FuncOp F);
196
220
197
- } // namespace Intrinsic
221
+ } // namespace CIRIntrinsic
198
222
} // namespace cir
199
223
200
224
#endif // LLVM_CLANG_CIR_DIALECT_INTRINSICS_H
0 commit comments