cs 201 compiler construction

18
1 CS 201 Compiler Construction Lecture Interprocedural Data Flow Analysis

Upload: john-franklin

Post on 03-Jan-2016

37 views

Category:

Documents


0 download

DESCRIPTION

CS 201 Compiler Construction. Lecture Interprocedural Data Flow Analysis. Intraprocedural Analysis. Individual procedures are analyzed in isolation; worst-case assumpltion are made while processing call sites. Example:. X = 3; P(); … = X - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 201 Compiler Construction

1

CS 201Compiler Construction

LectureInterprocedural Data Flow Analysis

Page 2: CS 201 Compiler Construction

2

Intraprocedural Analysis

• Individual procedures are analyzed in isolation; • worst-case assumpltion are made while

processing call sites.Example:

X = 3;P();… = X Does definiton X=3 reach this point? Yes Is X a constant? NoWe assume that P() does not kill any definition for reaching definitions analysis and we assumeP() kills all constants that reach the call P().

Page 3: CS 201 Compiler Construction

Interprocedural Analysis

By considering interactions between calling and called procedures, analyze the whole program.

Challenges• Scoping Rules• Aliasing due to reference parameters

Procedure P (f1,f2)f1 = …f2 = ……. = f1 where if f1 defined ? f1

=… what about call P(X,X)?

Page 4: CS 201 Compiler Construction

Interprocedural AnalysisChallenges contd…• Calling Context – cannot represent call-return

using simple control flow edges.

Invalid paths are created by simple control flow edges causing definition of X at statement 1 to reach use of X at statement 4.

Page 5: CS 201 Compiler Construction

Handling Calling Context

Various Approaches:1.Procedure Inlining – replace the call by

procedure body.Drawbacks– Code size increases– Recursion causes problems

2.Call String Approach – add calling context information to data flow values by tagging them with call-return history.

5

Page 6: CS 201 Compiler Construction

Handling Calling Context

3. Functional ApproachTwo phases

• Analyze effect of procedure invocation independent of calling context find a summary transfer function for the entire procedure

• Analyze each procedure using summary functions for all called procedures

6

Page 7: CS 201 Compiler Construction

Functional Approach

7

Page 8: CS 201 Compiler Construction

Functional Approach Contd..

8

Page 9: CS 201 Compiler Construction

Functional Approach Contd..

9

Page 10: CS 201 Compiler Construction

Functional Approach Contd..

10

Page 11: CS 201 Compiler Construction

Functional Approach Contd..

11

Page 12: CS 201 Compiler Construction

Functional Approach Contd..

12

Page 13: CS 201 Compiler Construction

Example: Available Expressions

13

Page 14: CS 201 Compiler Construction

Example: Available Expressions

14

Page 15: CS 201 Compiler Construction

Example: Available Expressions

15

Page 16: CS 201 Compiler Construction

Example: Available Expressions

16

Summary functions

Page 17: CS 201 Compiler Construction

Example: Available Expressions

17

Page 18: CS 201 Compiler Construction

18

Sample ProblemsInterprocedural Data Flow Analysis