Sparse Conditional Constant Propagation

Similar documents
Sparse Conditional Constant Propagation

Sparse Conditional Constant Propagation

Introduction to Machine-Independent Optimizations - 6

Using Static Single Assignment Form

Constant Propagation with Conditional Branches

Constant Propagation

Live Variable Analysis. Work List Iterative Algorithm Rehashed

Reuse Optimization. LLVM Compiler Infrastructure. Local Value Numbering. Local Value Numbering (cont)

Combining Optimizations: Sparse Conditional Constant Propagation

The Static Single Assignment Form:

Calvin Lin The University of Texas at Austin

A Sparse Algorithm for Predicated Global Value Numbering

A Propagation Engine for GCC

Data Flow Analysis. Program Analysis

Data Flow Analysis. Agenda CS738: Advanced Compiler Optimizations. 3-address Code Format. Assumptions

Computing Static Single Assignment (SSA) Form. Control Flow Analysis. Overview. Last Time. Constant propagation Dominator relationships

Rematerialization. Graph Coloring Register Allocation. Some expressions are especially simple to recompute: Last Time

Static Single Assignment (SSA) Form

Control-Flow Analysis

Program analysis for determining opportunities for optimization: 2. analysis: dataow Organization 1. What kind of optimizations are useful? lattice al

Compiler Construction 2009/2010 SSA Static Single Assignment Form

CSE P 501 Compilers. SSA Hal Perkins Spring UW CSE P 501 Spring 2018 V-1

Department of Computer Sciences CS502. Purdue University is an Equal Opportunity/Equal Access institution.

SSA Construction. Daniel Grund & Sebastian Hack. CC Winter Term 09/10. Saarland University

An Overview of GCC Architecture (source: wikipedia) Control-Flow Analysis and Loop Detection

Induction Variable Identification (cont)

Combining Analyses, Combining Optimizations - Summary

Sta$c Single Assignment (SSA) Form

Dataflow Analysis. Xiaokang Qiu Purdue University. October 17, 2018 ECE 468

Intermediate Representations Part II

Compiler Design. Fall Data-Flow Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Data-flow Analysis - Part 2

Advanced Compiler Construction

Calvin Lin The University of Texas at Austin

A Bad Name. CS 2210: Optimization. Register Allocation. Optimization. Reaching Definitions. Dataflow Analyses 4/10/2013

Control Flow Analysis & Def-Use. Hwansoo Han

EECS 583 Class 6 Dataflow Analysis

What If. Static Single Assignment Form. Phi Functions. What does φ(v i,v j ) Mean?

Advanced Compilers CMPSCI 710 Spring 2003 Dominators, etc.

Optimizations. Optimization Safety. Optimization Safety CS412/CS413. Introduction to Compilers Tim Teitelbaum

CSE 501 Midterm Exam: Sketch of Some Plausible Solutions Winter 1997

Compiler Passes. Optimization. The Role of the Optimizer. Optimizations. The Optimizer (or Middle End) Traditional Three-pass Compiler

Graphs & Digraphs Tuesday, November 06, 2007

Compiler Design Spring 2017

Why Global Dataflow Analysis?

Data-flow Analysis. Y.N. Srikant. Department of Computer Science and Automation Indian Institute of Science Bangalore

CONTROL FLOW ANALYSIS. The slides adapted from Vikram Adve

Review; questions Basic Analyses (2) Assign (see Schedule for links)

Dataflow Analysis 2. Data-flow Analysis. Algorithm. Example. Control flow graph (CFG)

Redundant Computation Elimination Optimizations. Redundancy Elimination. Value Numbering CS2210

Acknowledgement. Flow Graph Theory. Depth First Search. Speeding up DFA 8/16/2016

EECS 583 Class 8 Classic Optimization

Extended SSA with factored use-def chains to support optimization and parallelism

Simple and Efficient Construction of Static Single Assignment Form

Program Optimizations using Data-Flow Analysis

Lecture 3 Local Optimizations, Intro to SSA

Example of Global Data-Flow Analysis

The Development of Static Single Assignment Form

CS 426 Fall Machine Problem 4. Machine Problem 4. CS 426 Compiler Construction Fall Semester 2017

ECE 5775 High-Level Digital Design Automation Fall More CFG Static Single Assignment

Goals of Program Optimization (1 of 2)

COMPILER DESIGN - CODE OPTIMIZATION

Example. Example. Constant Propagation in SSA

Dataflow analysis (ctd.)

arxiv: v2 [cs.pl] 16 Sep 2014

Data Flow Analysis. CSCE Lecture 9-02/15/2018

Compiler Optimization and Code Generation

Points-To Analysis with Efficient Strong Updates

CS 4120 Lecture 31 Interprocedural analysis, fixed-point algorithms 9 November 2011 Lecturer: Andrew Myers

Alias Analysis for Intermediate Code

Register Allocation in Just-in-Time Compilers: 15 Years of Linear Scan

Register Allocation (wrapup) & Code Scheduling. Constructing and Representing the Interference Graph. Adjacency List CS2210

Alias Analysis for Intermediate Code

Lecture Notes on Static Single Assignment Form

Register allocation. CS Compiler Design. Liveness analysis. Register allocation. Liveness analysis and Register allocation. V.

Single-Pass Generation of Static Single Assignment Form for Structured Languages

Conditional Elimination through Code Duplication

Intermediate Representation (IR)

Topic I (d): Static Single Assignment Form (SSA)

