Get Assembly code after every optimization GCC makes?

前端 未结 7 2052
不知归路
不知归路 2020-12-19 00:19

From Optimization Compiler on Wikipedia,

Compiler optimization is generally implemented using a sequence of optimizing transformations

7条回答
  •  执笔经年
    2020-12-19 01:12

    If you would like to study compiler optimization and are agnostic to the compiler, then take a look at the Clang/LLVM projects. Clang is a C compiler that can output LLVM IR and LLVM commands can apply specific optimization passes individually.

    Output LLVM IR:

    clang test.c -S -emit-llvm -o test.ll
    

    Perform optimization pass:

    opt test.ll - -S -o test_opt.ll
    

    Compile to assembly:

    llc test.ll -o test.s
    

提交回复
热议问题