2

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.

Leedehai
  • 3,660
  • 3
  • 21
  • 44
  • 1
    I am not sure if the LLVM-IR, especially as represented in memory would qualify as fully linear. Basic blocks are linked according to the control flow graph and SSA instructions link to uses and operands according to the data flow. It is only really linear in textual form. AFAIK GCCs GIMPLE is organized somewhat similarly. An advantage of representing the links directly is that the compiler does not need to constantly recompute them, for example to find out where the result of a computation is used. – PaulR May 17 '18 at 16:25

1 Answers1

0

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.

Frank C.
  • 7,758
  • 4
  • 35
  • 45