<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>This question has been submitted to stackoverflow
(<a class="moz-txt-link-freetext" href="https://stackoverflow.com/questions/51934964/function-optimization-pass">https://stackoverflow.com/questions/51934964/function-optimization-pass</a>)
but someone suggested me that it should be submitted to llvm-dev
mailing list instead. I'm sorry for the duplication.</p>
<p>I am trying to use PassBulider and FunctionPassManager <code></code>
to optimize a function in a module, what I have done is:</p>
<p><br>
</p>
<p>mod = ...load module from LLVM IR bitcode file go_back.bc...<br>
<br>
auto lift_func = mod->getFunction("go_back");<br>
if (not lift_func) {<br>
llvm::errs() << "Error: cannot get function\n";<br>
return 0;<br>
}<br>
<br>
auto pass_builder = llvm::PassBuilder{};<br>
auto fa_manager = llvm::FunctionAnalysisManager{};<br>
<br>
pass_builder.registerFunctionAnalyses(fa_manager);<br>
auto fp_manager =
pass_builder.buildFunctionSimplificationPipeline(llvm::PassBuilder::OptimizationLevel::O2);<br>
<br>
fp_manager.run(*lift_func, fa_manager);</p>
<p>...print mod...</p>
<p><br>
</p>
<p>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</p>
<p>opt -O2 go_back.bc -o go_back_o2.bc</p>
<p>then I get a new module where the (single) function go_back is
optimized.</p>
<p>Many thanks for any response.</p>
<p>NB. The disassembled LLVM bitcode is at
<a class="moz-txt-link-freetext" href="https://gist.github.com/tathanhdinh/23470452910da9f73b857b2e6a12f144">https://gist.github.com/tathanhdinh/23470452910da9f73b857b2e6a12f144</a>
if anyone wants to take a look.<br>
</p>
</body>
</html>