EECS 583 Class 6 Dataflow Analysis

Composing Dataflow Analyses and Transformations

CS553 Lecture Generalizing Data-flow Analysis 3

Advanced Compiler Construction

Introduction to Machine-Independent Optimizations - 4

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Loop Invariant Code Motion. Background: ud- and du-chains. Upward Exposed Uses. Identifying Loop Invariant Code. Last Time Control flow analysis

EECS 583 Class 6 More Dataflow Analysis

CS422 Computer Architecture

Anticipation-based partial redundancy elimination for static single assignment form

Compiler Optimizations. Chapter 8, Section 8.5 Chapter 9, Section 9.1.7

Intermediate representation

Data Flow Information. already computed

Lecture Notes on Static Single Assignment Form

Lecture 21 CIS 341: COMPILERS

Lecture 6 Foundations of Data Flow Analysis

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Lecture 6. Register Allocation. I. Introduction. II. Abstraction and the Problem III. Algorithm

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Transcription:

CS738: Advanced Compiler Optimizations Sparse Simple Constant Propagation (SSC) Sparse Conditional Constant Propagation Amey Karkare karkare@cse.iitk.ac.in Improved analysis time over Simple Constant Propagation Finds all simple constant Same class as Simple Constant Propagation http://www.cse.iitk.ac.in/~karkare/cs738 Department of CSE, IIT Kanpur Motivating Example Dashed edges denote SSA def-use chains ENTRY a = 2 Preparations for SSC Analysis b = 3 Convert the program to SSA form a < b true false c1 = 4 c2 = 5 One statement per basic block Add connections called SSA edges Connect (unique) definition point of a variable to its use points Same as def-use chains c3 = φ(c1, c2) EXIT

SSC Algorithm: Initialization SSC Algorithm: Iterative Actions Evaluate expressions involving constants only and assign the value (c) to variable on LHS If expression can not be evaluated at compile time, assign Else (for expression contains variables) assign Initialize worklist WL with SSA edges whose def is not Algorithm terminates when WL is empty Take an SSA edge E out of WL Take meet of the value at def end and the use end of E for the variable defined at def end If the meet value is different from use value, replace the use by the meet Recompute the def d at the use end of E If the recomputed value is lower than the stored value, add all SSA edges originating at d Meet for φ-function SSC Algorithm: Complexity Height of CP lattice = 2 v = φ(v 1, v 2,..., v k ) ValueOf(v) = v 1 v 2... v n Each SSA edge is examined at most twice, for each lowering Theoritical size of SSA graph: O(V E) Practical size: linear in the program size

SSC: Practice Example ENTRY SSC: Practice Example a = 2 b = 3 true a < b false What if we change c1 = 4 to c1 = 5? c1 = 4 c2 = 5 c3 = φ(c1, c2) EXIT Sparse Condtional Constant Propagation (SCC) SCC Algorithm: Key Idea Constant Propagation with unreachable code elimination Ignore definitions that reach a use via a non-executable edge v = φ(v 1, v 2,..., v k ) ValueOf(v) = i ExecutablePath v i We ignore paths that are not yet marked executable

SCC Algorithm: Preparations SCC Algorithm: Initialization Two Worklists Flow Worklist (FWL) Worklist of flow graph edges SSA Worklist (SWL) Worlist of SSA graph edges Execution Halts when both worklists are empty Associate a flag, the ExecutableFlag, with every flow graph edge to control the evaluation of φ-function in the destination node Initialize FWL to contain edges leaving ENTRY node Initialize SWL to empty Each ExecutableFlag is false initially Each value is initially (Optimistic) SCC Algorithm: Iterations SCC Algorithm: Processing FWL Item Item is flow graph edge Remove an item from either worklist process the item (described next) If ExecutableFlag is true, do nothing Otherwise Mark the ExecutableFlag as true Visit-φ for all φ-functions in the destination If only one of the ExecutableFlags of incoming flow graph edges for dest is true (dest visted for the first time), then VisitExpression for all expressions in dest If the dest contains only one outgoing flow graph edge, add that edge to FWL

SCC Algorithm: Processing SWL Item SCC Algorithm: Visit-φ Item is SSA edge If dest is a φ-function, Visit-φ If dest is an expression and any of ExecutableFlags for the incoming flow graph edges of dest is true, perform VisitExpression v = φ(v 1, v 2,..., v k ) If i th incoming edge s ExecutableFlag is true, val i = ValueOf(v i ) else val i = ValueOf(v) = i val i SCC Algorithm: VisitExpression SCC Algorithm: Complexity Evaluate the expression using values of operands and rules for operators If the result is same as old, nothing to do Otherwise If the expression is part of assignment, add all outgoing SSA edges to SWL if the expression controls a conditional branch, then if the result is, add all outgoing flow edges to FWL if the value is constant c, only the corresponding flow graph edge is added to FWL Value can not be (why?) Each SSA edge is examined twice Flow graph nodes are visited once for every incoming edge Complexity = O(# of SSA edges + # of flow graph edges)

SCC Algorithm: Correctness and Precision Practice Example ENTRY a = 2 SCC is conservative Never labels a variable value as a constant SCC is at least as powerful as Conditional Constant Propagation (CC) Finds all constants as CC does PROOFs: In paper Constant propagation with conditional branches by Mark N. Wegman, F. Kenneth Zadeck, ACM TOPLAS 1991. b = 3 a < b true false c1 = 4 c2 = 5 c3 = φ(c1, c2) EXIT