/usr/share/doc/llvm-3.5-doc/html/HowToUseInstrMappings.html is in llvm-3.5-doc 1:3.5-4ubuntu2~trusty2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How To Use Instruction Mappings — LLVM 3.5 documentation</title>
<link rel="stylesheet" href="_static/llvm-theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '3.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="LLVM 3.5 documentation" href="index.html" />
<link rel="up" title="Writing an LLVM Backend" href="WritingAnLLVMBackend.html" />
<link rel="next" title="Accurate Garbage Collection with LLVM" href="GarbageCollection.html" />
<link rel="prev" title="Writing an LLVM Backend" href="WritingAnLLVMBackend.html" />
<style type="text/css">
table.right { float: right; margin-left: 20px; }
table.right td { border: 1px solid #ccc; }
</style>
</head>
<body>
<div class="logo">
<a href="index.html">
<img src="_static/logo.png"
alt="LLVM Logo" width="250" height="88"/></a>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="GarbageCollection.html" title="Accurate Garbage Collection with LLVM"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="WritingAnLLVMBackend.html" title="Writing an LLVM Backend"
accesskey="P">previous</a> |</li>
<li><a href="http://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li><a href="WritingAnLLVMBackend.html" accesskey="U">Writing an LLVM Backend</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="body">
<div class="section" id="how-to-use-instruction-mappings">
<h1>How To Use Instruction Mappings<a class="headerlink" href="#how-to-use-instruction-mappings" title="Permalink to this headline">¶</a></h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#introduction" id="id1">Introduction</a></li>
<li><a class="reference internal" href="#instrmapping-class-overview" id="id2"><tt class="docutils literal"><span class="pre">InstrMapping</span></tt> Class Overview</a><ul>
<li><a class="reference internal" href="#sample-example" id="id3">Sample Example</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="introduction">
<h2><a class="toc-backref" href="#id1">Introduction</a><a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>This document contains information about adding instruction mapping support
for a target. The motivation behind this feature comes from the need to switch
between different instruction formats during various optimizations. One approach
could be to use switch cases which list all the instructions along with formats
they can transition to. However, it has large maintenance overhead
because of the hardcoded instruction names. Also, whenever a new instruction is
added in the .td files, all the relevant switch cases should be modified
accordingly. Instead, the same functionality could be achieved with TableGen and
some support from the .td files for a fraction of maintenance cost.</p>
</div>
<div class="section" id="instrmapping-class-overview">
<h2><a class="toc-backref" href="#id2"><tt class="docutils literal"><span class="pre">InstrMapping</span></tt> Class Overview</a><a class="headerlink" href="#instrmapping-class-overview" title="Permalink to this headline">¶</a></h2>
<p>TableGen uses relationship models to map instructions with each other. These
models are described using <tt class="docutils literal"><span class="pre">InstrMapping</span></tt> class as a base. Each model sets
various fields of the <tt class="docutils literal"><span class="pre">InstrMapping</span></tt> class such that they can uniquely
describe all the instructions using that model. TableGen parses all the relation
models and uses the information to construct relation tables which relate
instructions with each other. These tables are emitted in the
<tt class="docutils literal"><span class="pre">XXXInstrInfo.inc</span></tt> file along with the functions to query them. Following
is the definition of <tt class="docutils literal"><span class="pre">InstrMapping</span></tt> class definied in Target.td file:</p>
<div class="highlight-llvm"><div class="highlight"><pre>class InstrMapping {
// Used to reduce search space only to the instructions using this
// relation model.
string FilterClass;
// List of fields/attributes that should be same for all the instructions in
// a row of the relation table. Think of this as a set of properties shared
// by all the instructions related by this relationship.
list<string> RowFields = [];
// List of fields/attributes that are same for all the instructions
// in a column of the relation table.
list<string> ColFields = [];
// Values for the fields/attributes listed in 'ColFields' corresponding to
// the key instruction. This is the instruction that will be transformed
// using this relation model.
list<string> KeyCol = [];
// List of values for the fields/attributes listed in 'ColFields', one for
// each column in the relation table. These are the instructions a key
// instruction will be transformed into.
list<list<string> > ValueCols = [];
}
</pre></div>
</div>
<div class="section" id="sample-example">
<h3><a class="toc-backref" href="#id3">Sample Example</a><a class="headerlink" href="#sample-example" title="Permalink to this headline">¶</a></h3>
<p>Let’s say that we want to have a function
<tt class="docutils literal"><span class="pre">int</span> <span class="pre">getPredOpcode(uint16_t</span> <span class="pre">Opcode,</span> <span class="pre">enum</span> <span class="pre">PredSense</span> <span class="pre">inPredSense)</span></tt> which
takes a non-predicated instruction and returns its predicated true or false form
depending on some input flag, <tt class="docutils literal"><span class="pre">inPredSense</span></tt>. The first step in the process is
to define a relationship model that relates predicated instructions to their
non-predicated form by assigning appropriate values to the <tt class="docutils literal"><span class="pre">InstrMapping</span></tt>
fields. For this relationship, non-predicated instructions are treated as key
instruction since they are the one used to query the interface function.</p>
<div class="highlight-llvm"><div class="highlight"><pre>def getPredOpcode : InstrMapping {
// Choose a FilterClass that is used as a base class for all the
// instructions modeling this relationship. This is done to reduce the
// search space only to these set of instructions.
let FilterClass = "PredRel";
// Instructions with same values for all the fields in RowFields form a
// row in the resulting relation table.
// For example, if we want to relate 'ADD' (non-predicated) with 'Add_pt'
// (predicated true) and 'Add_pf' (predicated false), then all 3
// instructions need to have same value for BaseOpcode field. It can be any
// unique value (Ex: XYZ) and should not be shared with any other
// instruction not related to 'add'.
let RowFields = ["BaseOpcode"];
// List of attributes that can be used to define key and column instructions
// for a relation. Key instruction is passed as an argument
// to the function used for querying relation tables. Column instructions
// are the instructions they (key) can transform into.
//
// Here, we choose 'PredSense' as ColFields since this is the unique
// attribute of the key (non-predicated) and column (true/false)
// instructions involved in this relationship model.
let ColFields = ["PredSense"];
// The key column contains non-predicated instructions.
let KeyCol = ["none"];
// Two value columns - first column contains instructions with
// PredSense=true while second column has instructions with PredSense=false.
let ValueCols = [["true"], ["false"]];
}
</pre></div>
</div>
<p>TableGen uses the above relationship model to emit relation table that maps
non-predicated instructions with their predicated forms. It also outputs the
interface function
<tt class="docutils literal"><span class="pre">int</span> <span class="pre">getPredOpcode(uint16_t</span> <span class="pre">Opcode,</span> <span class="pre">enum</span> <span class="pre">PredSense</span> <span class="pre">inPredSense)</span></tt> to query
the table. Here, Function <tt class="docutils literal"><span class="pre">getPredOpcode</span></tt> takes two arguments, opcode of the
current instruction and PredSense of the desired instruction, and returns
predicated form of the instruction, if found in the relation table.
In order for an instruction to be added into the relation table, it needs
to include relevant information in its definition. For example, consider
following to be the current definitions of ADD, ADD_pt (true) and ADD_pf (false)
instructions:</p>
<div class="highlight-llvm"><div class="highlight"><pre>def ADD : ALU32_rr<(outs IntRegs:$dst), (ins IntRegs:$a, IntRegs:$b),
"$dst = add($a, $b)",
[(set (i32 IntRegs:$dst), (add (i32 IntRegs:$a),
(i32 IntRegs:$b)))]>;
def ADD_Pt : ALU32_rr<(outs IntRegs:$dst),
(ins PredRegs:$p, IntRegs:$a, IntRegs:$b),
"if ($p) $dst = add($a, $b)",
[]>;
def ADD_Pf : ALU32_rr<(outs IntRegs:$dst),
(ins PredRegs:$p, IntRegs:$a, IntRegs:$b),
"if (!$p) $dst = add($a, $b)",
[]>;
</pre></div>
</div>
<p>In this step, we modify these instructions to include the information
required by the relationship model, <tt>getPredOpcode</tt>, so that they can
be related.</p>
<div class="highlight-llvm"><div class="highlight"><pre>def ADD : PredRel, ALU32_rr<(outs IntRegs:$dst), (ins IntRegs:$a, IntRegs:$b),
"$dst = add($a, $b)",
[(set (i32 IntRegs:$dst), (add (i32 IntRegs:$a),
(i32 IntRegs:$b)))]> {
let BaseOpcode = "ADD";
let PredSense = "none";
}
def ADD_Pt : PredRel, ALU32_rr<(outs IntRegs:$dst),
(ins PredRegs:$p, IntRegs:$a, IntRegs:$b),
"if ($p) $dst = add($a, $b)",
[]> {
let BaseOpcode = "ADD";
let PredSense = "true";
}
def ADD_Pf : PredRel, ALU32_rr<(outs IntRegs:$dst),
(ins PredRegs:$p, IntRegs:$a, IntRegs:$b),
"if (!$p) $dst = add($a, $b)",
[]> {
let BaseOpcode = "ADD";
let PredSense = "false";
}
</pre></div>
</div>
<p>Please note that all the above instructions use <tt class="docutils literal"><span class="pre">PredRel</span></tt> as a base class.
This is extremely important since TableGen uses it as a filter for selecting
instructions for <tt class="docutils literal"><span class="pre">getPredOpcode</span></tt> model. Any instruction not derived from
<tt class="docutils literal"><span class="pre">PredRel</span></tt> is excluded from the analysis. <tt class="docutils literal"><span class="pre">BaseOpcode</span></tt> is another important
field. Since it’s selected as a <tt class="docutils literal"><span class="pre">RowFields</span></tt> of the model, it is required
to have the same value for all 3 instructions in order to be related. Next,
<tt class="docutils literal"><span class="pre">PredSense</span></tt> is used to determine their column positions by comparing its value
with <tt class="docutils literal"><span class="pre">KeyCol</span></tt> and <tt class="docutils literal"><span class="pre">ValueCols</span></tt>. If an instruction sets its <tt class="docutils literal"><span class="pre">PredSense</span></tt>
value to something not used in the relation model, it will not be assigned
a column in the relation table.</p>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="GarbageCollection.html" title="Accurate Garbage Collection with LLVM"
>next</a> |</li>
<li class="right" >
<a href="WritingAnLLVMBackend.html" title="Writing an LLVM Backend"
>previous</a> |</li>
<li><a href="http://llvm.org/">LLVM Home</a> | </li>
<li><a href="index.html">Documentation</a>»</li>
<li><a href="WritingAnLLVMBackend.html" >Writing an LLVM Backend</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2003-2014, LLVM Project.
Last updated on 2015-02-12.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
</div>
</body>
</html>
|