[LLVMdev] Question on JIT optimizations

Brent Walker brenthwalker at gmail.com
Fri Nov 4 07:31:15 PDT 2011


Hi,
If hope this is the right list to post a question like this.  If not,
my apologies -- please redirect me.

Following the Kaledoscope example I am trying to write a simple JIT and
compile my own small language using LLVM.  Compilation happens using the
C++ api by constructing a VM and emitting code using the api (just as the
Kaledoscope example).

The code in this setup will be optimized according to the optimizer
pipeline one sets up as in the code below.  I find that if I only use the
passes below the quality of the code is not that good (for example inlining
is not aggressive enough) -- moreover the number of passes is overwhelming
and the order in which they are specified seems important and I do not have
the expertise to set that up.  What I would like, is to set up the passes
in exactly the same as clang -O2 or llvm-gcc -O2 do.  Is there some way to
get that behavior using the api below?  How do language implementors do
this in the LLVM environment?

Thank you for any help.  And thank you for this great tool.

Brent

  FunctionPassManager OurFPM(TheModule);

  // Set up the optimizer pipeline.  Start with registering info about how the
  // target lays out data structures.
  OurFPM.add(new TargetData(*TheExecutionEngine->getTargetData()));
  // Provide basic AliasAnalysis support for GVN.
  OurFPM.add(createBasicAliasAnalysisPass());
  // Do simple "peephole" optimizations and bit-twiddling optzns.
  OurFPM.add(createInstructionCombiningPass());
  // Reassociate expressions.
  OurFPM.add(createReassociatePass());
  // Eliminate Common SubExpressions.
  OurFPM.add(createGVNPass());
  // Simplify the control flow graph (deleting unreachable blocks, etc).
  OurFPM.add(createCFGSimplificationPass());

  OurFPM.doInitialization();

  // Set the global so the code gen can use this.
  TheFPM = &OurFPM;

  // Run the main "interpreter loop" now.
  MainLoop();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111104/edc16816/attachment.html>


More information about the llvm-dev mailing list