Skip to content

Commit a3373e8

Browse files
committed
Don't splat into Expr.
1 parent 715ed8f commit a3373e8

File tree

7 files changed

+34
-16
lines changed

7 files changed

+34
-16
lines changed

src/add_ifelse.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function add_andblock!(ls::LoopSet, condexpr::Expr, condeval::Expr, elementbytes
5959
if condeval.head === :call
6060
@assert first(condeval.args) === :setindex!
6161
array, raw_indices = ref_from_setindex!(ls, condeval)
62-
ref = Expr(:ref, array, raw_indices...)
62+
ref = Expr(:ref, array); append!(ref.args, raw_indices)
6363
return add_andblock!(ls, condop, ref, condeval.args[3], elementbytes, position)
6464
end
6565
@assert condeval.head === :(=)
@@ -100,7 +100,8 @@ function add_orblock!(ls::LoopSet, condexpr::Expr, condeval::Expr, elementbytes:
100100
if condeval.head === :call
101101
@assert first(condeval.args) === :setindex!
102102
array, raw_indices = ref_from_setindex!(ls, condeval)
103-
return add_orblock!(ls, condop, Expr(:ref, array, raw_indices...), condeval.args[3], elementbytes, position)
103+
ref = Expr(:ref, array); append!(ref.args, raw_indices)
104+
return add_orblock!(ls, condop, ref, condeval.args[3], elementbytes, position)
104105
end
105106
@assert condeval.head === :(=)
106107
@assert length(condeval.args) == 2

src/broadcast.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ function LowDimArray{D}(data::A) where {D,T,N,A <: AbstractArray{T,N}}
128128
end
129129
function extract_all_1_array!(ls::LoopSet, bcname::Symbol, N::Int, elementbytes::Int)
130130
refextract = gensym(bcname)
131-
pushpreamble!(ls, Expr(:(=), refextract, Expr(:ref, bcname, [1 for n 1:N]...)))
131+
ref = Expr(:ref, bcname); append!(ref.args, [1 for n 1:N])
132+
pushpreamble!(ls, Expr(:(=), refextract, ref))
132133
return add_constant!(ls, refextract, elementbytes) # or replace elementbytes with sizeof(T) ? u
133134
end
134135
function add_broadcast!(

src/costs.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ struct Instruction
1818
end
1919
# lower(instr::Instruction) = Expr(:(.), instr.mod, QuoteNode(instr.instr))
2020
# Base.convert(::Type{Expr}, instr::Instruction) = Expr(:(.), instr.mod, QuoteNode(instr.instr))
21-
function Base.Expr(instr::Instruction, args...)
21+
function callexpr(instr::Instruction)
2222
if instr.mod === :LoopVectorization
23-
Expr(:call, lv(instr.instr), args...)::Expr
23+
Expr(:call, lv(instr.instr))
2424
else#if instr.mod === :Main
25-
Expr(:call, instr.instr, args...)::Expr
26-
# else
27-
# Expr(:call, convert(Expr, instr), args...)::Expr
25+
Expr(:call, instr.instr)
2826
end
2927
end
28+
function callexpr(instr::Instruction, arg)
29+
ce = callexpr(instr)
30+
append!(ce.args, arg)
31+
ce
32+
end
3033
Base.hash(instr::Instruction, h::UInt64) = hash(instr.instr, hash(instr.mod, h))
3134
# function Base.isless(instr1::Instruction, instr2::Instruction)
3235
# if instr1.mod === instr2.mod

src/lower_compute.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function lower_compute!(
200200
isvectorized = vectorized loopdependencies(op)
201201
modsuffix = 0
202202
for u 0:Uiter
203-
instrcall = Expr(instr) # Expr(:call, instr)
203+
instrcall = callexpr(instr)
204204
varsym = if tiledouterreduction > 0 # then suffix !== nothing
205205
modsuffix = ((u + suffix*(Uiter + 1)) & 3)
206206
# modsuffix = u

src/lower_store.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,25 @@ end
4545
function reduce_range!(q::Expr, toreduct::Symbol, instr::Instruction, Uh::Int, Uh2::Int)
4646
if 2Uh == Uh2
4747
for u 0:2:Uh2-1
48-
push!(q.args, Expr(:(=), Symbol(toreduct, (u>>>1)), Expr(instr, Symbol(toreduct, u), Symbol(toreduct, u + 1))))
48+
instrexpr = callexpr(instr)
49+
push!(instrexpr.args, Symbol(toreduct, u))
50+
push!(instrexpr.args, Symbol(toreduct, u + 1))
51+
push!(q.args, Expr(:(=), Symbol(toreduct, (u>>>1)), instrexpr))
4952
end
5053
else
5154
for u Uh:Uh2-1
5255
tru = Symbol(toreduct, u - Uh)
53-
push!(q.args, Expr(:(=), tru, Expr(instr, tru, Symbol(toreduct, u))))
56+
instrexpr = callexpr(instr)
57+
push!(instrexpr.args, tru)
58+
push!(instrexpr.args, Symbol(toreduct, u))
59+
push!(q.args, Expr(:(=), tru, instrexpr))
5460
end
5561
for u 2Uh:Uh2-1
5662
tru = Symbol(toreduct, u - 2Uh)
57-
push!(q.args, Expr(:(=), tru, Expr(instr, tru, Symbol(toreduct, u))))
63+
instrexpr = callexpr(instr)
64+
push!(instrexpr.args, tru)
65+
push!(instrexpr.args, Symbol(toreduct, u))
66+
push!(q.args, Expr(:(=), tru, instrexpr))
5867
end
5968
end
6069
end

src/lowering.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ function lower_no_unroll(ls::LoopSet, us::UnrollSpecification, n::Int, inclmask:
241241
# Expr(:block, loopiteratesatleastonce(loop, true), Expr(:while, expect(tc), body))
242242
Expr(:block, Expr(:while, isstatic ? tc : expect(tc), body))
243243
elseif isstatic && length(loop) 8
244-
Expr(:block, (body for _ 1:length(loop))...)
244+
bodyq = Expr(:block)
245+
foreach(_ -> push!(bodyq.args, body), 1:length(loop))
246+
bodyq
245247
else
246248
termcond = gensym(:maybeterm)
247249
push!(body.args, Expr(:(=), termcond, isstatic ? tc : expect(tc)))

src/operations.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,13 @@ function Base.show(io::IO, op::Operation)
242242
print(io, Expr(:(=), op.variable, op.instruction.instr))
243243
end
244244
elseif isload(op)
245-
print(io, Expr(:(=), op.variable, Expr(:ref, name(op.ref), getindices(op)...)))
245+
ref = Expr(:ref, name(op.ref)); append!(ref.args, getindices(op))
246+
print(io, Expr(:(=), op.variable, ref))
246247
elseif iscompute(op)
247-
print(io, Expr(:(=), op.variable, Expr(op.instruction, name.(parents(op))...)))
248+
print(io, Expr(:(=), op.variable, callexpr(op.instruction, map(name, parents(op)))))
248249
elseif isstore(op)
249-
print(io, Expr(:(=), Expr(:ref, name(op.ref), getindices(op)...), name(first(parents(op)))))
250+
ref = Expr(:ref, name(op.ref)); append!(ref.args, getindices(op))
251+
print(io, Expr(:(=), ref, name(first(parents(op)))))
250252
elseif isloopvalue(op)
251253
print(io, Expr(:(=), op.variable, op.variable))
252254
end

0 commit comments

Comments
 (0)