How to make clang compile to llvm IR

前端 未结 5 1671
感情败类
感情败类 2020-11-27 10:01

I want clang to compile my C/C++ code to LLVM bytecode rather than binary executable. How can I achieve that? And if I get the LLVM by

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 10:13

    If you have multiple files and you don't want to have to type each file, I would recommend that you follow these simple steps (I am using clang-3.8 but you can use any other version):

    1. generate all .ll files

      clang-3.8 -S -emit-llvm *.c
      
    2. link them into a single one

      llvm-link-3.8 -S -v -o single.ll *.ll
      
    3. (Optional) Optimise your code (maybe some alias analysis)

      opt-3.8 -S -O3 -aa -basicaaa -tbaa -licm single.ll -o optimised.ll
      
    4. Generate assembly (generates a optimised.s file)

      llc-3.8 optimised.ll
      
    5. Create executable (named a.out)

      clang-3.8 optimised.s
      

提交回复
热议问题