@@ -11,7 +11,7 @@ in a non-strict SSA form. Then we convert each IR instruction to a
11
11
Julia representation (an object of a subtype of
12
12
AbstractInstruction). All the operands (i.e., the varibales) these
13
13
instructions use are stored in a data structure called
14
- `bindings `. This conversion/binding process is performed at
14
+ `Bindings `. This conversion/binding process is performed at
15
15
compile-time / tape-recording time.
16
16
17
17
There are mainly three kinds of instructions on a tape:
@@ -23,7 +23,7 @@ There are mainly three kinds of instructions on a tape:
23
23
24
24
Once the tape is recorded, we can run the tape to gain the same effect
25
25
as calling the original function. We first fill the arguments into
26
- the bindings , then go through each instruction on the tape, stop after
26
+ the Bindings , then go through each instruction on the tape, stop after
27
27
we encounter a ReturnInstruction.
28
28
29
29
We provide a mechanism to add a callback after each instruction, with
@@ -67,9 +67,9 @@ mutable struct TapedFunction{F, TapeType}
67
67
ir:: Core.CodeInfo
68
68
tape:: TapeType
69
69
counter:: Int
70
- bindings :: Bindings
71
- arg_indices :: Vector{Int} # arg indices in bindings
72
- retval :: Int # 0 indicates the function has not returned
70
+ binding_values :: Bindings
71
+ arg_binding_slots :: Vector{Int} # arg indices in binding_values
72
+ retval_binding_slot :: Int # 0 indicates the function has not returned
73
73
74
74
function TapedFunction {F, T} (f:: F , args... ; cache= false ) where {F, T}
75
75
args_type = _accurate_typeof .(args)
@@ -82,9 +82,9 @@ mutable struct TapedFunction{F, TapeType}
82
82
return tf
83
83
end
84
84
ir = _infer (f, args_type)
85
- bindings , slots, tape = translate! (RawTape (), ir)
85
+ binding_values , slots, tape = translate! (RawTape (), ir)
86
86
87
- tf = new {F, T} (f, length (args), ir, tape, 1 , bindings , slots, 0 )
87
+ tf = new {F, T} (f, length (args), ir, tape, 1 , binding_values , slots, 0 )
88
88
TRCache[cache_key] = tf # set cache
89
89
return tf
90
90
end
@@ -94,7 +94,7 @@ mutable struct TapedFunction{F, TapeType}
94
94
95
95
function TapedFunction {F, T0} (tf:: TapedFunction{F, T1} ) where {F, T0, T1}
96
96
new {F, T0} (tf. func, tf. arity, tf. ir, tf. tape,
97
- tf. counter, tf. bindings , tf. arg_indices , 0 )
97
+ tf. counter, tf. binding_values , tf. arg_binding_slots , 0 )
98
98
end
99
99
100
100
TapedFunction (tf:: TapedFunction{F, T} ) where {F, T} = TapedFunction {F, T} (tf)
113
113
114
114
compile (tf:: TapedFunction{F, RawTape} ) where {F} = TapedFunction {F, CompiledTape} (tf)
115
115
116
- @inline _lookup (tf:: TapedFunction , v:: Int ) = @inbounds tf. bindings [v]
117
- @inline _update_var! (tf:: TapedFunction , v:: Int , c) = @inbounds tf. bindings [v] = c
116
+ @inline _lookup (tf:: TapedFunction , v:: Int ) = @inbounds tf. binding_values [v]
117
+ @inline _update_var! (tf:: TapedFunction , v:: Int , c) = @inbounds tf. binding_values [v] = c
118
118
119
119
"""
120
120
Instruction
@@ -144,21 +144,21 @@ end
144
144
145
145
struct NOOPInstruction <: AbstractInstruction end
146
146
147
- @inline result (t:: TapedFunction ) = t. bindings [t. retval ]
147
+ @inline result (t:: TapedFunction ) = t. binding_values [t. retval_binding_slot ]
148
148
149
149
function (tf:: TapedFunction )(args... ; callback= nothing , continuation= false )
150
- if ! continuation # reset counter and retval to run from the start
150
+ if ! continuation # reset counter and retval_binding_slot to run from the start
151
151
tf. counter = 1
152
- tf. retval = 0
152
+ tf. retval_binding_slot = 0
153
153
end
154
154
155
155
# set args
156
156
if tf. counter <= 1
157
- # The first slot in `bindings ` is assumed to be `tf.func`.
158
- tf. arg_indices [1 ] > 0 && _update_var! (tf, tf. arg_indices [1 ], tf. func)
159
- for i in 1 : length (args) # the subsequent arg_indices are arguments
157
+ # The first slot in `binding_values ` is assumed to be `tf.func`.
158
+ tf. arg_binding_slots [1 ] > 0 && _update_var! (tf, tf. arg_binding_slots [1 ], tf. func)
159
+ for i in 1 : length (args) # the subsequent arg_binding_slots are arguments
160
160
slot = i + 1
161
- tf. arg_indices [slot] > 0 && _update_var! (tf, tf. arg_indices [slot], args[i])
161
+ tf. arg_binding_slots [slot] > 0 && _update_var! (tf, tf. arg_binding_slots [slot], args[i])
162
162
end
163
163
end
164
164
@@ -167,7 +167,7 @@ function (tf::TapedFunction)(args...; callback=nothing, continuation=false)
167
167
ins = tf. tape[tf. counter]
168
168
ins (tf)
169
169
callback != = nothing && callback ()
170
- tf. retval != 0 && break
170
+ tf. retval_binding_slot != 0 && break
171
171
end
172
172
return result (tf)
173
173
end
@@ -244,7 +244,7 @@ function (instr::CondGotoInstruction)(tf::TapedFunction)
244
244
end
245
245
246
246
function (instr:: ReturnInstruction )(tf:: TapedFunction )
247
- tf. retval = instr. arg
247
+ tf. retval_binding_slot = instr. arg
248
248
end
249
249
250
250
function (instr:: NOOPInstruction )(tf:: TapedFunction )
@@ -315,10 +315,10 @@ function allocate_binding!(var, tbind::TempBindings, ::Type{T}) where T
315
315
end
316
316
317
317
function translate! (tape:: RawTape , ir:: Core.CodeInfo )
318
- bindings = Bindings ()
319
- sizehint! (bindings , 128 )
318
+ binding_values = Bindings ()
319
+ sizehint! (binding_values , 128 )
320
320
bcache = Dict {IRVar, Int} ()
321
- tbind = TempBindings (bindings , bcache)
321
+ tbind = TempBindings (binding_values , bcache)
322
322
slots = Dict {Int, Int} ()
323
323
324
324
for (idx, line) in enumerate (ir. code)
@@ -330,11 +330,11 @@ function translate!(tape::RawTape, ir::Core.CodeInfo)
330
330
for (k, v) in tbind. book
331
331
isa (k, Core. SlotNumber) && (slots[k. id] = v)
332
332
end
333
- arg_indices = fill (0 , maximum (keys (slots)))
333
+ arg_binding_slots = fill (0 , maximum (keys (slots)))
334
334
for (k, v) in slots
335
- arg_indices [k] = v
335
+ arg_binding_slots [k] = v
336
336
end
337
- return (bindings, arg_indices , tape)
337
+ return (binding_values, arg_binding_slots , tape)
338
338
end
339
339
340
340
function _const_instruction (var:: IRVar , v, tbind:: TempBindings , ir)
475
475
476
476
function Base. copy (tf:: TapedFunction )
477
477
new_tf = TapedFunction (tf)
478
- new_tf. bindings = copy_bindings (tf. bindings )
478
+ new_tf. binding_values = copy_bindings (tf. binding_values )
479
479
return new_tf
480
480
end
0 commit comments