LearnViz CompSci
Home / Learn / Languages & Compilers / Intermediate Representations

Intermediate Topic 26 of 50 Languages & Compilers

Intermediate Representations

Language-neutral forms used between compiler stages.

How it works

An intermediate representation is the internal form a compiler uses between the source language and machine code. Examples include abstract syntax trees, three-address code, control flow graphs, static single assignment form, bytecode and LLVM IR. A good IR is simple, explicit about control and data flow, independent of both source language and target machine, and easy to analyze and transform. Compilers often use several IRs at different levels of abstraction.

Step-by-step walkthrough

  1. Different languages are translated into a common IR.
  2. Another language joins them.
  3. Optimizations are written once on the IR.
  4. The IR is then lowered to x86, ARM or others.
  5. This gives M plus N work instead of M times N.

Where it is used

Optimizations, analysis, cross-language compilation and support for many targets rely on IRs. LLVM IR, GCC GIMPLE, Java bytecode and MLIR are widely used examples.

Common pitfall

Overly low-level IRs lose high-level information needed for optimizations, while high-level ones make machine details hard. Maintaining many IRs increases complexity. Different phases must preserve semantics when lowering. Choose IR levels deliberately, dump and inspect IR when debugging optimizations, and verify invariants after each pass.

Where it fits in the course

Intermediate Representations is topic 26 of 50 in Languages & Compilers, rated Intermediate. It follows Parser Generators. The next topic is Three-Address Code.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Languages & Compilers quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Intermediate Representations?
Language-neutral forms used between compiler stages. It belongs to Languages & Compilers and is an intermediate-level topic.
Where do people use Intermediate Representations?
Optimizations, analysis, cross-language compilation and support for many targets rely on IRs.
What is the most common mistake with Intermediate Representations?
Overly low-level IRs lose high-level information needed for optimizations, while high-level ones make machine details hard.
What should I learn before this topic?
Start with Parser Generators, the topic just before it in Languages & Compilers.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Languages & Compilers quiz.
Is Intermediate Representations hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn Intermediate Representations?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Intermediate Representations?
Parser Generators, Three-Address Code, LL and LR Parsing are closely connected. The full list is in the related topics section of this page.
What should I study after Intermediate Representations?
Continue with Three-Address Code, the next topic in Languages & Compilers.

Related topics