Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/analysis/alias.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ non-anchor operands like literals) collapse to `ALIAS_UNIVERSE` — the
"may alias anything" default policy is encoded here, once.
"""
function alias_class(info::AliasInfo, @nospecialize(op))
op isa SSAValue || op isa Argument || op isa SlotNumber || return ALIAS_UNIVERSE
op isa SSAValue || op isa Argument || return ALIAS_UNIVERSE
return something(info[op], ALIAS_UNIVERSE)
end

Expand Down
7 changes: 3 additions & 4 deletions src/compiler/analysis/dataflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
LatticeAnchor

The keys that dataflow results are indexed by: an SSA value defined in some
block, a block argument, or a kernel parameter reference (`Argument` /
`SlotNumber`). `BlockArgument` is used for loop-carried values and IfOp
outputs.
block, a block argument, or a kernel parameter reference (`Argument`).
`BlockArgument` is used for loop-carried values and IfOp outputs.
"""
const LatticeAnchor = Union{SSAValue, BlockArgument, Argument, SlotNumber}
const LatticeAnchor = Union{SSAValue, BlockArgument, Argument}


#=============================================================================
Expand Down
29 changes: 0 additions & 29 deletions src/compiler/codegen/expressions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ function emit_expr!(ctx::CGCtx, expr::Expr, @nospecialize(result_type))
return emit_call!(ctx, expr, result_type)
elseif expr.head === :invoke
return emit_invoke!(ctx, expr, result_type)
elseif expr.head === :(=)
return emit_assignment!(ctx, expr, result_type)
elseif expr.head === :new
return emit_new!(ctx, expr, result_type)
elseif expr.head === :foreigncall
Expand Down Expand Up @@ -56,33 +54,6 @@ function emit_new!(ctx::CGCtx, expr::Expr, @nospecialize(result_type))
throw(IRError("Struct construction not supported in Tile IR: $T"))
end

function emit_assignment!(ctx::CGCtx, expr::Expr, @nospecialize(result_type))
lhs = expr.args[1]
rhs = expr.args[2]

tv = emit_rhs!(ctx, rhs, result_type)

if lhs isa SlotNumber && tv !== nothing
ctx[lhs] = tv
end

return tv
end

function emit_rhs!(ctx::CGCtx, @nospecialize(rhs), @nospecialize(result_type))
if rhs isa Expr
return emit_expr!(ctx, rhs, result_type)
elseif rhs isa SSAValue || rhs isa SlotNumber || rhs isa Argument
return emit_value!(ctx, rhs)
elseif rhs isa QuoteNode
return emit_constant!(ctx, rhs.value, result_type)
elseif rhs isa GlobalRef
return emit_value!(ctx, rhs)
else
return emit_constant!(ctx, rhs, result_type)
end
end

