You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can ask for different level of optimization, but such a simple function, it will not make much difference:
139
155
```julia
140
-
@pass"convert" ir =convert_to_ircode(ci, sv)
141
-
@pass"slot2reg" ir =slot2reg(ir, ci, sv)
142
-
@pass"compact 1" ir =compact!(ir)
143
-
@pass"Inlining" ir =ssa_inlining_pass!(ir, sv.inlining, ci.propagate_inbounds)
144
-
@pass"compact 2" ir =compact!(ir)
145
-
@pass"SROA" ir =sroa_pass!(ir, sv.inlining)
146
-
@pass"ADCE" ir =adce_pass!(ir, sv.inlining)
147
-
@pass"compact 3" ir =compact!(ir)
156
+
CC.@pass"convert" ir =convert_to_ircode(ci, sv)
157
+
CC.@pass"slot2reg" ir =slot2reg(ir, ci, sv)
158
+
CC.@pass"compact 1" ir =compact!(ir)
159
+
CC.@pass"Inlining" ir =ssa_inlining_pass!(ir, sv.inlining, ci.propagate_inbounds)
160
+
CC.@pass"compact 2" ir =compact!(ir)
161
+
CC.@pass"SROA" ir =sroa_pass!(ir, sv.inlining)
162
+
CC.@pass"ADCE" ir =adce_pass!(ir, sv.inlining)
163
+
CC.@pass"compact 3" ir =compact!(ir)
148
164
```
149
165
150
166
@@ -164,35 +180,37 @@ The code is stored in `IRCode` data structure.
164
180
stmts::InstructionStream
165
181
argtypes::Vector{Any}
166
182
sptypes::Vector{VarState}
167
-
linetable::Vector{LineInfoNode}
183
+
debuginfo::Compiler.DebugInfoStream
168
184
cfg::CFG
169
185
new_nodes::NewNodeStream
170
186
meta::Vector{Expr}
187
+
valid_worlds::Compiler.WorldRange
171
188
end
172
189
```
173
190
174
191
where
175
192
* `stmts` is a stream of instruction (more in this below)
176
193
* `argtypes` holds types of arguments of the function whose `IRCode` we have obtained
177
194
* `sptypes` is a vector of `VarState`. It seems to be related to parameters of types
178
-
* `linetable` is a table of unique lines in the source code from which statement came from
195
+
* `debuginfo` is a table of unique lines in the source code from which statement came from
179
196
* `cfg` holds control flow graph, which contains building blocks and jumps between them
180
197
* `new_nodes` is an infrastructure that can be used to insert new instructions to the existing `IRCode` . The idea behind is that since insertion requires a renumbering all statements, they are put in a separate queue. They are put to correct position with a correct `SSANumber` by calling `compact!`.
181
198
* `meta` is something.
199
+
* `valid_worlds` specify a "time" span in which the world is valid
182
200
183
201
**InstructionStream**
184
202
185
203
```julia
186
204
struct InstructionStream
187
-
inst::Vector{Any}
205
+
stmt::Vector{Any}
188
206
type::Vector{Any}
189
207
info::Vector{CallInfo}
190
208
line::Vector{Int32}
191
209
flag::Vector{UInt8}
192
210
end
193
211
```
194
212
where
195
-
* `inst` is a vector of instructions, stored as `Expr`essions. The allowed fields in `head` are described [here](https://docs.julialang.org/en/v1/devdocs/ast/#Expr-types)
213
+
* `stmt` is a vector of instructions, stored as `Expr`essions. The allowed fields in `head` are described [here](https://docs.julialang.org/en/v1/devdocs/ast/#Expr-types)
196
214
* `type` is the type of the value returned by the corresponding statement
197
215
* `CallInfo` is ???some info???
198
216
* `line` is an index into `IRCode.linetable` identifying from which line in source code the statement comes from
@@ -208,15 +226,16 @@ The code is stored in `IRCode` data structure.
208
226
For the above `foo` function, the InstructionStream looks like
209
227
210
228
```julia
211
-
julia DataFrame(flag = ir.stmts.flag, info = ir.stmts.info, inst = ir.stmts.inst, line = ir.stmts.line, type = ir.stmts.type)
229
+
julia DataFrame(flag = ir.stmts.flag, info = ir.stmts.info, stmt = ir.stmts.stmt, type = ir.stmts.type)
We can index into the statements as `ir.stmts[1]`, which provides a "view" into the vector. To obtain the first instruction, we can do `ir.stmts[1][:inst]`.
222
241
@@ -231,7 +250,7 @@ Let's now go back to the problem of automatic differentiation. Recall the IRCode
231
250
└── return%3
232
251
=> Float64
233
252
```
234
-
The forward part needs to replace each call of the function by a call to `rrule` and stode pullbacks.
253
+
The forward part needs to replace each call of the function by a call to `rrule` and store pullbacks.
235
254
So in pseudocode, we want something like
236
255
```julia
237
256
(%1, %2) =rrule(*, _2, _3)
@@ -249,7 +268,7 @@ To implement the code performing the above transformation, we initiate few varia
249
268
```julia
250
269
adinfo = [] # storage for informations about pullbacks, needed for the construction of the reverse pass
251
270
new_insts = Any[] # storate for instructions
252
-
new_line = Int32[] # Index of instruction we are differentiating
271
+
new_line =Int32[] # Index of instruction we are differentiating
253
272
ssamap =Dict{SSAValue,SSAValue}() # this maps old SSA values to new SSA values, since they need to be linearly ordered.
254
273
```
255
274
@@ -274,7 +293,7 @@ The main loop transforming the function looks like foollows
0 commit comments