compiler-constructionclangllvmllvm-irintermediate-language

Pros and cons of graphical and linear intermediate representation in compiler design?


There are two kinds of intermediate representation (IR) in compiler design, briefly introduced here: graphical (e.g. abstract syntax tree) and linear (e.g. LLVM IR). What are the pros and cons of the two?

I noticed Clang implemented both, but it seems only the linear representation (LLVM IR) is used in the LLVM backend.


Solution

  • That is a highly subjective decision on the part of the compiler developer. In my language I implement a AST graph which is then walked to produce the LLVM-IR. I could have easily gone from semantic checking to the IR but I do some refactoring/optimization, which the AST lends itself to nicely, prior to the IR generation.