Docsity

Cache-Conscious Code Layout: Block Selection and Procedure Positioning - Prof. Scott Mahlk, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Cache-Conscious Code Layout: Block Selection and Procedure Positioning - Prof. Scott Mahlk and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

  • EECS 583 – Class 6 Finish Hyperblocks Cache-Conscious Code Layout University of Michigan January 30,
  • 1 -

Reading Material^ Y^ Today’s class^ »^ “Profiled Guided Code Positioning”,^ K. Pettis and R. Hansen, Proc. PLDI-90, 1999^ »^ “Procedure Placement Using Temporal Ordering Information”,^ N. Gloy et al., Proc. MICRO-30, 1997^ Y^ Material for the next lecture^ »^ Compilers: Principles, Techniques, and Tools

A. Aho, R. Sethi, and J. Ullman, Addison-Wesley, 1988. (Sections: 10.5, 10.6, 10.9, 10.10)

  • 3 -

Block Selection – Try 2^ Y^ Problems with BSV formula^ »^ Ignore dependence height^ »^ Blocks considered independently (control flow ignored)^ Y^ Enumerate all paths of execution through region of interest^ »^ Consider a path – execution from entry to some exit^ »^ Give priority to path as a whole^ Y^ Path priority^ »^ dep_ratioi = 1.0 – (dep_heighti / max dep_height)^ »^ op_ratioi = 1.0 – (num_opsi / max num_ops)^ »^ priorityi = (probabilityi x hazardi) x (dep_ratioi + op_ratioi + K)^ y^ Hazard multiplier was 0.25 for paths containing subroutine call orunresolvable memory store^ y^ K = base contribution for a path (0.1 used)

  • 4 -

Block Selection – Try 2 (continued)^ Y^ Path selection^ »^ Rank paths from highest to lowest priority^ »^ Include paths until either:^ y^ Estimated available resources full^ y^ Priority drops too low^ »^ Exclude any paths with excessive resource util or dep height^ Y^ Use union of selected paths to form Hyperblock^ »^ Causes some lower priority paths to be included

  • 6 -

Block Selection – Try 2 – Example continued

Profile Guided Code Positioning^ K. Pettis and R. Hansen, PLDI-90, 1990.

  • 9 -

Procedure Positioning^ Y^ “Closest is best” strategy: if a procedure calls anotherfrequently, we want the two procedures to wind up closeto one another. This increases the chances that they willland on the same page, reducing the working set.^ Y^ Construct a weighted call graph^ »^ Node = procedure^ »^ Edge from A

Æ^ B means procedure A calls B (perhaps multipletimes)

»^ Weight on edge is the total number of dynamic calls Y Using the weighted call graph to build the link order forthe procedures

  • 10 -

Example Call Graph

  • 12 -

Merging Nodes (continued)^ Y^ Procedures in a node are organized as a linear list called a^ chain^ – this is the layout order of the procedures^ Y^ Next, we merge AD and CF nodes. 4 choices result:^ »^ A-D-C-F or F-C-D-A^ »^ A-D-F-C or C-F-D-A^ »^ D-A-C-F or F-C-A-D^ »^ D-A-F-C or C-F-A-D^ Y^ Use “Closest is best” strategy^ »^ F is not connected to either A or D and C is more stronglyconnected to A than D^ »^ Thus, C and A should be adjacent: Pick DACF or FCAD^ Y^ Repeat merging process until no edges in graph

  • 13 -

Basic Block Ordering^ Y^ Define the order of the basic blocks in eachprocedure^ Y^ First, identify chains of blocks^ » 2 methods^ y^ Top-down^ y^ Bottom-up^ Y^ Second, define precedence relation between thechains^ » Want non-taken conditional branches to be forward asmuch as possible

  • 15 -

Class Problem

Create the BB chains using top-downpositioning

  • 16 -

Bottom-up Chain Formation^ Y^ Form BB chains using the following steps^ » Initially consider each basic block as the head and tailof a chain.^ » Looking at the edges from largest to smallest weight,two different chains are merged if the arc connects thetail of one chain to the head of the other.

  • 18 -

Define Precedence Relation Among Chains

Chains: 1)^ A 2)^ E-N-B-C-D-F-H 3)^ I-J-L 4)^ G-O 5)^ K 6)^ M

Y^ 6 conditional branches in our example^ »^ B to C/O

C to D/G^

D to E/F »^ F to H/I^

I to J/M^

J to K/L

Y^ Branch B to C/O^ »^ Yields, chain 2(B) before chain 4(O) Y^ Branch C to D/G^ »^ Yields, chain 2(C) before chain 4(G) Y^ Branch D to E/F^ »^ Nothing, all in same chain Y^ Branch F to H/I^ »^ Yields, chain 2(F) before chain 3(I) Y^ Branch I to J/M^ »^ Yields, chain 3(I) before chain 6(M) Y^ Branch J to K/L^ »^ Yields chain 3(J) before chain 5(L) Y^ Final order: A , E-N-B-C-D-F-H, I-J-L, G-O, K, M

This yields a partial order. To get a full order, choose a chain to follow another by the highest inter- chain weight

Procedure Placement UsingTemporal Ordering Information^ N. Gloy, T. Blackwell, M. Smith, and B. Calder,MICRO-30, 1997.