Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang compiler stages

Tags:

llvm

clang

Clang Compiler is built based on LLVM infrastructure, Clang frontend takes the C/C++ source code and generates the LLVM-IR, who does the job of using the Optimizer and the code generation?

Since the optimizer pass libraries are to be strategically placed and called in an order to generate the optimized code, where is the order specified, also who generates the target code? Is this part of Clang fronted program or is there any other program that does this optimization and generation?

like image 703
Bharadwaj Avatar asked Oct 30 '22 23:10

Bharadwaj


1 Answers

There are actually two clangs, so to speak.

One is a front-end: it just does parsing, builds an Abstract Syntax Tree(AST), and applies various semantic checks. It also can do some static analysis and other helpful things. One can access the front-end using -cc1 option, e.g.: clang -cc1 -ast-dump

Second one is a driver: it takes AST from front-end and emits LLVM IR while applying some optimizations, and then making all the other magic such as building object files and linking various components together. This is what usually happens when one calls clang main.c or similar command.

Please, consider looking at help provided by both clangs:

clang -help
clang -help-hidden
clang -cc1 -help
clang -cc1 -help-hidden
like image 101
AlexDenisov Avatar answered Nov 13 '22 04:11

AlexDenisov