HJL
HJL

Reputation: 129

Is LLVM IR a graph?

I'm starting new research in the field of compiler optimization. As a start, I'm looking into several different papers related and encountered a few different optimization techniques.

One main thing I'm currently looking at is the compilers' technique that converting input source code into a graph (e.g. control-flow, data-flow, linked list, etc.), then performs optimization onto the graph and produces the machine code. Code-to-Graph-to-Code. For example, JIT compilers in the JavaScript engines, i.e. V8, ChakraCore, etc.

Then, I came across LLVM IR. Because of the earlier searches, my impression of optimization on code is doing on a graph like explained above. However, I do not believe that is the case for LLVM, but I'm not sure. I found that there are tools to generate a control-flow graph from the LLVM IR, but it doesn't mean it's optimizing the graph.

So, my question is "Is LLVM IR a graph?" If not, how does it optimize the code? Code-to-Code directly?

Upvotes: 2

Views: 764

Answers (1)

yugr
yugr

Reputation: 21886

LLVM IR (and it's backend form, Machine IR) is a traditional three-address code IR so technically is not a graph IR in the sense e.g. sea-of-nodes IR is. But it contains several graph structures in it: a graph of basic blocks (Control Flow Graph) and a graph of data dependencies (SSA def-use chains) which are used to simplify optimizations. In addition, during instruction selection phase in backend original LLVM IR is temporarily converted to a true graph IR - SelectionDAG.

Upvotes: 8

Related Questions