-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeGen.html
196 lines (150 loc) · 5.21 KB
/
CodeGen.html
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
<!DOCTYPE html>
<html>
<head>
<link rel="Stylesheet" type="text/css" href="style.css">
<title>CodeGen</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>
<span class="todo">TODO</span>: A bottom up approach might be more efficient since the top level of the
framework is too abstract to grasp.
</p>
<div id="CodeGen"><h1 id="CodeGen" class="header"><a href="#CodeGen">CodeGen</a></h1></div>
<ul>
<li>
"The two pieces of the LLVM code generator are the high-level interface to the
code generator and the set of reusable components that can be used to build
target-specific backends."
</ul>
<p>
<span id="CodeGen-Code generation model for standard register-based microprocessors"></span><strong id="Code generation model for standard register-based microprocessors">Code generation model for standard register-based microprocessors</strong>
</p>
<ol>
<li>
Instruction Selection — Turn IR into <em>DAG</em> of target instructions. † Directed
acyclic graph is a graph without circle. Using DAG to represent IR and target
instruction then pattern match them.
<li>
<span class="todo">TODO</span>: Complete the reset of the steps
</ol>
<div id="CodeGen-Target description classes"><h2 id="Target description classes" class="header"><a href="#CodeGen-Target description classes">Target description classes</a></h2></div>
<ul>
<li>
Under include/llvm/Target
<li>
Describes target machine
<li>
Using TableGen to generate target description classes.
<li>
Subclassed by the concerte tagget implementation.
</ul>
<p>
Only TargetMachine and DataLayout classes are requred to be define for a
backend to fit into the LLVM system.
</p>
<p>
<span class="todo">TODO</span>: Learn about TableGen
</p>
<div id="CodeGen-Machine code description classes"><h2 id="Machine code description classes" class="header"><a href="#CodeGen-Machine code description classes">Machine code description classes</a></h2></div>
<ul>
<li>
Under include/llvm/CodeGen
<li>
<em>Agnostic</em> to any target machine
<li>
Has concepts like "constant pool entires" and "jump tables" which are above
assembly level
</ul>
<p>
Target machine instructions are represented as an instance of the MachineInstr
class. It's extremely abstract and only keeps track of an opcode number and a
set of operands.
</p>
<p>
<span id="CodeGen-Machine code description classes-McahineInstr class"></span><strong id="McahineInstr class">McahineInstr class</strong>
The opcode only has meaning to a specific backend. Instructions are defined in
the *InstrInfo.td (HexagonInstrInfo.td)
</p>
<div id="CodeGen-Machine code description classes-"MC" Layer"><h3 id=""MC" Layer" class="header"><a href="#CodeGen-Machine code description classes-"MC" Layer">"MC" Layer</a></h3></div>
<p>
Think it as of a assembly writing API
</p>
<ul>
<li>
Represents assembly level constructs which <span id="CodeGen-Machine code description classes-"MC" Layer-is"></span><strong id="is">is</strong> specific to target machine
<li>
IR -> MCStreamer -> assembly
</ul>
<p>
<span id="CodeGen-Machine code description classes-"MC" Layer-MCStreamer"></span><strong id="MCStreamer">MCStreamer</strong>
</p>
<ul>
<li>
Abstract assembler API
<li>
Directly corresponds to what we see in a .s file and implemented in differnt
ways (e.g. to ouput a .s file, output and ELF.o file etc)
<li>
One method per directive (e.g EmitLabel, SwitchSection, EmitValue(for .byte,
.word), etc, which directly correspond to assembly level directives.
</ul>
<p>
LLVM IR and Machine* constructs are lowered down to the MC layer, emitting
directives through MCStreamer.
</p>
<p>
MCAsmStreamer (for .s file) prints out directive for each method.
MCObjectStreamer implements a full assembler.
</p>
<p>
MCtargetStreamer is for target specific directives.
</p>
<p>
"To make llvm use these classes, the target initialization must call
TargetRegistry::RegisterAsmStreamer and TargetRegistry::RegisterMCObjectStreamer
passing callbacks that allocate the corresponding target streamer and pass it to
createAsmStreamer or to the appropriate object streamer constructor."
</p>
<p>
<span id="CodeGen-Machine code description classes-"MC" Layer-MCContext"></span><strong id="MCContext">MCContext</strong> class
</p>
<ul>
<li>
Owner of data structures at the MC layer corresponds to symbols, sections,
etc.
<li>
Used to create symbols and sections.
</ul>
<p>
<span id="CodeGen-Machine code description classes-"MC" Layer-MCSymbol"></span><strong id="MCSymbol">MCSymbol</strong> class
</p>
<ul>
<li>
Represent assembly label
<li>
Created by MCContext and unique
</ul>
<p>
<span id="CodeGen-Machine code description classes-"MC" Layer-MCSection"></span><strong id="MCSection">MCSection</strong> class
</p>
<ul>
<li>
Represent object file section
<li>
Subclassed by specific object file implementation
</ul>
<p>
<span id="CodeGen-Machine code description classes-"MC" Layer-MCInst"></span><strong id="MCInst">MCInst</strong> class
</p>
<ul>
<li>
Represent instructions
<li>
Holds opcode and a vector of MCOperands
<li>
MCOperands is a union of three cases: 1) immediate, 2) register ID, 3)
symbolic expression (e.g. "Lfoo-Lbar+42") as MCExpr
</ul>
</body>
</html>