[97a262]: userguide / html / RVM / BURS.html  Maximize  Restore  History

Download this file

113 lines (96 with data), 7.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>RVM : BURS</title>
<link rel="stylesheet" href="styles/site.css" type="text/css" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
<tr>
<td valign="top" class="pagebody">
<div class="pageheader">
<span class="pagetitle">
RVM : BURS
</span>
</div>
<div class="pagesubheading">
This page last changed on Jul 02, 2008 by <font color="#0050B2">dgrove</font>.
</div>
<p>The optimizing compiler uses the Bottom-Up Rewrite System (BURS) for instruction selection. BURS is essentially a tree pattern matching system derived from Iburg by David R. Hanson. (See "Engineering a Simple, Efficient Code-Generator Generator" by Fraser, Hanson, and Proebsting, LOPLAS 1(3), Sept. 1992.) The instruction selection rules for each architecture are specified in an architecture-specific fileslocated in <tt>$RVM_ROOT/rvm/src-generated/opt-burs/${arch</tt>}, where ${arch} is the specific instruction architecture of interest. The rules are used in generating a parser, which transforms the IR.</p>
<p>Each rule is defined by a four-line record, consisting of:</p>
<ul>
<li><tt>PRODUCTION</tt>: the tree pattern to be matched. The format of each pattern is explained below.</li>
<li><tt>COST</tt>: the cost of matching the pattern as opposed to skipping it. It is a Java<a href="http://docs.codehaus.org/display/RVM/Trademarks" title="Trademarks">���</a> expression that evaluates to an integer.</li>
<li><tt>FLAGS</tt>: The flags for the operation:
<ul>
<li>NOFLAGS: this production performs no operation</li>
<li>EMIT_INSTRUCTION: this production will emit instructions</li>
<li>LEFT_CHILD_FIRST: visit child on left-and side of production first</li>
<li>RIGHT_CHILD_FIRST: visit child on right-hand side of production first</li>
</ul>
</li>
<li><tt>TEMPLATE</tt>: Java code to emit</li>
</ul>
<p>Each production has a <em>non-terminal</em>, which denotes a value, followed by a colon (":"), followed by a dependence tree that produces that value. For example, the rule resulting in memory add on the INTEL architecture is expressed in the following way:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>stm: INT_STORE(INT_ADD_ACC(INT_LOAD(r,riv),riv),OTHER_OPERAND(r, riv))
ADDRESS_EQUAL(P(p), PLL(p), 17)
EMIT_INSTRUCTION
EMIT(MIR_BinaryAcc.mutate(P(p), IA32_ADD, MO_S(P(p), DW), BinaryAcc.getValue(PL(p))));
</pre>
</div></div>
<p>The production in this rule represents the following tree:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre> r riv
\ /
INT_LOAD riv
\ /
INT_ADD_ACC r riv
\ | /
INT_STORE
</pre>
</div></div>
<p>where <tt>r</tt> is a non-terminal that represents a register or a tree producing a register, <tt>riv</tt> is a non-terminal that represents a register (or a tree producing one) or an immediate value, and <tt>INT_LOAD</tt>, <tt>INT_ADD_ACC</tt> and <tt>INT_STORE</tt> are operators (<em>terminals</em>). <tt>OTHER_OPERAND</tt> is just an abstraction to make the tree binary.</p>
<p>There are multiple helper functions that can be used in Java code (both cost expressions and generation templates). In all code sequences the name <tt>p</tt> is reserved for the current tree node. Some of the helper methods are shortcuts for accessing properties of tree nodes:</p>
<ul>
<li><tt>P(p)</tt> is used to access the instruction associated with the current (root) node,</li>
<li><tt>PL(p)</tt> is used to access the instruction associated with the left child of the current (root) node (provided it exists),</li>
<li><tt>PR(p)</tt> is used to access the instruction associated with the right child of the current (root) node (provided it exists),</li>
<li>similarly, <tt>PLL(p)</tt>, <tt>PLR(p)</tt>, <tt>PRL(p)</tt> and <tt>PRR(p)</tt> are used to access the instruction associated with the left child of the left child, right child of the left child, left child of the right child and right child of the right child, respectively, of the current (root) node (provided they exist).</li>
</ul>
<p>What the above rule basically reads is the following:<br/>
If a tree shown above is seen, evaluate the cost expression (which, in this case, calls a helper function to test whether the addresses in the <tt>STORE</tt> (<tt>P(p)</tt>) and the <tt>LOAD</tt> (<tt>PLL(p)</tt>) instructions are equal. The function returns 17 if they are, and a special value <tt>INFINITE</tt> if not), and if the cost is acceptable, emit the <tt>STORE</tt> instruction (<tt>P(p)</tt>) mutated in place into a machine-dependent add-accumulate instruction (<tt>IA32_ADD</tt>) that adds a given value to the contents of a given memory location.</p>
<p>The rules file is used to generate a file called <tt>ir.brg</tt>, which, in turn, is used to produce a file called <tt>BURS_STATE.java</tt>.</p>
<p>For more information on helper functions look at <tt>BURS_Helpers.java</tt>. For more information on the BURS algorithm see <tt>BURS.java</tt>.</p>
<h2><a name="BURS-Futuredirections"></a>Future directions</h2>
<p>Whilst jburg allows us to do good instruction selection there are a number of areas where it is lacking:</p>
<h3><a name="BURS-Vectoroperations"></a>Vector operations</h3>
<p>We can't write productions for vector operations unless we match an entire tree of operations. For example, it would be nice to write a rule of the form:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>(r, r): ADD(r,r), ADD(r,r)
</pre>
</div></div>
<p>if say the architecture supported a vector add operation (ie SIMD). Unfortunately we can't have tuples on the LHS of expressions and the comma represents that matching two coverings is necessary. <a href="#BURS-leupers">Leupers</a> has shown how with a modified BURS system they can achieve this result. Their syntax is:</p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
<pre>r: ADD(r,r)
r: ADD(r,r)
</pre>
</div></div>
<p><a name="BURS-leupers"></a></p>
<ul>
<li><a href="http://doi.acm.org/10.1145/343647.343679">Rainer Leupers, Code selection for media processors with SIMD instructions, 2000</a></li>
</ul>
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td height="12" background="http://docs.codehaus.org/images/border/border_bottom.gif"><img src="images/border/spacer.gif" width="1" height="1" border="0"/></td>
</tr>
<tr>
<td align="center"><font color="grey">Document generated by Confluence on Jul 04, 2010 19:57</font></td>
</tr>
</table>
</body>
</html>