15
15
#include " mlir/Dialect/LLVMIR/LLVMDialect.h"
16
16
#include " mlir/IR/Matchers.h"
17
17
#include " mlir/Transforms/InliningUtils.h"
18
+ #include " llvm/Support/Debug.h"
19
+
20
+ #define DEBUG_TYPE " llvm-inliner"
18
21
19
22
using namespace mlir ;
20
23
@@ -134,26 +137,43 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
134
137
if (!wouldBeCloned)
135
138
return false ;
136
139
auto callOp = dyn_cast<LLVM::CallOp>(call);
140
+ if (!callOp) {
141
+ LLVM_DEBUG (llvm::dbgs ()
142
+ << " Cannot inline: call is not an LLVM::CallOp\n " );
143
+ return false ;
144
+ }
137
145
auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(callable);
138
- if (!callOp || !funcOp)
146
+ if (!funcOp) {
147
+ LLVM_DEBUG (llvm::dbgs ()
148
+ << " Cannot inline: callable is not an LLVM::LLVMFuncOp\n " );
139
149
return false ;
150
+ }
140
151
if (auto attrs = funcOp.getArgAttrs ()) {
141
152
for (Attribute attr : *attrs) {
142
153
auto attrDict = cast<DictionaryAttr>(attr);
143
154
for (NamedAttribute attr : attrDict) {
144
155
if (attr.getName () == LLVM::LLVMDialect::getByValAttrName ())
145
156
continue ;
146
157
// TODO: Handle all argument attributes;
158
+ LLVM_DEBUG (llvm::dbgs () << " Cannot inline " << funcOp.getSymName ()
159
+ << " : unhandled argument attribute \" "
160
+ << attr.getName () << " \"\n " );
147
161
return false ;
148
162
}
149
163
}
150
164
}
151
165
// TODO: Handle result attributes;
152
- if (funcOp.getResAttrs ())
166
+ if (funcOp.getResAttrs ()) {
167
+ LLVM_DEBUG (llvm::dbgs () << " Cannot inline " << funcOp.getSymName ()
168
+ << " : unhandled result attribute\n " );
153
169
return false ;
170
+ }
154
171
// TODO: Handle exceptions.
155
- if (funcOp.getPersonality ())
172
+ if (funcOp.getPersonality ()) {
173
+ LLVM_DEBUG (llvm::dbgs () << " Cannot inline " << funcOp.getSymName ()
174
+ << " : unhandled function personality\n " );
156
175
return false ;
176
+ }
157
177
if (funcOp.getPassthrough ()) {
158
178
// TODO: Used attributes should not be passthrough.
159
179
DenseSet<StringAttr> disallowed (
@@ -167,7 +187,14 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
167
187
auto stringAttr = dyn_cast<StringAttr>(attr);
168
188
if (!stringAttr)
169
189
return false ;
170
- return disallowed.contains (stringAttr);
190
+ if (disallowed.contains (stringAttr)) {
191
+ LLVM_DEBUG (llvm::dbgs ()
192
+ << " Cannot inline " << funcOp.getSymName ()
193
+ << " : found disallowed function attribute "
194
+ << stringAttr << " \n " );
195
+ return true ;
196
+ }
197
+ return false ;
171
198
}))
172
199
return false ;
173
200
}
@@ -185,14 +212,28 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
185
212
// Some attributes on memory operations require handling during
186
213
// inlining. Since this is not yet implemented, refuse to inline memory
187
214
// operations that have any of these attributes.
188
- if (auto iface = dyn_cast<LLVM::AliasAnalysisOpInterface>(op))
189
- if (iface.getAliasScopesOrNull () || iface.getNoAliasScopesOrNull ())
215
+ if (auto iface = dyn_cast<LLVM::AliasAnalysisOpInterface>(op)) {
216
+ if (iface.getAliasScopesOrNull () || iface.getNoAliasScopesOrNull ()) {
217
+ LLVM_DEBUG (llvm::dbgs ()
218
+ << " Cannot inline: unhandled alias analysis metadata\n " );
190
219
return false ;
191
- if (auto iface = dyn_cast<LLVM::AccessGroupOpInterface>(op))
192
- if (iface.getAccessGroupsOrNull ())
220
+ }
221
+ }
222
+ if (auto iface = dyn_cast<LLVM::AccessGroupOpInterface>(op)) {
223
+ if (iface.getAccessGroupsOrNull ()) {
224
+ LLVM_DEBUG (llvm::dbgs ()
225
+ << " Cannot inline: unhandled access group metadata\n " );
193
226
return false ;
194
- return isa<LLVM::CallOp, LLVM::AllocaOp, LLVM::LifetimeStartOp,
195
- LLVM::LifetimeEndOp, LLVM::LoadOp, LLVM::StoreOp>(op);
227
+ }
228
+ }
229
+ if (!isa<LLVM::CallOp, LLVM::AllocaOp, LLVM::LifetimeStartOp,
230
+ LLVM::LifetimeEndOp, LLVM::LoadOp, LLVM::StoreOp>(op)) {
231
+ LLVM_DEBUG (llvm::dbgs ()
232
+ << " Cannot inline: unhandled side effecting operation \" "
233
+ << op->getName () << " \"\n " );
234
+ return false ;
235
+ }
236
+ return true ;
196
237
}
197
238
198
239
// / Handle the given inlined return by replacing it with a branch. This
0 commit comments