LLVM框架学习笔记(2)——使用LLC编译

那么上次提到了怎么编写IR代码,这次是如何给不同平台编译的笔记。

依旧使用我们的hello.c作为示范。

clang -Os -S -emit-llvm hello.c -o hello.ll
llc hello.ll

到上面为止都是通用的,下面就是指定平台:($为shell提示符)

$ clang -Os -S -emit-llvm hello.c -o hello.ll
$ llc -O3 hello.ll
$ clang hello.s -x assembler -o hello
$ file hello
hello: Mach-O 64-bit executable x86_64

可以看出在不加参数的情况下,默认的target和本机一样。若指明平台:

ARMv7:

$ clang -Os -S -emit-llvm hello.c -o hello.ll
$ llc -O3 hello.ll -march=arm -o hello-arm.s
$ clang hello-arm.s -x assembler -arch armv7 -isysroot $(xcrun  --sdk iphoneos --show-sdk-path) -o hello-armv7
$ file hello-armv7
hello-armv7: Mach-O executable arm

ARM64

$ clang -Os -S -emit-llvm hello.c -o hello.ll
$ llc -O3 hello.ll -march=arm64 -o hello-arm.s
$ clang hello-arm.s -x assembler -arch arm64 -isysroot $(xcrun  --sdk iphoneos --show-sdk-path) -o hello-arm64
$ file hello-arm64
hello-arm64: Mach-O 64-bit executable

当然,llc还支持很多其他的CPU,具体可以去官网查看。

2 thoughts on “LLVM框架学习笔记(2)——使用LLC编译”

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × four =