lecture-3 Program Analysis

# lecture-3 Program Analysis - Administrative info Subscribe...

This preview shows pages 1–4. Sign up to view the full content.

1 Administrative info Subscribe to the class mailing list!!! instructions are on the class web page, which is accessible from my home page, which is accessible by searching for Sorin Lerner on google From last lecture Flow functions: Given information in before statement s, F s ( in ) returns information after statement s Flow functions are a central component of a dataflow analysis They state constraints on the information flowing into and out of a statement 1: x := ... 2: y := ... 3: y := ... 4: p := ... if(...) ... x ... 5: x := ... ... y ... ... x ... 6: x := ... 7: *p := ... merge ... x ... ... y ... 8: y := ... d 0 d 1 d 2 d 3 d 5 d 6 d 7 d 9 d 10 d 11 d 13 d 14 d 15 d 16 d 12 d 4 d 8 Back to example d 1 = F a (d 0 ) d 2 = F b (d 1 ) d 3 = F c (d 2 ) d 4 = F d (d 3 ) d 5 = F e (d 4 ) d 6 = F g (d 5 ) d 7 = F h (d 6 ) d 8 = F i (d 7 ) d 10 = F j (d 9 ) d 11 = F k (d 10 ) d 12 = F l (d 11 ) d 9 = F f (d 5 ) d 13 = F m (d 12 , d 8 ) d 14 = F n (d 13 ) d 15 = F o (d 14 ) d 16 = F p (d 15 ) How to find solutions for d i ? How to find solutions for d i ? This is a forward problem given information flowing in to a node, can determine using the flow function the info flow out of the node To solve, simply propagate information forward through the control flow graph, using the flow functions What are the problems with this approach? First problem What about the incoming information? – d 0 is not constrained so where do we start? Need to constrain d 0 Two options: explicitly state entry information have an entry node whose flow function sets the information on entry (doesn’t matter if entry node has an incoming edge, its flow function ignores any input) Entry node s: entry in out out = { x ° s | x ± Formals }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 1: x := ... 2: y := ... 3: y := ... 4: p := ... if(...) ... x ... 5: x := ... ... y ... ... x ... 6: x := ... 7: *p := ... merge ... x ... ... y ... 8: y := ... d 0 d 1 d 2 d 3 d 5 d 6 d 7 d 9 d 10 d 11 d 13 d 14 d 15 d 16 d 12 d 4 d 8 Back to example d 1 = F a (d 0 ) d 2 = F b (d 1 ) d 3 = F c (d 2 ) d 4 = F d (d 3 ) d 5 = F e (d 4 ) d 6 = F g (d 5 ) d 7 = F h (d 6 ) d 8 = F i (d 7 ) d 10 = F j (d 9 ) d 11 = F k (d 10 ) d 12 = F l (d 11 ) d 9 = F f (d 5 ) d 13 = F m (d 12 , d 8 ) d 14 = F n (d 13 ) d 15 = F o (d 14 ) d 16 = F p (d 15 ) d 0 = F entry () Which order to process nodes in? How to find solutions for d i ? Sort nodes in topological order each node appears in the order after all of its predecessors Just run the flow functions for each of the nodes in the topological order Second problem When there are loops, there is no topological order! What to do? Let’s try and see what we should do 1: x := ... 2: y := ... 3: y := ... 4: p := ... ... x ... 5: x := ... ... y ... ... x ... 6: x := ... 7: *p := ... ... x ... ... y ... 8: y := ... 1: x := ... 2: y := ... 3: y := ... 4: p := ... ... x ... 5: x := ... ... y ... ... x ... 6: x := ... 7: *p := ... ... x ... ... y ... 8: y := ... Solution: iterate! Initialize all d i to the empty set Store all nodes onto a worklist while worklist is not empty: remove node n from worklist apply flow function for node n update the appropriate d i , and add nodes whose inputs have changed back onto worklist
3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern