1 Induction Variables Region-Based Analysis Meet and Closure of Transfer Functions Affine Functions of Reference Variables.

Slides:



Advertisements
Similar presentations
&& Department of nskinfo-i educationwww.nsksofttch.com CS2303-THEORY OF COMPUTATION uChapter: Closure.
Advertisements

Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
Symbolic Analysis. Symbolic analysis tracks the values of variables in programs symbolically as expressions of input variables and other variables, which.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) SSA Guo, Yao.
1 Optimization Optimization = transformation that improves the performance of the target code Optimization must not change the output must not cause errors.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Jeffrey D. Ullman Stanford University. 2  A set of nodes N and edges E is a region if: 1.There is a header h in N that dominates all nodes in N. 2.If.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Architecture-dependent optimizations Functional units, delay slots and dependency analysis.
SSA.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Control Flow Analysis. Construct representations for the structure of flow-of-control of programs Control flow graphs represent the structure of flow-of-control.
1 Code Optimization. 2 The Code Optimizer Control flow analysis: control flow graph Data-flow analysis Transformations Front end Code generator Code optimizer.
1 EE5900 Advanced Embedded System For Smart Infrastructure Static Scheduling.
Discussion #33 Adjacency Matrices. Topics Adjacency matrix for a directed graph Reachability Algorithmic Complexity and Correctness –Big Oh –Proofs of.
1 CS 201 Compiler Construction Lecture 7 Code Optimizations: Partial Redundancy Elimination.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Lectures on Network Flows
Example in SSA X := Y op Z in out F X := Y op Z (in) = in [ { X ! Y op Z } X :=  (Y,Z) in 0 out F X :=   (in 0, in 1 ) = (in 0 Å in 1 ) [ { X ! E |
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
1 Constant Propagation A More Complex Semilattice A Nondistributive Framework.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
1 CS 201 Compiler Construction Lecture 3 Data Flow Analysis.
Aho-Corasick String Matching An Efficient String Matching.
Loop invariant detection using SSA An expression is invariant in a loop L iff: (base cases) –it’s a constant –it’s a variable use, all of whose single.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
1 Data-Flow Frameworks Lattice-Theoretic Formulation Meet-Over-Paths Solution Monotonicity/Distributivity.
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Loops Guo, Yao.
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Global optimization. Data flow analysis To generate better code, need to examine definitions and uses of variables beyond basic blocks. With use- definition.
PSUCS322 HM 1 Languages and Compiler Design II IR Code Optimization Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU.
1 Generalizing Map-Reduce The Computational Model Map-Reduce-Like Algorithms Computing Joins.
1 Regular Expressions Definitions Equivalence to Finite Automata.
Constant Propagation. The constant propagation framework is different from all the data-flow problems discussed so far, in that It has an unbounded set.
1 Region-Based Data Flow Analysis. 2 Loops Loops in programs deserve special treatment Because programs spend most of their time executing loops, improving.
UNC Chapel Hill M. C. Lin Point Location Reading: Chapter 6 of the Textbook Driving Applications –Knowing Where You Are in GIS Related Applications –Triangulation.
1 Data-Flow Analysis Proving Little Theorems Data-Flow Equations Major Examples.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
By: Pashootan Vaezipoor Path Invariant Simon Fraser University – Spring 09.
Higher Grade Computing Studies 4. Standard Algorithms Higher Computing Software Development S. McCrossan 1 Linear Search This algorithm allows the programmer.
Jeffrey D. Ullman Stanford University. 2 boolean x = true; while (x) {... // no change to x }  Doesn’t terminate.  Proof: only assignment to x is at.
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Loops.
1 Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism.
CS 614: Theory and Construction of Compilers Lecture 15 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
1 Control Flow Graphs. 2 Optimizations Code transformations to improve program –Mainly: improve execution time –Also: reduce program size Can be done.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
1 CS 201 Compiler Construction Lecture 2 Control Flow Analysis.
Dr. Tamer Samy Gaafar Lec. 2 Transfer Functions & Block Diagrams.
1 Code Optimization Chapter 9 (1 st ed. Ch.10) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Loops Simone Campanoni
Lecture 5 Partial Redundancy Elimination
CS 201 Compiler Construction
Chapter 2 Resistive Circuits
Finding a Path With Largest Smallest Edge
Princeton University Spring 2016
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
CS 201 Compiler Construction
Control Flow Analysis CS 4501 Baishakhi Ray.
TARGET CODE GENERATION
Instructor: Alexander Stoytchev
Optimizations using SSA
Control Flow Analysis (Chapter 7)
Interval Partitioning of a Flow Graph
EECS 583 – Class 4 If-conversion
CSC D70: Compiler Optimization LICM: Loop Invariant Code Motion
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Presentation transcript:

1 Induction Variables Region-Based Analysis Meet and Closure of Transfer Functions Affine Functions of Reference Variables

2 Regions uA set of nodes N and edges E is a region if: 1.There is a header h in N that dominates all nodes in N. 2.If n ≠ h is in N, then all predecessors of n are also in N. 3.E consists of all edges between nodes in N, possibly excluding nodes that enter h.

3 T1-T2 Reduction uFor reducible flow graphs, we can “reduce” the graph by two region- creating transformations. wT1: Remove a loop from a node. wT2: combine two nodes n and m such that m’s only predecessor is n, and m is not the entry.

4 Example: T1-T2 Reduction T2

5 Example: T1-T2 Reduction T1

6 Example: T1-T2 Reduction T2

7 Example: T1-T2 Reduction T2

8 Example: T1-T2 Reduction T1

9 Example: T1-T2 Reduction 12345

10 Regions Constructed During T1-T2 Reduction uEach node represents a set of nodes and edges of the original flow graph. uEach edge represents one or more edges of the original flow graph.

11 Regions Constructed During T1-T2 Reduction --- (2) uT2: Take the union of the two sets of nodes and edges. Then add edges represented by the edge between the two combined nodes. uT1: Add edges represented by the loop edge removed.

12 Example: T1-T2 Reduction

13 Region-Based Analysis --- (1) uFirst, compute for each region, smallest- to-largest, some transfer functions: 1.For region R with subregion S: f R,IN[S] = meet over paths from the header of R to the header of S, staying within R. 2.For each region R with exit block (= has a successor outside R) B, f R,OUT[B] = meet over paths within R from header of R to end of B.

14 Example: Transfer Functions R S f R,IN[S] = f 1 (f 2 f 3 )* f S,OUT[2] = f 2 (f 3 f 2 )* f R,OUT[2] = f 1 f 2 (f 3 f 2 )* f R,OUT[4] = f 1 f 4

15 Example: Meet R T f R,OUT[2] = f 1 f 2 (f 3 f 2 )* f R,OUT[4] = f 1 f 4 f T,IN[5] = f 1 f 4 ∧ f 1 f 2 (f 3 f 2 )*

16 Additional Assumptions uWe can take the meet of transfer functions.  [f ∧ g](x) = f(x) ∧ g(x). uThere is a closure f* for each transfer function f.  f* = f 0 ∧ f 1 ∧ f 2 ∧ … Note f 0 = identity, f 1 = f.

17 Example: RD’s  Meet of transfer functions f(x) = (x - K) ∪ G and g(x) = (x - K’) ∪ G’ corresponds to the paths of f and g in parallel.  Thus, [f ∪ g](x) = (x – (K ∩ K’) ∪ (G ∪ G’)).  f*(x) = x ∪ f(x) ∪ f(f(x)) ∪ … = x ∪ (x – K) ∪ G ∪ (x - K ∪ G) – K ∪ G … = x ∪ G. f(x) f(f(x))

18 Region-Based Analysis --- (2) uFinally, having computed f R’,IN[R] wR = entire flow graph; R’ = R plus dummy entry proceed largest-to-smallest, computing IN[h], for the header h of each subregion. uSince every node is the header of some region, we have all the IN’s, from which we can compute the OUT’s.

19 Example: Top-Down Finale R S T IN[1] = f R’,IN[R] (v ENTRY ) U IN[2] = f U,IN[S] (IN[1]) IN[3] = f S,IN[3] (IN[2])

20 New Topic: Symbolic Analysis uValues V are mappings from variables to expressions of reference variables. uExample: m(a) = 2i; m(b) = i+j. wi and j are the reference variables.

21 Application to Induction Variables uReference variables are basic induction variables = counts of the number of times around some loop. uV consists of affine mappings = each variable is mapped to either: 1.A linear function of the reference variables, or 2.NAA = “Not an affine” mapping, or 3.UNDEF = top element = “nothing known.”

22 Example: Affine Mapping m(a) = 2i + 3j +4 m(b) = NAA m(c) = 4i + 1 m(d) = UNDEF

23 Induction Variable Discovery uNatural application of region-based analysis. uEach loop is a region, and its induction variables can be discovered by a framework based on affine mappings. uIn region-based analysis, you don’t even need the top element, UNDEF.

24 Example: A Transfer Function  Let f be the transfer function associated with a block containing only a = a+10. uLet f(m) = m’. wm’(a) = m(a)  m’(x) = m(x) for all x ≠ a. uBook uses the notation f(m)(a) = m(a), etc., to avoid having to name f(m).

25 Example: Meet  (f ∧ g)(m)(x) = wf(m)(x) if f(m)(x) = g(m)(x). wNAA otherwise. uNote: above assumes no occurrences of UNDEF. How would you treat the case where f(m)(x) or g(m)(x), or both, are UNDEF?

26 Example: Some Analysis a=b+3 b=a+2 a=a+5 B1 B5 B2 B4 B3 f B3 (m) (a) = m(a) (b) = m(a)+2 f B2 (m) (a) = m(a)+5 (b) = m(b) f B4 (m) (a) = m(b)+3 (b) = m(b) R f R,OUT[B4] (m) (a) = m(a)+5 (b) = m(a)+2

27 Example: Meet a=b+3 b=a+2 a=a+5 B1 B5 B2 B4 B3 f B2 (m) (a) = m(a)+5 (b) = m(b) R f R,OUT[B4] (m) (a) = m(a)+5 (b) = m(a)+2 S f S,OUT[B5] (m) (a) = m(a)+5 (b) = NAA

28 Handling Loop Regions uTreat the iteration count i as a basic induction variable. uIf f(m)(x) = m(x)+c, then f i (m)(x) = m(x)+ci. uSome other cases, e.g., where m(x) is an affine function of basic induction variables, in book.

29 Example: The Entire Loop a=b+3 b=a+2 a=a+5 B1 B5 B2 B4 B3 S f S,OUT[B5] (m) (a) = m(a)+5 (b) = NAA T f S,OUT[B5] (m) (a) = m(a)+5i (b) = NAA i OUT i [B3](m) (a) = m(a)+5i (b) = m(a)+5i+2 OUT i [B4](m) (a) = m(a)+5i+5 (b) = m(a)+5i+2 OUT i [B2](m) (a) = m(a)+5i+5 (b) = NAA OUT i [B5](m) (a) = m(a)+5i+5 (b) = NAA

30 Taking Advantage of Affine Expressions uReplace the loop counter variable by one of the induction variables (variables that are mapped to an affine expression of the loop count at the point were the loop count is tested).

31 Example: Assume i is Loop Counter i<10? a=b+3 b=a+2 a=a+5 i=i+1 B1 B5 B2 B4 B3 i=0 a=30 Here, the value of a is m(a)+5i, where m(a) is the value of a before entering the loop, and i is the number of iterations of the loop so far. Since a=30 when i=0, replace “i<10?” by “a<80?”. If i is dead on exit from the loop, delete “i=i+1” and “i=0”.

32 Example: Revised Code a<80? a=b+3 b=a+2 a=a+5 B1 B5 B2 B4 B3 a=30