Program Representations - Advanced Compiler - Lecture Slides , Slides of Computer Science

These are the Lecture Slides of Advanced Compiler which includes Partial Transfer Functions, Input Information, Output Information, Data-Based Context Sensitivity, Bottom-Up Example, Infinite Domains, Interprocedural Analysis etc. Key important points are: Program Representations, Input Languages, Typed Binaries, Source-Level Debugging, High-Level Syntax, Abstract Syntax Tree, Translate Input Programs, Assembly Code, Virtual Machine Code

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharmaa
dharmaa 🇮🇳

4.4

(19)

149 documents

1 / 32

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Program Representations
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Program Representations - Advanced Compiler - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Program Representations

Representing programs

  • Goals

Option 1: high-level syntax based IR

  • Represent source-level structures and expressions directly
  • Example: Abstract Syntax Tree

Option 2: low-level IR

  • Translate input programs into low-level primitive chunks, often close to the target machine
  • Examples: assembly code, virtual machine code (e.g. stack machines), three- address code, register- transfer language (RTL) - Standard RTL instrs:

Comparison

Comparison

  • Advantages of high-level rep
    • analysis can exploit high-level knowledge of constructs
    • easy to map to source code (debugging, profiling)
  • Advantages of low-level rep
    • can do low-level, machine specific reasoning
    • can be language-independent
  • Can mix multiple reps in the same compiler

Control dependencies

  • Option 1: high-level representation
    • control implicit in semantics of AST nodes
  • Option 2: control flow graph (CFG)
    • nodes are individual instructions
    • edges represent control flow between instructions
  • Options 2b: CFG with basic blocks
    • basic block: sequence of instructions that don’t have any branches, and that have a single entry point
    • BB can make analysis more efficient: compute flow functions for an entire BB before start of analysis

Control dependencies

  • CFG does not capture loops very well
  • Some fancier options include:
    • the Control Dependence Graph
    • the Program Dependence Graph
  • More on this later. Let’s first look at data dependencies

Def/use chains

  • Directly captures dataflow
    • works well for things like constant prop
  • But...
  • Ignores control flow
    • misses some opt opportunities since conservatively considers all paths
    • not executable by itself (for example, need to keep CFG around)
    • not appropriate for code motion transformations
  • Must update after each transformation
  • Space consuming

SSA

  • Static Single Assignment
    • invariant: each use of a variable has only one def

SSA

  • Create a new variable for each def
  • Insert φ pseudo-assignments at merge points
  • Adjust uses to refer to appropriate new names
  • Question: how can one figure out where to insert φ nodes using a liveness analysis and a reaching defns analysis.

Converting back from SSA

  • Semantics of x 3 := φ(x 1 , x 2 )
    • set x 3 to xi if execution came from ith predecessor
  • How to implement φ nodes?

Common Sub-expression Elim

  • Want to compute when an expression is available in a var
  • Domain:

Flow functions

X := Y op Z

in

out

FX := Y op Z (in) =

X := Y

in

out

FX := Y(in) =