13.07.2015 Views

Tiling Examples for X86 ISA

Tiling Examples for X86 ISA

Tiling Examples for X86 ISA

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Tiling</strong> <strong>Examples</strong> <strong>for</strong> <strong>X86</strong> <strong>ISA</strong>Slides Selected from Radu Rugina’sCS412/413 Lecture on InstructionSelection at Cornell


Instruction Selection• Translate 3‐address code to DAG• Cover DAG with tiles– Disjoint i set of tiles cover DAG– Algorithm:• Greedy maximal munch• Dynamic programming


<strong>Tiling</strong>• Assume abstract assembly– Infinite registers– Temporary and/or local variables stored in registers– Array, struct, parameter passing use memory accesses• Translation process from IR:– Convert 3‐address code IR to abstract assembly– Build DAG– Per<strong>for</strong>m tiling


Example• a = a + i where a is a local variable and i is aa = a + i where a is a local variable and i is aparameter passed in from a caller


Pentium <strong>ISA</strong>• Two‐address CISC• Multiple addressing modes– Immediate: $imm– Register: reg– Indirect: (reg), (reg + imm)– Indexed: (reg + reg’), (reg + imm*reg’)


More Tile <strong>Examples</strong>


Conditional Branches


Load Effective Address


Maximal Munch Algorithm• A greedy algorithm• Start from top of tree (or DAG)• Find dlargest tile that matches top node• Tile the sub‐trees recursively


Greedy <strong>Tiling</strong>


ADD Expression and Statement


Designing Tiles• Only add tiles that are useful to compiler• Many instructions will be too hard to useeffectively or will offer no advantage• Need tiles <strong>for</strong> all single‐node trees toguarantee that every tree can be tiled


Implementation• Maximal Munch: start from top node• Find largest tile matching top node and all ofthe children nodes• Invoke recursively on all children of tile• Generate code <strong>for</strong> this tile• Code <strong>for</strong> children will have been generatedgalready in recursive calls


Matching Tiles


Finding globally optimum tiling• Goal: find minimum total cost tiling of DAG• Algorithm: <strong>for</strong> every node, find minimum totalcost tiling of that node and subgraph below it• Lemma: Given minimum cost tiling of allnodes in subgraph, we can find minimum costtiling of the node by trying out all possibletiles matching the node• There<strong>for</strong>e: start from leaves, work upward totop node


Timing Cost Model• Idea: associate cost with each tile (say proportional tonumber of cycles to execute)– May not be a good metric on modern architectures• Total execution time is sum of costs of all tiles


Dynamic Progamming• Traverse DAG recursively, and <strong>for</strong> each node n, record ,where–t is the best tile to use <strong>for</strong> subgraph rooted at n,– c is the total cost of tiling the subgraph rooted at n if t ischosen.• To compute <strong>for</strong> node n– Consider every tile t’ that matches rooted at n, andcompute total cost c’ = cost of tile t’ + sum of the costs oftiling the subgraphs rooted at the leaves of t’ (which costscan be computed recursively and memoized)–Store lowest‐cost tile t’ and its total cost c’• To emit code, traverse least‐cost tiles recursively and emitcode in postorder

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!