Skip to content

Commit

Permalink
compiler: test cleanups (JuliaLang#46281)
Browse files Browse the repository at this point in the history
These utilities are now defined within test/compiler/irutils.jl.
  • Loading branch information
aviatesk committed Aug 8, 2022
1 parent bcda258 commit 6cf58d6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
15 changes: 1 addition & 14 deletions test/compiler/EscapeAnalysis/setup.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include(normpath(@__DIR__, "..", "irutils.jl"))
include(normpath(@__DIR__, "EAUtils.jl"))
using Test, Core.Compiler.EscapeAnalysis, .EAUtils
import Core: Argument, SSAValue, ReturnNode
Expand All @@ -7,7 +8,6 @@ import .EA: ignore_argescape
isT(T) = (@nospecialize x) -> x === T
isreturn(@nospecialize x) = isa(x, Core.ReturnNode) && isdefined(x, :val)
isthrow(@nospecialize x) = Meta.isexpr(x, :call) && Core.Compiler.is_throw_call(x)
isnew(@nospecialize x) = Meta.isexpr(x, :new)
isϕ(@nospecialize x) = isa(x, Core.PhiNode)
function with_normalized_name(@nospecialize(f), @nospecialize(x))
if Meta.isexpr(x, :foreigncall)
Expand All @@ -20,19 +20,6 @@ end
isarrayalloc(@nospecialize x) = with_normalized_name(nn->!isnothing(Core.Compiler.alloc_array_ndims(nn)), x)
isarrayresize(@nospecialize x) = with_normalized_name(nn->!isnothing(EA.array_resize_info(nn)), x)
isarraycopy(@nospecialize x) = with_normalized_name(nn->EA.is_array_copy(nn), x)
import Core.Compiler: argextype, singleton_type
iscall(y) = @nospecialize(x) -> iscall(y, x)
function iscall((ir, f), @nospecialize(x))
return iscall(x) do @nospecialize x
singleton_type(Core.Compiler.argextype(x, ir, Any[])) === f
end
end
iscall(pred::Function, @nospecialize(x)) = Meta.isexpr(x, :call) && pred(x.args[1])

# check if `x` is a statically-resolved call of a function whose name is `sym`
isinvoke(y) = @nospecialize(x) -> isinvoke(y, x)
isinvoke(sym::Symbol, @nospecialize(x)) = isinvoke(mi->mi.def.name===sym, x)
isinvoke(pred::Function, @nospecialize(x)) = Meta.isexpr(x, :invoke) && pred(x.args[1]::Core.MethodInstance)

"""
is_load_forwardable(x::EscapeInfo) -> Bool
Expand Down
22 changes: 1 addition & 21 deletions test/compiler/inline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,26 +384,6 @@ using Base.Experimental: @opaque
f_oc_getfield(x) = (@opaque ()->x)()
@test fully_eliminated(f_oc_getfield, Tuple{Int})

import Core.Compiler: argextype, singleton_type
const EMPTY_SPTYPES = Any[]

code_typed1(args...; kwargs...) = first(only(code_typed(args...; kwargs...)))::Core.CodeInfo
get_code(args...; kwargs...) = code_typed1(args...; kwargs...).code

# check if `x` is a dynamic call of a given function
iscall(y) = @nospecialize(x) -> iscall(y, x)
function iscall((src, f)::Tuple{Core.CodeInfo,Base.Callable}, @nospecialize(x))
return iscall(x) do @nospecialize x
singleton_type(argextype(x, src, EMPTY_SPTYPES)) === f
end
end
iscall(pred::Base.Callable, @nospecialize(x)) = Meta.isexpr(x, :call) && pred(x.args[1])

# check if `x` is a statically-resolved call of a function whose name is `sym`
isinvoke(y) = @nospecialize(x) -> isinvoke(y, x)
isinvoke(sym::Symbol, @nospecialize(x)) = isinvoke(mi->mi.def.name===sym, x)
isinvoke(pred::Function, @nospecialize(x)) = Meta.isexpr(x, :invoke) && pred(x.args[1]::Core.MethodInstance)

@testset "@inline/@noinline annotation before definition" begin
M = Module()
@eval M begin
Expand Down Expand Up @@ -1253,7 +1233,7 @@ let src = code_typed1(g_call_peel, Tuple{Any})
end

const my_defined_var = 42
@test fully_eliminated((); retval=42) do
@test fully_eliminated(; retval=42) do
getglobal(@__MODULE__, :my_defined_var, :monotonic)
end
@test !fully_eliminated() do
Expand Down
4 changes: 2 additions & 2 deletions test/compiler/irutils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Core: CodeInfo, ReturnNode, MethodInstance
import Core.Compiler: argextype, singleton_type
import Core.Compiler: IRCode, IncrementalCompact, argextype, singleton_type
import Base.Meta: isexpr

argextype(@nospecialize args...) = argextype(args..., Any[])
Expand All @@ -12,7 +12,7 @@ isreturn(@nospecialize x) = isa(x, ReturnNode)

# check if `x` is a dynamic call of a given function
iscall(y) = @nospecialize(x) -> iscall(y, x)
function iscall((src, f)::Tuple{CodeInfo,Base.Callable}, @nospecialize(x))
function iscall((src, f)::Tuple{IR,Base.Callable}, @nospecialize(x)) where IR<:Union{CodeInfo,IRCode,IncrementalCompact}
return iscall(x) do @nospecialize x
singleton_type(argextype(x, src)) === f
end
Expand Down

0 comments on commit 6cf58d6

Please sign in to comment.