Reputation: 409
I have wrote a wrapper over a function and i want to inline it (this wrapper just maps the arguments for the original function in another way). I am trying to call the inliner in llvm over my module after my changes and it doesn't do the work, although i tried calling the pass from opt tool and it worked, Any idea what's may be wrong ?
Here is how i call the inliner pass:
llvm::PassManager my_passes;
my_passes.add(llvm::createFunctionInliningPass(4096));
my_passes.run(module);
Upvotes: 5
Views: 1084
Reputation: 205
I've managed to get the "AlwaysInline" pass working. The steps were much like what you describe:
llvm::Module m("MyJIT", llvm::getGlobalContext());
llvm::PassManager pm;
pm.add(llvm::createAlwaysInlinerPass());
...
llvm::Function* f = buildMyFunction();
f->addAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::AlwaysInline);
...
llvm::DebugFlag = true;
pm.runOnModule(m);
m.dump();
Note the llvm::DebugFlag variable, which will cause the llvm code generation machinery to spew a healthy amount of diagnostic output. It's declared in llvm/Support/Debug.h
and can be changed from your code or from gdb via set llvm::DebugFlag = 1
.
Also try poking around the llvm source; the relevant bits will be in ${llvm_root_dir}/lib/Transforms/IPO/Inliner.cpp
Upvotes: 3