31
SSA Form Seminar France April 27 to 30, 2009 Dr. Markus Schordan Deputy Program Director of Game Engineering UAS Technikum Wien

SSA Form Seminar France - compilers.cs.uni-saarland.de

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SSA Form Seminar France - compilers.cs.uni-saarland.de

SSA Form SeminarFrance

April 27 to 30, 2009

Dr. Markus SchordanDeputy Program Director of Game Engineering

UAS Technikum Wien

Page 2: SSA Form Seminar France - compilers.cs.uni-saarland.de

Overview• Computation of program information with SATIrE

– Flow-sensitivity and context-sensitivity

– Points-to analysis

– Shape analysis

– program annotations for making analysis resultspersistent

• Representation in SSA Form– Memory regions and indirections

– SSA Form for representing analysis results

– Code pattern detection

10/10/2008 Markus Schordan 2

Page 3: SSA Form Seminar France - compilers.cs.uni-saarland.de

References

• The Language of the Visitor Design PatternMarkus SchordanJournal of Universal Computer Science (JUCS), Vol. 12, No. 7, pp. 849-867, August 2006.Special Issue: Selected Papers from The 10th Brazilian Symposium on Programming Languages. Issue edited by Mariza Andrade Silva Bigonhaand Alex de Vasconcellos Garcia.

• Source Code based Component Recognition in Software Stacks forEmbedded SystemsDietmar Schreiner, Markus Schordan, Gergo Barany, Karl Göschka.In Proceedings of the 4th ASME/IEEE International Conference ofMechatronic and Embedded Systems and Applications (MESA 2008), pp. 463-468, ISBN: 978-1-4244-2368-2, Beijing, China, Oct 12-15, 2008.

10/10/2008 Markus Schordan 3

Page 4: SSA Form Seminar France - compilers.cs.uni-saarland.de

SATIrE: Static Analysis Tool Integration Engine

Activities - Projects

• ALL-TIMES– 7. EU FP– Dec 2007- Feb 2010– European timing analysis integration– Partners: MDH, TU Vienna, AbsInt,

Rapita, Symtavision, Gliwa

• CoSTA (timing analysis)– FWF, National (Austria)– Jul 2006 – Dec 2009

• ARTIST2– 6. EU FP– Sep 2004- Sep 2008

10/10/2008 Markus Schordan 4

Page 5: SSA Form Seminar France - compilers.cs.uni-saarland.de

SATIrE People

10/10/2008 Markus Schordan 5

SATIrE DevelopersStaff: Markus Schordan, Gergö Barany, Adrian Prantl, Dietmar Schreiner, Florian Brandner, Dietmar EbnerStudents: Viktor Pavlu, Mihai Ghete, Christoph Roschger, Christoph Bonitz, Günther Khyo, Christian Biesinger

Integrated Tools - InitiatorsLLNL-ROSE: Dan Quinlan (LLNL,CA,USA)PAG: Florian Martin (AbsInt)Termite: Adrian Prantl (TU Vienna)Clang: LLVM/Apple Community

SATIrE-Based Tools – InitiatorsTuBound: Adrian Prantl (TU Vienna)

SATIrE Downloadhttp://www.complang.tuwien.ac.at/satire

Page 6: SSA Form Seminar France - compilers.cs.uni-saarland.de

SATIrE: Static Analysis Tools Integration Engine

10/10/2008 Markus Schordan 8

SATIrE

Page 7: SSA Form Seminar France - compilers.cs.uni-saarland.de

SATIrE Analyses

10/10/2008 Markus Schordan 9

AnalysisName

ImplementationLanguage

Input FlowSensitive

ContextSensitive

„classic analyses“(RD, AE, LV, CP)

FULA (PAG) ICFG Yes Yes

Shape FULA (PAG) ICFG yes Yes

Points-to C++ AST No Yes

Type-Based Alias C++ AST No No

Interval FULA (PAG) ICFG Yes Yes

Loop-Bound Prolog (+Constraints) Interval No No

Page 8: SSA Form Seminar France - compilers.cs.uni-saarland.de

PAG – Analysis Specification

