Chapter-9(Instructoin_Selection)-1

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

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

Chapter 9 Instruction Selection

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

View Full Document
Instruction Selection Phase Finding the appropriate machine instructions to implement a given intermediate representation
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

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

View Full Document
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
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

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

View Full Document
An Example a[i] := x
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

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

View Full Document
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
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!

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

View Full Document
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.
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.

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

View Full Document
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.
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;

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 ]}

### 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
Ask a homework question - tutors are online