[llvm-dev] Function optimization pass

Ta Thanh Dinh via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 20 10:28:54 PDT 2018


This question has been submitted to stackoverflow 
(https://stackoverflow.com/questions/51934964/function-optimization-pass) 
but someone suggested me that it should be submitted to llvm-dev mailing 
list instead. I'm sorry for the duplication.

I am trying to use PassBulider and FunctionPassManager || to optimize a 
function in a module, what I have done is:


mod = ...load module from LLVM IR bitcode file go_back.bc...

auto lift_func = mod->getFunction("go_back");
if (not lift_func) {
     llvm::errs() << "Error: cannot get function\n";
     return 0;
}

auto pass_builder = llvm::PassBuilder{};
auto fa_manager = llvm::FunctionAnalysisManager{};

pass_builder.registerFunctionAnalyses(fa_manager);
auto fp_manager = 
pass_builder.buildFunctionSimplificationPipeline(llvm::PassBuilder::OptimizationLevel::O2);

fp_manager.run(*lift_func, fa_manager);

...print mod...


but the program crashes always at fp_manager.run. Strange enough, LLVM's 
opt tool (which uses legacy optimization API) works without any problem, 
i.e if I run

opt -O2 go_back.bc -o go_back_o2.bc

then I get a new module where the (single) function go_back is optimized.

Many thanks for any response.

NB. The disassembled LLVM bitcode is at 
https://gist.github.com/tathanhdinh/23470452910da9f73b857b2e6a12f144 if 
anyone wants to take a look.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180820/99781ec5/attachment.html>


More information about the llvm-dev mailing list