PROBLEM Reaching_Definitions

direction: forward

carrier: VarLabPairSetLifted

init: bot

init_start: lift({})

combine: comb

retfunc: comb

widening: wide

equal: eq

10/10/2008 Markus Schordan 10

TRANSFER

...

ExprStatement(exprstmt), _:

sl1_assignment(exprstmt,label,@);

SUPPORT

comb(a.b) = a lub b;

wide(a,b) = b;

eq(a,b) = (a=b);

Page 9: SSA Form Seminar France - compilers.cs.uni-saarland.de

PAG – Analysis Specification

10/10/2008 Markus Schordan 11

/* handling SL1 assignments in analysis */sl1_assignment::Expression,snum,VarLabPairSetLifted ->VarLabPairSetLifted;sl1_assignment(exp,lab,bot) = bot;sl1_assignment(exp,lab,top) = top;sl1_assignment(exp,lab,infoLifted) =let info <= infoLifted; incase exp of/* one variable on each side of assignment */AssignOp(VarRefExp(cvarname1) as VarRef1,

VarRefExp(cvarname2) as VarRef2)=>let x = varref_varid(varRef1); inlift(update_info(x,lab,info)) /* program variable */;

endcase;

/* update the analysis information with kill and gen functions */update_info::str,snum,VarLabPairSet -> VarLabPairSet;update_info(x,lab,info) = union(rdkill(x,info),rdgen(x,lab));

/* kill variable */rdkill::str,VarLabPairSet -> VarLabPairSet;rdkill(var,varset) = { (var1,lab1) | (var1,lab1) <-- varset,

if var1 != var };

Sets

Matching

Page 10: SSA Form Seminar France - compilers.cs.uni-saarland.de

Overview of Pointer Analyses

10/10/2008 Markus Schordan 14

Page 11: SSA Form Seminar France - compilers.cs.uni-saarland.de

Points-To Analysis

• Variant of Steensgaard‘s algorithm

• Flow-insensitive

• Consideres type information

• Consideres function pointers

• Handles full C

• Context-sensitive version: static call strings withfunction summaries

• Heap allocated data structures are considered bycall sites of malloc/new

10/10/2008 Markus Schordan 15

Page 12: SSA Form Seminar France - compilers.cs.uni-saarland.de

Shape Analysis

10/10/2008 Markus Schordan 16

Analyzed example program: list create, list reversal

Computes the shape of heap allocated

data structures for each program point

Page 13: SSA Form Seminar France - compilers.cs.uni-saarland.de

Shape AnalysisPrecision and Complexity

10/10/2008 Markus Schordan 17

Strong update Graph for each statement:

worst-case: 2n Nodes

Analyzed program: DSW-Algorithm

Page 14: SSA Form Seminar France - compilers.cs.uni-saarland.de

Running Example and SSA Forms

1. Scalar variables only

2. With pointers to local variables

3. Heap allocated data structures

10/10/2008 Markus Schordan 20

Page 15: SSA Form Seminar France - compilers.cs.uni-saarland.de

Artificial Sum (only scalar vars)

10/10/2008 Markus Schordan 21

Page 16: SSA Form Seminar France - compilers.cs.uni-saarland.de

Example: With Pointers

10/10/2008 Markus Schordan 23

Page 17: SSA Form Seminar France - compilers.cs.uni-saarland.de

Strong vs Weak Update

10/10/2008 Markus Schordan 24

Page 18: SSA Form Seminar France - compilers.cs.uni-saarland.de

Flow-Insensitive Points-To Analysis

10/10/2008 Markus Schordan 25

Page 19: SSA Form Seminar France - compilers.cs.uni-saarland.de

Memory Regions - Cases

10/10/2008 Markus Schordan 31

R1 R2 R3 R4

R12 R34

R1234

1. R12=R3; // partitions2. R1=R12; // sub-region is assigned a super-region3. R12=R1; // super-region is assigned a sub-region4. R12=R1; R12=R2; // complete region

(e.g. initialization)

• Partitions

• Subsets

Layers

