Chapter-9(Instructoin_Selection)-1

Chapter-9(Instructoin_Selection)-1 - Chapter 9 Instruction...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 9 Instruction Selection
Background image of page 1

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

View Full DocumentRight Arrow Icon
Instruction Selection Phase Finding the appropriate machine instructions to implement a given intermediate representation
Background image of page 2
Contents TREE Patterns and the fundamental idea Algorithms for instruction selection Maximal Munch Dynamic Programming Tree Grammars Fast Matching Efficiency of tiling algorithm CISC machines IS for Tiger
Background image of page 3

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

View Full DocumentRight Arrow Icon
TREE PATTERNS Tree pattern : express a machine instruction as a fragment of an IR tree Invented Jouette architecture Some instructions have more than one tree pattern: ADDI, LOAD
Background image of page 4
The Fundamental Idea Tiling the IR tree The tiles are the set of tree patterns (legal machine instructions) To cover the tree with nonoverlapping tiles
Background image of page 5

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

View Full DocumentRight Arrow Icon
An Example a[i] := x
Background image of page 6
An Example a "reasonable" set of tile patterns - it is always possible to tile the tree with tiny tiles, each covering only one node ADDI r 1 r 0 + a ADD r 1 fp + r 1 LOAD r 1 M [ r 1 + 0] ADDI r 2 r 0 + 4 MUL r 2 r i × r 2 ADD r 1 r 1 = r 2 ADDI r 2 r 0 + x ADD r 2 fp + r 2 LOAD r 2 M [ r 2 + 0] STORE M [ r 1 + 0] ← r 2
Background image of page 7

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

View Full DocumentRight Arrow Icon
Optimal and Optimum Tilings An IR tree can be tiled in many different ways The best tiling of a tree corresponds to an instruction sequence of least cost: The shortest sequence of instructions the lowest total time
Background image of page 8
Optimal and Optimum Tilings Suppose we could give each kind of instruction a cost. optimum tiling : the one whose tiles sum to the lowest possible value. optimal tiling : the one where no two adjacent tiles can be combined into a single tile of lower cost. Every optimum tiling is also optimal , but not vice versa!
Background image of page 9

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

View Full DocumentRight Arrow Icon
Algorithms for instruction selection Algorithms for optimal tilings are simpler. Complex Instruction Set Computers (CISC) : instructions accomplish several operations each. Reduced Instruction Set Computers (RISC): instruction accomplishes just a small number of operations. There is usually no difference between optimum and optimal tilings.
Background image of page 10
Maximal Munch A simple optimal tiling algorithm, as: Starting at the root of the tree Find the largest tile that fits. Cover the root node and perhaps several other nodes near the root, leaving several subtree. Repeat the same algorithm for each subtree.
Background image of page 11

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

View Full DocumentRight Arrow Icon
Maximal Munch As each tile is placed, the instruction corresponding to that tile is generated. The algorithm generates the instructions in reverse order The “largest tile” is the one with the most nodes. If two tiles of equal size match the root, then the choice between them is arbitrary As you can expect, straightforward implementation use recursive functions.
Background image of page 12
static void munchStm(T_stm s) { switch (s->kind) { case T_MOVE: { T_exp dst = s->u.MOVE.dst, src = s->u.MOVE.src; if (dst->kind == T_MEM) { if (dst->u.MEM->kind == T_BINOP && dst->u.MEM->u.BINOP.op == T_PLUS && dst->u.MEM->u.BINOP.right->kind == T_CONST) { T_exp e1 = dst->u.MEM->u.BINOP.left, e2 = src; /* MOVE(MEM(BINOP(PLUS, e1, CONST(i))), e2) */ munchExp(e1); munchExp(e2); emit(“STORE”); } else if (dst->u.MEM->kind == T_BINOP && dst->u.MEM->u.BINOP.op == T_PLUS } T_exp e1 = dst->u.MEM, e2 = src->u.MEM;
Background image of page 13

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

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 45

Chapter-9(Instructoin_Selection)-1 - Chapter 9 Instruction...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online