From 08ebc4815bc00651ee5bf707eeba888ce4521022 Mon Sep 17 00:00:00 2001 From: KDr2 Date: Tue, 22 Oct 2024 19:58:59 +0800 Subject: [PATCH] eval static parameter when binding vars --- .github/workflows/Testing.yaml | 1 + src/tapedfunction.jl | 15 ++++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Testing.yaml b/.github/workflows/Testing.yaml index 48d03b62..728f92e1 100644 --- a/.github/workflows/Testing.yaml +++ b/.github/workflows/Testing.yaml @@ -12,6 +12,7 @@ jobs: matrix: version: - '1.7' + - '1.10' - '1' - 'nightly' os: diff --git a/src/tapedfunction.jl b/src/tapedfunction.jl index cf9f74c0..520468f2 100644 --- a/src/tapedfunction.jl +++ b/src/tapedfunction.jl @@ -269,9 +269,10 @@ end const IRVar = Union{Core.SSAValue, Core.SlotNumber} -function bind_var!(var_literal, bindings::Bindings, ir::Core.CodeInfo) - # for literal constants - push!(bindings, var_literal) +function bind_var!(var, bindings::Bindings, ir::Core.CodeInfo) + # for literal constants, and statuc parameter + var = Meta.isexpr(var, :static_parameter) ? ir.parent.sparam_vals[var.args[1]] : var + push!(bindings, var) idx = length(bindings) return idx end @@ -412,12 +413,8 @@ function translate!!(var::IRVar, line::Expr, bindings::Bindings, isconst::Bool, ir::Core.CodeInfo) head = line.head _bind_fn = (x) -> bind_var!(x, bindings, ir) - # expand static parameter - _expand_sp = (x) -> begin - Meta.isexpr(x, :static_parameter) ? ir.parent.sparam_vals[x.args[1]] : x - end if head === :new - args = map(_bind_fn ∘ _expand_sp, line.args) + args = map(_bind_fn, line.args) return Instruction(__new__, args |> Tuple, _bind_fn(var)) elseif head === :call # Only some of the function calls can be optimized even though many of their results are @@ -427,7 +424,7 @@ function translate!!(var::IRVar, line::Expr, v = ir.ssavaluetypes[var.id].val _canbeoptimized(v) && return _const_instruction(var, v, bindings, ir) end - args = map(_bind_fn ∘ _expand_sp, line.args) + args = map(_bind_fn, line.args) # args[1] is the function func = line.args[1] if Meta.isexpr(func, :static_parameter) # func is a type parameter