Page 20: SSA Form Seminar France - compilers.cs.uni-saarland.de

Subsets and Partition-Layers

10/10/2008 Markus Schordan 32

Want to have an SSA where

• each variable representing a memory region that ispotentially modified, shows up on the LHS.

• each variable representing a memory region that isaccessed shows up on the RHS.

Solutions:• Use the superset that contains all mod/ref regions and

name it.• Use multi-assignments.

Page 21: SSA Form Seminar France - compilers.cs.uni-saarland.de

Pointer Analysis Precision

10/10/2008 Markus Schordan 33

a

b

ap

bpcp

a

b

ap

bpcp

a, b

ap

bpcp

1

2

3

Page 22: SSA Form Seminar France - compilers.cs.uni-saarland.de

Memory Regions

10/10/2008 Markus Schordan 34

r5

r4

r3

r2r1

r5

r4

r3

r2r1

r4

r3

r2r1

1

2

3

Page 23: SSA Form Seminar France - compilers.cs.uni-saarland.de

With Dynamic Data Structures

10/10/2008 Markus Schordan 37

Page 24: SSA Form Seminar France - compilers.cs.uni-saarland.de

Type-Supported Points-To [1]

10/10/2008 Markus Schordan 38

Before: 17: ap->next=b

Page 25: SSA Form Seminar France - compilers.cs.uni-saarland.de

Type-Supported Points-To [2]

10/10/2008 Markus Schordan 39

Collapsing after: 17: ap->next=b

Page 26: SSA Form Seminar France - compilers.cs.uni-saarland.de

Shape Analysis

10/10/2008 Markus Schordan 40

In general: requires cross-linking of shape graphs

(ongoing work)

Page 27: SSA Form Seminar France - compilers.cs.uni-saarland.de

rSSA Form: Dynamic DS

a=new List();b=new List();ap=a;bp=b;i=n; j=n; while (i>0) { ap->next=new List();ap=ap->next;i=i-1; j=i; while (j>0) {

bp->next=new List();bp=bp->next;j=j-1;

} } ap->next=b;

10/10/2008 Markus Schordan 41

r1.1=new ;r2.1=new ;r1.2=r1.1;r2.2=r2.1i.1=n.1; j.1=n.1; i.3=phi(i.1,i.2) j.5=phi(j.1,j.4)r1.5=phi(r1.2,r1.4)r2.6=phi(r2.2,r2.5)

while (i.3>0) { r1.3=r1.5 + new;r1.4=r1.3;i.2=i.3-1; j.2=i.2; j.4=phi(j.2,j.3)

r2.5=phi(r2.6,r2.4)

while (j.5>0) { r2.3=r2.5 + new;r2.4=r2.3;j.3=j.4-1;

} }

r1.6=r1.5 + r2.6;

r1: a,ap,ap->next

r2: b,bp,bp->next

preserving

definitions

Page 28: SSA Form Seminar France - compilers.cs.uni-saarland.de

Using SSA

• Region-based SSA Form allows to create a high-level abstraction of a program

• Design pattern detection

– Based on reduced program dependence graph

• Component recognition

– Based on type & field-access information(= regions)

10/10/2008 Markus Schordan 43

Page 29: SSA Form Seminar France - compilers.cs.uni-saarland.de

Design Pattern Detection

10/10/2008 Markus Schordan 44

Green nodes: accept methods

Blue nodes : visit methods

Call Graph

Page 30: SSA Form Seminar France - compilers.cs.uni-saarland.de

Component Recognition

10/10/2008 Markus Schordan 45

Unstructured

Unfiltered

Dependencies

Components

Filtered

Dependencies

Page 31: SSA Form Seminar France - compilers.cs.uni-saarland.de

Summary

• SATIrE: Static Analysis Tool Integration Engine

– Flow-sensitive context-sensitive analysis of C/C++

– Website: http://www.complang.tuwien.ac.at/satire

• Memory region based SSA Form

– The more precise the pointer analysis the morememory regions

– Scaling via memory sub-region relation

• Region-based SSA form with program informationsuitable for code pattern detection

10/10/2008 Markus Schordan 46