3

I can get the optimization level from the command llc -help

-O=<char>               - Optimization level. [-O0, -O1, -O2, or -O3] (default = '-O2')

I want to know what the optimization does exactly.

So, I'm searching the source code of the backend optimizer.

I google it by "llvm backend optimizer", but there is no information about it, only some target-independent pass source code.

I want to know what does the optimization do for div-rem-pars.

It can combine two instructions of llvm IR to one instruction for assembly code.

Laurel
  • 5,965
  • 14
  • 31
  • 57
Shane
  • 337
  • 1
  • 10
  • John Regehr wrote [a long blog post that walks through this](https://blog.regehr.org/archives/1603). He stops a little before the end, so you have to run the `opt` command in the posting and also look at the target-specific passes at the end. – arnt Jan 18 '22 at 13:51

1 Answers1

2

Apparently there are backend optimizers options in llvm. They are however not well documented [1,2]. The TargetMachine [3] class has functions getOptLevel and setOptLevel to set an optimization level from 0-3 for a specific target machine, so starting from there you can try to track where it is used.

[1] https://llvm.org/docs/CodeGenerator.html#ssa-based-machine-code-optimizations
[2] https://llvm.org/docs/CodeGenerator.html#late-machine-code-optimizations
[3] https://llvm.org/doxygen/classllvm_1_1TargetMachine.html

Jakob Stark
  • 3,346
  • 6
  • 22
  • Now it is 2022, however `Late Machine Code Optimizations` and `SSA-based Machine Code Optimizations` is still in status `To Be Written` ... sad story – lirui Oct 08 '22 at 13:08