Bitcode and opt level


  1. what tools we have in LLVM to convert bitcode into IR?
  2. can one compile C/CPP file to bitcode with 1 opt level and than compile it to assenbly using different opt level?
    2.1 basically I would like to compile C/CPP file with -O0 to bitcode and than later compile the bitcode to object with any other opt level
  3. same as 2 but with other optimization flags like unroll, vectorization etc.


Bitcode is IR in binary form. llvm-dis will convert that to textual form, llvm-as will convert the textual form back to bitcode.

It’s entirely possible to compile to bitcode at -O0 and then optimize it later with whatever flags you want. Beware that by default, clang -O0 will annotate each function with the optnone attribute, meaning most optimizations will have no effect. You can avoid this by compiling your C/C++ with clang -O0 -Xclang -disable-O0-optnone.

thanks for the explanation.
we have a bc generated by glow. when I compile it using clang to assembly with Oz it still vectorize and unroll loops although it should not be done.
I see very manor changes between compiling it with -O3 or -Oz.
so I wondered what do I miss.
if there are attributes that override opt level, how can I see it?

If you just want to look at the IR, use llvm-dis to “disassemble” the bitcode to textual IR. Then you can look at the attributes on different functions and see what is going on. There are descriptions of the attributes here.