Skip to content

Commit e93e199

Browse files
committed
Use IRStructurizer APIs.
1 parent cde62c4 commit e93e199

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/compiler/passes/licm.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# The algorithm walks the IR recursively while tracking the definition depth
77
# of each value. An operation whose data dependencies all resolve to depths
88
# *less than* its containing loop can be hoisted above that loop. A stack of
9-
# SSAMaps collects operations at their target depth; at the end of each block,
10-
# the original body is replaced with the (filtered) rebuilt map.
9+
# instruction lists collects operations at their target depth; at the end of
10+
# each block, the original body is rebuilt from the filtered list.
1111

1212
# Whether a block can be moved, based on the operations it contains.
1313
@enum BlockMobility begin
@@ -35,7 +35,7 @@ function update!(di::DependencyInfo, dep_depth::Int, cur_depth::Int)
3535
end
3636

3737
struct StackItem
38-
new_body::SSAMap
38+
entries::Vector{Tuple{Int,Any,Any}} # (ssa_idx, stmt, typ) triples
3939
is_loop_body::Bool
4040
end
4141

@@ -57,8 +57,7 @@ end
5757
function _hoist!(block::Block, stack::Vector{StackItem}, def_depth::Dict{Any,Int},
5858
is_loop_body::Bool)
5959
depth = length(stack)
60-
new_body = SSAMap()
61-
push!(stack, StackItem(new_body, is_loop_body))
60+
push!(stack, StackItem(Tuple{Int,Any,Any}[], is_loop_body))
6261

6362
mobility = CAN_MOVE
6463
min_depth = 0
@@ -148,20 +147,25 @@ function _hoist!(block::Block, stack::Vector{StackItem}, def_depth::Dict{Any,Int
148147
end
149148

150149
# Place at target depth
151-
push!(stack[target_depth + 1].new_body, (inst.ssa_idx, s, inst.typ))
150+
push!(stack[target_depth + 1].entries, (inst.ssa_idx, s, inst.typ))
152151

153152
# Record definition depth AFTER hoisting (enables cascading hoists)
154153
def_depth[SSAValue(inst.ssa_idx)] = target_depth
155154
end
156155

157-
# Handle terminator operands for min_depth computation
156+
# Handle terminator for mobility
158157
term = block.terminator
159158
if term isa ContinueOp || term isa BreakOp
160159
mobility = min(mobility, CAN_MOVE_WITH_LOOP)
161160
end
162161

163-
pop!(stack)
164-
block.body = new_body
162+
# Rebuild block body from collected entries
163+
entries = pop!(stack).entries
164+
empty!(block)
165+
for (idx, s, typ) in entries
166+
push!(block, idx, s, typ)
167+
end
168+
165169
return BlockResult(mobility, min_depth)
166170
end
167171

src/cuTile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module cuTile
22

33
using IRStructurizer
4-
using IRStructurizer: Block, ControlFlowOp, BlockArgument, SSAMap,
4+
using IRStructurizer: Block, ControlFlowOp, BlockArgument,
55
YieldOp, ContinueOp, BreakOp, ConditionOp,
66
IfOp, ForOp, WhileOp, LoopOp, Undef,
77
SourceLocation, source_location

0 commit comments

Comments
 (0)