LLVM IR入门笔记

参考文章:GitHub - Evian-Zhang/llvm-ir-tutorial: LLVM IR入门指南

第一章 LLVM IR入门指南

clang test.c -o test
#经历了什么步骤

## 1. dump x.c -> ast
clang -Xclang -ast-dump -fsyntax-only test.c

##2.ast -> llvm IR
clang -S -emit-llvm test.c  
(clang -cc1 -disable-O0-optnone -S -emit-llvm test.c)

## 3. llvm IR -> llvm IR
opt test.ll -S --O3 
或者
clang -S -emit-llvm -O3 test.c

## 4. llvm IR -> asm
llc test.ll -o test.s

LLVM IR 是

- 内存中的IR

- IR也可以dump成 text/binary

clang -S -emit-llvm test.c -o test.ll    # dump成可读的llvm ir

clang -c -emit-llvm test.c -o test.bc    # dump成bin的llvm ir

也可以用这个来相互转换

llvm-as test.ll -o test.bc

llvm-dis test.bc -o test.ll

第二章 hello world

clang llvm.ll -o main

./main 

猜你喜欢

转载自blog.csdn.net/Chunying27/article/details/128798346