interprocedural path profiling david melski thomas reps university of wisconsin
TRANSCRIPT
![Page 1: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/1.jpg)
Interprocedural Path Profiling
David Melski
Thomas Reps
University of Wisconsin
![Page 2: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/2.jpg)
Introduction
• What is path profiling?– Counts the number of times particular path
fragments are executed
• Our work: extensions of Ball-Larus– New interprocedural techniques– New intraprocedural techniques
![Page 3: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/3.jpg)
Applications
• Program Optimization– Path-qualified dataflow analysis (Ammons, Larus)
• Software Maintenance– Path spectra (Reps et al.)– “Oddball” paths– Debugger applications
![Page 4: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/4.jpg)
Ball-Larus Tech.
• “Remove” cycles – Add surrogate edges– Remove backedges
Left with a DAG: have a finite
number of acyclic paths
![Page 5: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/5.jpg)
Ball-Larus Tech.
• Label each vertex v with numPaths[v],
(the number of paths from v to Exit.)
• Use bottom-up traversal
![Page 6: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/6.jpg)
Ball-Larus Tech.
• Label edges such that:
For each path p, p’s path number—the sum of p’s edges—is a unique value
pathNum = 0
pathNum = 3
pathNum = 1
pathNum = 2
![Page 7: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/7.jpg)
Ball-Larus Tech.
• Add Instrumentation:• Var. pathNum
Example: start w/ pathNum=0pathNum+=0 (pathNum=0)
pathNum+=0 (pathNum=0)pathNum+=0 (pathNum=0)
pathNum+=0 (pathNum=0)
pathNum+=0 (pathNum=0)Profile[pathNum] ++pathNum=2
![Page 8: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/8.jpg)
Edge Labels
![Page 9: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/9.jpg)
Introductory Example (main)int main() { double t, result = 0.0; int i = 1;
while( i <= 18 ) { if( (i%2) == 0 ) { t = pow( i, 2 ); result += t; } if( (i%3) == 0 ) { t = pow( i, 2 ); result += t; } i++; } return 0;}
( ) ( )2 32
1
92
1
6
j kj k
![Page 10: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/10.jpg)
Supergraph G*
• Unique vertices Entryglobal and Exitglobal
• CFG for each procedure P– Unique EntryP and ExitP
• call and return-site vertices for each procedure call
• call-edges and return-edges connect calls to procedures
![Page 11: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/11.jpg)
Invalid Path Example
• Do not want to consider invalid paths for profiling
![Page 12: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/12.jpg)
Valid Paths
pow
m ain
Entryg l o b a l
Exitg l o b a l
• Label interprocedural edges with parens
• Don’t accept paths with mismatched parens
( )
[}
{]
Invalid: ( { ] )Same-Level: ( { } )Unbalanced-Left: ( {
![Page 13: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/13.jpg)
Interprocedural Cycles
• Complicates interprocedural profiling
![Page 14: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/14.jpg)
Creating G*-fin
• Modify G*:– In each procedure:
• Add Gexit• Remove Backedges
– (Removes cycles in control-flow graphs)u8: Gexitpow
![Page 15: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/15.jpg)
Creating G*-fin
• Modify G* (cont):– Remove recursive
edges– (Removes cycles in
call graph)
R
main
Entryg l o b a l
Exitg l o b a l
![Page 16: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/16.jpg)
Observable Paths
• In G*-fin:– A finite number of unbalanced-left paths. – Each unbalanced-left path defines an
observable path—an item that we log in a profile.
– (observable paths are unbalanced-left because they may end in the middle of a procedure)
![Page 17: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/17.jpg)
Context-Prefix and Active-Suffix
S
Q
R
Entryg l o b a l
Exitg l o b a l
• Each path has– a context-prefix– an active-suffix– a counter
• The counter counts the executions of the active-suffix in the context of the context-prefix
![Page 18: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/18.jpg)
![Page 19: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/19.jpg)
![Page 20: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/20.jpg)
![Page 21: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/21.jpg)
![Page 22: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/22.jpg)
![Page 23: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/23.jpg)
![Page 24: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/24.jpg)
![Page 25: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/25.jpg)
![Page 26: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/26.jpg)
Overview: Instrumentation
• Each procedure Q takes additional parameters: – pathNum (passed by reference)– numPathsExitQ (passed by value)
• On a procedure call to Q from P, calculate numPathsExitQ for current context:– numPathsExitQ = yr(numPathsExitP)
![Page 27: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/27.jpg)
Overview: Instrumentation
numPathsExitPow = yr(numPathsExitMain)
pathNumOnEntryPow = pathNum
E.g., Function call:
![Page 28: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/28.jpg)
Overview: Instrumentation
pathNum += re(numPathsExitPow)
E.g., Edge Traversal:
![Page 29: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/29.jpg)
Overview: Instrumentation
pathNum += re(numPathsExitPow)Profile[pathNum] ++
pathNum = pathNumOnEntryPowpathNum += re(numPathsExitPow)
E.g., Backedge Traversal:
![Page 30: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/30.jpg)
Assigning y functions
• Solve the following equations:
Exit
GExit
Entry
P
P
Q
Exit vertex
GExit vertex
Call vertex to Q with return vertex
Otherwise
x x
x
c rc r
v ww v
.
.
succ( )
1
f g x f x g x . ( ) ( )
![Page 31: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/31.jpg)
![Page 32: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/32.jpg)
Assigning ycall functions
numPaths[ExitPow] = Yrtn(numPaths[ExitMain])
numPaths[EntryPow] = Yentry(Yrtn(numPaths[ExitMain])
numPaths[Call] = Yentry(Yrtn(numPaths[ExitMain])
Ycall = Yentry Yrtn
![Page 33: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/33.jpg)
Discussion
• Relationship of y functions to Interprocedural DFA (e.g., Sharir and Pnueli’s j functions):
Exit
GExit
Entry
P
P
Q
Exit vertex
GExit vertex
Call vertex to Q with return vertex
Otherwise
x x
x
c rc r
v ww v
.
.
succ( )
1
Otherwise
tex return ver with Q to vertex Call
xExit verte.
)succ(
Entry
Exit
Q
P
w
vw
v
rc rc
xx
![Page 34: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/34.jpg)
Conclusion
• Interprocedural Context Path Profiling– still some difficulties:
• Doubly exponential observable paths
(but can “prune” paths)• instrumentation is somewhat more costly
(2 ops per edge instead of 1)
– Need static analysis to find y and r functions
![Page 35: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/35.jpg)
Conclusion
• Developed a toolkit of path-profiling techniques:– Interprocedural vs. intraprocedural– Edge functions vs. edge values– Context vs. piecewise
![Page 36: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/36.jpg)
Possible Approaches
• Remove most call-edges and return-edges• Inline every non-recursive procedure• Duplicate every non-recursive procedure• Parameterize instrumentation in each
procedure to behave differently for different contexts
![Page 37: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/37.jpg)
Handling Recursion
• Assign values to each edge EntryglobalDEntryRi:
otherwise)1(
0 if0
jREntryij
i
![Page 38: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/38.jpg)
Handling Recursion
• Before a recursive call to R:– save pathNum (in pathNumBeforeCall)– set pathNum to value on EntryglobalDEntryR
• After a recursive call– update profile with pathNum– restore pathNum to pre-call value (from pathNumBeforeCall)
![Page 39: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/39.jpg)
Theory: Context-Free DAGs
• Let L be a context-free language over S• Let G be a directed graph whose edges are
labeled with members of S• A path in G is an L-path if its word is in L• (L,G) is a context-free DAG if the number
of L-paths through G is finite
![Page 40: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/40.jpg)
Interprocedural Piecewise Profiling
• Modification of context profiling:– For each procedure P:
• Add the vertex GEntryP
• Add the edge EntryglobalDGEntryP
– Replace each surrogate edge EntryPDv with GEntryPDv
• Use Unbalanced-Right-Left paths in G*-fin• (must handle unbalanced-right paths)
![Page 41: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/41.jpg)
Other Techniques
• Intraprocedural context path profiling– Context indicates the path taken to a loop
header
• Hybrid techniques– Exploit parameterization of the instrumentation
![Page 42: Interprocedural Path Profiling David Melski Thomas Reps University of Wisconsin](https://reader036.vdocuments.us/reader036/viewer/2022062519/5697c0091a28abf838cc7352/html5/thumbnails/42.jpg)
Discussion
• Keeping the numbering dense:– the number of paths can be
exponential in the size of the graph– might require O(n) bits for pathNum
– dense numbering important– piecewise or hybrid may be more
practical