1515#include " mlir/Dialect/LLVMIR/LLVMDialect.h"
1616#include " mlir/IR/Matchers.h"
1717#include " mlir/Transforms/InliningUtils.h"
18+ #include " llvm/Support/Debug.h"
19+
20+ #define DEBUG_TYPE " llvm-inliner"
1821
1922using namespace mlir ;
2023
@@ -134,26 +137,43 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
134137 if (!wouldBeCloned)
135138 return false ;
136139 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+ }
137145 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 " );
139149 return false ;
150+ }
140151 if (auto attrs = funcOp.getArgAttrs ()) {
141152 for (Attribute attr : *attrs) {
142153 auto attrDict = cast<DictionaryAttr>(attr);
143154 for (NamedAttribute attr : attrDict) {
144155 if (attr.getName () == LLVM::LLVMDialect::getByValAttrName ())
145156 continue ;
146157 // TODO: Handle all argument attributes;
158+ LLVM_DEBUG (llvm::dbgs () << " Cannot inline " << funcOp.getSymName ()
159+ << " : unhandled argument attribute \" "
160+ << attr.getName () << " \"\n " );
147161 return false ;
148162 }
149163 }
150164 }
151165 // 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 " );
153169 return false ;
170+ }
154171 // 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 " );
156175 return false ;
176+ }
157177 if (funcOp.getPassthrough ()) {
158178 // TODO: Used attributes should not be passthrough.
159179 DenseSet<StringAttr> disallowed (
@@ -167,7 +187,14 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
167187 auto stringAttr = dyn_cast<StringAttr>(attr);
168188 if (!stringAttr)
169189 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 ;
171198 }))
172199 return false ;
173200 }
@@ -185,14 +212,28 @@ struct LLVMInlinerInterface : public DialectInlinerInterface {
185212 // Some attributes on memory operations require handling during
186213 // inlining. Since this is not yet implemented, refuse to inline memory
187214 // 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 " );
190219 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 " );
193226 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 ;
196237 }
197238
198239 // / Handle the given inlined return by replacing it with a branch. This
0 commit comments