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

Calvin Lin The University of Texas at Austin

The Static Single Assignment Form:

A Sparse Algorithm for Predicated Global Value Numbering

A Propagation Engine for GCC

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

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

Control-Flow Analysis

Data Flow Analysis. Program 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.

Induction Variable Identification (cont)

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

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

Calvin Lin The University of Texas at Austin

Advanced Compiler Construction

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

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

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

Graphs & Digraphs Tuesday, November 06, 2007

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

Why Global Dataflow Analysis?

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

Redundant Computation Elimination Optimizations. Redundancy Elimination. Value Numbering CS2210

Compiler Design Spring 2017

EECS 583 Class 8 Classic Optimization

Program Optimizations using Data-Flow Analysis

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

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

CONTROL FLOW ANALYSIS. The slides adapted from Vikram Adve

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

Simple and Efficient Construction of Static Single Assignment Form

Lecture 3 Local Optimizations, Intro to SSA

Example of Global Data-Flow Analysis

Goals of Program Optimization (1 of 2)

The Development of Static Single Assignment Form

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

COMPILER DESIGN - CODE OPTIMIZATION

Example. Example. Constant Propagation in SSA

Dataflow analysis (ctd.)

Compiler Optimization and Code Generation

arxiv: v2 [cs.pl] 16 Sep 2014

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

Alias Analysis for Intermediate Code

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

Points-To Analysis with Efficient Strong Updates

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

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

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

Alias Analysis for Intermediate Code

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

CS553 Lecture Generalizing Data-flow Analysis 3

Conditional Elimination through Code Duplication

Lecture Notes on Static Single Assignment Form

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

Composing Dataflow Analyses and Transformations

Intermediate Representation (IR)

Advanced Compiler Construction

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

Principles of Program Analysis: Data Flow Analysis

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

EECS 583 Class 6 Dataflow Analysis

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

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

Introduction to Machine-Independent Optimizations - 4

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

Program Analysis. Uday Khedker. ( uday) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

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

Intermediate representation

EECS 583 Class 6 More Dataflow Analysis

Anticipation-based partial redundancy elimination for static single assignment form

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Data Flow Information. already computed

Lecture Notes on Static Single Assignment Form

7. Optimization! Prof. O. Nierstrasz! Lecture notes by Marcus Denker!

Lecture 21 CIS 341: COMPILERS

Transcription:

CS618: Program Analysis 2016-17 I st Semester Sparse Simple Constant Propagation (SSC) Sparse Conditional Constant Propagation Amey Karkare karkare@cse.iitk.ac.in karkare@cse.iitb.ac.in Improved analysis time over Simple Constant Propagation Finds all simple constant Same class as Simple Constant Propagation Department of CSE, IIT Kanpur/Bombay karkare, CSE, IITK/B CS618 1/22 karkare, CSE, IITK/B CS618 2/22 Motivating Example Preparations for SSC Analysis Dashed edges denote SSA def-use chains ENTRY a = 2 b = 3 a < b true false c1 = 4 c2 = 5 Convert the program to SSA form 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 karkare, CSE, IITK/B CS618 3/22 karkare, CSE, IITK/B CS618 4/22

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 karkare, CSE, IITK/B CS618 5/22 karkare, CSE, IITK/B CS618 6/22 Meet for φ-function SSC Algorithm: Complexity v = φ(v 1, v 2,...,v k ) ValueOf(v) = v 1 v 2... v n Height of CP lattice = 2 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 karkare, CSE, IITK/B CS618 7/22 karkare, CSE, IITK/B CS618 8/22

SSC: Practice Example ENTRY SSC: Practice Example a = 2 true b = 3 a < b false What if we change c1 = 4 to c1 = 5? c1 = 4 c2 = 5 c3 = φ(c1, c2) EXIT karkare, CSE, IITK/B CS618 9/22 karkare, CSE, IITK/B CS618 10/22 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 We ignore paths that are not yet marked executable v i karkare, CSE, IITK/B CS618 11/22 karkare, CSE, IITK/B CS618 12/22

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) karkare, CSE, IITK/B CS618 13/22 karkare, CSE, IITK/B CS618 14/22 SCC Algorithm: Iterations SCC Algorithm: Processing FWL Item Remove an item from either worklist process the item (described next) Item is flow graph edge 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 karkare, CSE, IITK/B CS618 15/22 karkare, CSE, IITK/B CS618 16/22

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 karkare, CSE, IITK/B CS618 17/22 karkare, CSE, IITK/B CS618 18/22 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) karkare, CSE, IITK/B CS618 19/22 karkare, CSE, IITK/B CS618 20/22

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 karkare, CSE, IITK/B CS618 21/22 karkare, CSE, IITK/B CS618 22/22