CS553 Colorado State University =============================================== Control Flow =============================================== 10/15/09 ------------------------ Loops are important (2) - the majority of execution time in programs is spent in loops ------------------------------ Data-flow and Control-flow (3) Data-flow creates a partial ordering between the production of a value and its consumption. Control-flow creates a dependence between the execution of a guard expression and the statements being guarded. ------------------------- Control-flow in an AST (5) -> show an example AST and have students talk through the control flow In an AST control flow is implicit and in a control flow graph it is explicit. -> show the control flow graph for the same AST To make the control-flow explicit the intermediate representation has been lowered into something that is 3-address code like. ------------------------- Control-flow Analysis (6) After code has been lowered ... - create a control-flow graph - discover loops ------------------------- Loop Concepts (7) What is ... - a strongly connected component? - an edge source and target Today we will learn about ... - dominators - natural loops -> have students identify parts of loop in the While1.java control-flow graph ------------------------- Dominator approach to discovering loops (11) Note that dominators are also used to generate SSA representation. Back edges - back edge based on a depth first spanning tree is an edge that is not in the spanning tree and goes from a node to one of its ancestors - back edges for a natural loop has the additional constraint that the ancestor dominates the source node Natural loops are easier to optimize because they have a single entry point. For example loop invariant code motion needs a single loop header. ------------------------- Computing Dominators (12) - For the entry node s, we’ll initialize the Dom set to be the set consisting of s - For all other nodes, set their Dom sets to be all nodes, and we’ll prune these sets as we iterate - We then iterate until we reach a fixed point: D(n) is the set that consists of the node itself + all nodes that dominate all of n’s predecessors. This set will decrease as we find that nodes do not dominate all predecessors --> Why do we init sets to N and not empty set? ------------------------- Reducibility (14, 15) --> Perform T1 and T2 transformations on example While1.java CFG. Recall that the depth of the CFG affects the complexity of data-flow analysis. ------------------------- Induction Variables (18) Read why we want to do induction variable detection http://ieeexplore.ieee.org/search/wrapper.jsp?arnumber=546612 Polaris paper -to recognize parallel loops, want to get rid of everything but loop index as having loop carried dependences -dependence analysis, array reference expressions need to be in terms of the loop index ------------------------- Example Induction Variables (19) 3-address code -------------- s = 0 i = 0 loop: if i>=N goto end t1 = i * 4 t2 = a + t1 t3 = M[t1] s = s + t3 i = i + 1 goto loop end: arithmetic progressions? i= 0, 1, 2, 3, ... t1 = 0, 4, 8, 12, ... t2 = a, a+4, a+8, a+12, ... t3 = nope, reading something from memory s = nope, depends on t3 ------------------------- Induction Variable Identification (20) --> Which of the induction variables from the example were basic and which were derived? ------------------------- Induction Variable Triples (21) --> What are the triples for the induction variables in the example? ------------------------------------------ Example: Induction Variable Detection and Elimination (25-28) --> draw example on board and use algorithms to transform -------------------- mstrout@cs.colostate.edu, 10/15/09