#=============================================================================
Call Emission
=============================================================================#
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/codegen/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ Base.@nospecializeinfer function emit_kernel!(writer::BytecodeWriter, func_buf::
tv = ghost_value(argtype_unwrapped,
Base.issingletontype(argtype_unwrapped) ?
argtype_unwrapped.instance : nothing)
ctx[SlotNumber(i)] = tv
ctx[Argument(i)] = tv
continue
elseif is_const_arg(i)
Expand Down Expand Up @@ -157,7 +156,6 @@ Base.@nospecializeinfer function emit_kernel!(writer::BytecodeWriter, func_buf::
# body is uniformly tile-typed after scalar_elim_pass!.
jltype = boundary_jltype(argtype)
tv = CGVal(val, type_id, jltype)
ctx[SlotNumber(arg_idx)] = tv
ctx[Argument(arg_idx)] = tv
end
end
Expand All @@ -179,7 +177,6 @@ Base.@nospecializeinfer function emit_kernel!(writer::BytecodeWriter, func_buf::
# Non-primitive (tuple etc.): ghost with constant
tv = ghost_value(T, val)
end
ctx[SlotNumber(i)] = tv
ctx[Argument(i)] = tv
end
end
Expand All @@ -188,7 +185,6 @@ Base.@nospecializeinfer function emit_kernel!(writer::BytecodeWriter, func_buf::
for (arg_idx, argtype) in enumerate(ctx.arg_types)
argtype === nothing && continue
tv = arg_ref_value(arg_idx, Int[], argtype)
ctx[SlotNumber(arg_idx)] = tv
ctx[Argument(arg_idx)] = tv
end

Expand Down
2 changes: 0 additions & 2 deletions src/compiler/codegen/statements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ function emit_statement!(ctx::CGCtx, @nospecialize(stmt), ssa_idx::Int, @nospeci
tv = emit_value!(ctx, stmt)
elseif stmt isa QuoteNode
tv = emit_constant!(ctx, stmt.value, result_type)
elseif stmt isa SlotNumber
tv = ctx[stmt]
elseif stmt isa Argument
tv = emit_value!(ctx, stmt)
elseif stmt isa SSAValue
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/codegen/values.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function emit_value!(ctx::CGCtx, ssa::SSAValue)
return tv
end
emit_value!(ctx::CGCtx, arg::Argument) = ctx[arg]
emit_value!(ctx::CGCtx, slot::SlotNumber) = ctx[slot]
emit_value!(ctx::CGCtx, block_arg::BlockArgument) = ctx[block_arg]

function emit_value!(ctx::CGCtx, val::Integer)
Expand Down Expand Up @@ -101,7 +100,7 @@ and unwrap in one step.
"""
function get_constant(ctx::CGCtx, @nospecialize(ref))
# Direct values (not IR references) - return as-is
if !(ref isa SSAValue || ref isa Argument || ref isa SlotNumber ||
if !(ref isa SSAValue || ref isa Argument ||
ref isa Expr || ref isa GlobalRef || ref isa QuoteNode)
return Some(ref)
end
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transform/throws.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function throw_constant(sci::StructuredIRCode, def_index, @nospecialize(x))
return Some(string(vals...))
end
return nothing
elseif x isa Union{Argument, SlotNumber, BlockArgument, Expr}
elseif x isa Union{Argument, BlockArgument, Expr}
return nothing
else
return Some(x)
Expand All @@ -40,7 +40,7 @@ end
function thrown_type(block::Block, @nospecialize(exception))
if exception isa QuoteNode
return typeof(exception.value)
elseif !(exception isa Union{SSAValue, Argument, SlotNumber, BlockArgument, Expr, GlobalRef})
elseif !(exception isa Union{SSAValue, Argument, BlockArgument, Expr, GlobalRef})
return typeof(exception)
end
T = value_type(block, exception)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transform/token_order.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#
# Mirrors cuTile Python's `token_order_pass`.

using Core: SSAValue, Argument, SlotNumber
using Core: SSAValue, Argument

#=============================================================================
Per-block memory effects
Expand Down
26 changes: 0 additions & 26 deletions src/compiler/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ mutable struct CGCtx
# Loop/if ops store a CGVal with tuple_values field (extracted by getfield statements)
values::Dict{Int, CGVal}
args::Dict{Int, CGVal} # Argument index -> CGVal
slots::Dict{Int, CGVal} # Slot number -> CGVal
block_args::Dict{Int, CGVal} # BlockArgument id -> CGVal (for control flow)

# Destructured argument handling: path-keyed flat values
Expand Down Expand Up @@ -384,7 +383,6 @@ function CGCtx(; cb::CodeBuilder, sci::StructuredIRCode,
Dict{Int, CGVal}(),
Dict{Int, CGVal}(),
Dict{Int, CGVal}(),
Dict{Int, CGVal}(),
Dict{Tuple{Int, Vector{Int}}, Vector{Value}}(),
Vector{Union{Type, Nothing}}(nothing, length(sci.argtypes) + 1),
cb,
Expand Down Expand Up @@ -437,10 +435,6 @@ function Base.getindex(ctx::CGCtx, arg::Argument)
get(ctx.args, arg.n, nothing)
end

function Base.getindex(ctx::CGCtx, slot::SlotNumber)
get(ctx.slots, slot.id, nothing)
end

function Base.setindex!(ctx::CGCtx, tv::CGVal, ssa::SSAValue)
ctx.values[ssa.id] = tv
end
Expand All @@ -449,10 +443,6 @@ function Base.setindex!(ctx::CGCtx, tv::CGVal, arg::Argument)
ctx.args[arg.n] = tv
end

function Base.setindex!(ctx::CGCtx, tv::CGVal, slot::SlotNumber)
ctx.slots[slot.id] = tv
end

function Base.getindex(ctx::CGCtx, block_arg::BlockArgument)
get(ctx.block_args, block_arg.id, nothing)
end
Expand Down Expand Up @@ -792,22 +782,6 @@ end
# Argument helpers
#-----------------------------------------------------------------------------

"""
extract_argument_index(arg) -> Union{Int, Nothing}

Extract the raw argument index from a SlotNumber or Argument.
Returns the index that corresponds directly to `ir.argtypes[idx]`.
Note: index 1 is the function itself; user args start at index 2.
"""
function extract_argument_index(@nospecialize(arg))
if arg isa SlotNumber
return arg.id
elseif arg isa Argument
return arg.n
end
nothing
end

#-----------------------------------------------------------------------------
# Tile helpers
#-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/cuTile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using IRStructurizer: Block, ControlFlowOp, BlockArgument,
import IRStructurizer: operands, replace_uses!, insert_before!

using Base: compilerbarrier, donotdelete
using Core: MethodInstance, CodeInfo, SSAValue, Argument, SlotNumber,
using Core: MethodInstance, CodeInfo, SSAValue, Argument,
ReturnNode, PiNode, QuoteNode, GlobalRef
using Core.Compiler
const CC = Core.Compiler
Expand Down
3 changes: 1 addition & 2 deletions test/codegen/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,7 @@ const _CODEGEN_TEST_FLOAT64 = 3.14159
end

@testset "external constant assigned to local variable" begin
# Bug 2: GlobalRef on RHS of assignment in emit_rhs! returned nothing.
# Using a local variable forces Julia to emit an assignment from the GlobalRef.
# Bug 2: a GlobalRef bound to a local variable was emitted as nothing.
@test @filecheck begin
@check_label "entry"
code_tiled(Tuple{ct.TileArray{Float32,1,Int32,spec1d}}) do a
Expand Down