[llvm-dev] LLVMTargetMachine with optimization level passed from clang.

Sumanth Gundapaneni via llvm-dev llvm-dev at lists.llvm.org
Wed Jan 4 16:03:10 PST 2017

I see the BackendUtil.cpp of Clang creates the TargetMachine with the
optimization level based on below mentioned logic


  CodeGenOpt::Level OptLevel = CodeGenOpt::Default;

  switch (CodeGenOpts.OptimizationLevel) {

  default: break;

  case 0: OptLevel = CodeGenOpt::None; break;

  case 3: OptLevel = CodeGenOpt::Aggressive; break;



As per my understanding, the correspondence between optimization level and
CodeGenOpt is as below

O0  -  none

O1  -  less

O2 -   default

O3  -  aggressive


My goal is to turn on a target dependent codegen optimization at -O1(less).
The TargetMachine is constructed with "CodeGenOpt::Default". Is there a way
I could do this in LLVM ? What is the standard way of doing this ? Also, the
code in BackendUtil.cpp seem somewhat offbeat to me.


--Sumanth G


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

More information about the llvm-dev mailing list