clang description:
clang is a C, C++, and Objective-C compiler which encompasses preprocessing, parsing, optimization, code generation, assembly, and linking.
clang 编译 C文件过程:
1、Preprocessing 对头文件预处理
2、Parsing and Semantic Analysis 将输入文件生成“Abstract Syntax Tree”(AST)
3、Code Generation and Optimization:This stage translates an AST into low-level intermediate code(LLVM IR),This phase is responsible for optimizing the generated code and handling target-specific code generation.做优化并生成.s的汇编文件。
4、在生成可执行文件并target linker
常用OPTIONS 编译选项说明:
-c
Run all of the above, plus the assembler, generating a target “.o” object file.
Language Selection and Mode Options
-stdlib=
Specify the C++ standard library to use; supported options are libstdc++ and libc++. If not specified, platform default will be used.
-fno-builtin
Disable special handling and optimizations of builtin functions like strlen() and malloc().
Code Generation Options
Driver Options
Diagnostics Options
Preprocessor Options
face_detection的run.tcl
exec clang ${design}.c -emit-llvm -c -fno-builtin -O1 -mllvm -disable-llvm-optzns -fno-vectorize -fno-slp-vectorize -fno-unroll-loops -o ${design}_O1.bc
Clang为LLVM提供的C语言编译器,默认参数可以生成本机可执行的二进制程序。-S和-c参数与GCC一样,可分别生成.s汇编文件与.o目标文件。
-emit-llvm选项可与-S或-c选项一起使用,以分别为代码生成LLVM .ll或.bc文件。
-mllvm Additional arguments to forward to LLVM’s option processing