The unseen hero of modern compilers



Created by Olivier Cano / @kindermoumoute

November 5, 2017

Keyboard Shortcuts

Full Screen F
Next Slide Space bar
Slide Notes S
Thumbnail View Esc

View online at github.com/kindermoumoute/ssaform
Note: Some slides move down instead of to the side, so use the space bar to advance slides.

About Me

  • Student at Centrale Lille IG2I, northern France
  • Worked on Intel's Snap Telemetry Framework
  • Looking for my end-of-study internship
  • Passionate about programming


Started programming on calculators





Today is about SSA Form

SSA FORM

Definition


In compiler design, static single assignment form is a property of an intermediate representation (IR), which requires that each variable is assigned exactly once, and every variable is defined before it is used.

Intermediate reprensentation



Goals


  • Remove unecessary variables
  • Optimize basic mathematic expressions

In other words


  • Limit abusive use of registers
  • Use the most efficient instruction sets

SSA by example

Human point of view

z = i + x
x = 2 * z
    i, x and z are integer

  • 1 addition
  • 1 multiplication
  • 2 assignments

Dumb compiler

z = i + x
x = 2 * z
  • Load 2 variables
  • Add x to i
  • Storing the result
  • Load a constant and a variable
  • Multiply 2 by a variable
  • Storing the result

Compiler using SSA

x = (i + x) << 1
  • Load 2 variables
  • Adding a variable
  • Optimized multiplication by 2
  • Storing the result
z = i + x
x = 2 * z





"premature optimization is the root of all evil"

Thank you!





Sources