Skip to content

Add a few convenience utilities #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2020
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
1 change: 1 addition & 0 deletions src/LoopVectorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export LowDimArray, stridedpointer, vectorizable,


include("vectorizationbase_extensions.jl")
include("predicates.jl")
include("map.jl")
include("filter.jl")
include("costs.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ function substitute_broadcast(q::Expr, mod::Symbol)
f = first(ciₙargs)
if ciₙ.head === :(=)
push!(ex.args, Expr(:(=), f, syms[((ciₙargs[2])::Core.SSAValue).id]))
elseif f === GlobalRef(Base, :materialize!)
elseif isglobalref(f, Base, :materialize!)
add_ci_call!(ex, lv(:vmaterialize!), ciₙargs, syms, n, mod)
elseif f === GlobalRef(Base, :materialize)
elseif isglobalref(f, Base, :materialize)
add_ci_call!(ex, lv(:vmaterialize), ciₙargs, syms, n, mod)
else
add_ci_call!(ex, f, ciₙargs, syms, n)
Expand Down
2 changes: 1 addition & 1 deletion src/costs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function isreductcombineinstr(instr::Symbol)
end
isreductcombineinstr(instr::Instruction) = isreductcombineinstr(instr.instr)

const FUNCTIONSYMBOLS = Dict{Type{<:Function},Instruction}(
const FUNCTIONSYMBOLS = IdDict{Type{<:Function},Instruction}(
typeof(+) => :(+),
typeof(SIMDPirates.vadd) => :(+),
typeof(SIMDPirates.vadd!) => :(+),
Expand Down
4 changes: 2 additions & 2 deletions src/graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function terminatecondition(
looprange(loop, 1, mangledname)
end

# load/compute/store × isunroled × istiled × pre/post loop × Loop number
# load/compute/store × isunrolled × istiled × pre/post loop × Loop number
struct LoopOrder <: AbstractArray{Vector{Operation},5}
oporder::Vector{Vector{Operation}}
loopnames::Vector{Symbol}
Expand Down Expand Up @@ -402,7 +402,7 @@ function register_single_loop!(ls::LoopSet, looprange::Expr)
L = add_loop_bound!(ls, itersym, Expr(:call, :first, N), false)
U = add_loop_bound!(ls, itersym, Expr(:call, :last, N), true)
Loop(itersym, L, U)
elseif f === :OneTo || f == Expr(:(.), :Base, QuoteNode(:OneTo))
elseif f === :OneTo || isscopedname(f, :Base, :OneTo)
otN = r.args[2]
if otN isa Integer
Loop(itersym, 0, otN)
Expand Down
23 changes: 23 additions & 0 deletions src/predicates.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
isscopedname(ex, modpath, name::Symbol)

Test whether expression `ex` is a module-scoped `name`. Both of these return `true`:

```
isscopedname(:(Base.OneTo), :Base, :OneTo)
isscopedname(:(Base.Checked.checked_add), (:Base, :Checked), :checked_add)
```
"""
function isscopedname(ex, modpath, name::Symbol)
isexpr(ex, :(.), 2) && (a = ex.args[2]; isa(a, QuoteNode) && a.value === name) && hasscope(ex.args[1], modpath)
end
hasscope(modex, mod::Symbol) = modex === mod
hasscope(modex, mod::Tuple{Symbol}) = hasscope(modex, mod[1])
hasscope(modex, modpath::Tuple{Vararg{Symbol}}) = isscopedname(modex, Base.front(modpath), modpath[end])

"""
isglobalref(g, mod, name)

Return true if `g` is equal to `GlobalRef(mod, name)`.
"""
isglobalref(g, mod, name) = isa(g, GlobalRef) && g.mod === mod && g.name === name
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ end

@time include("printmethods.jl")

@time include("utils.jl")

@time include("offsetarrays.jl")

@time include("map.jl")

@time include("filter.jl")
Expand Down
15 changes: 15 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using LoopVectorization
using Test

@testset "Utilities" begin
@test LoopVectorization.isscopedname(:(Base.OneTo), :Base, :OneTo)
@test LoopVectorization.isscopedname(:(A.B.C.D), (:A, :B, :C), :D)
@test !LoopVectorization.isscopedname(:(A.B.D), (:A, :B, :C), :D)
@test !LoopVectorization.isscopedname(:(A.B.C.D), (:A, :B, :C), :E)
@test !LoopVectorization.isscopedname(:hello, :Base, :OneTo)

@test LoopVectorization.isglobalref(GlobalRef(Base, :getindex), Base, :getindex)
@test !LoopVectorization.isglobalref(GlobalRef(Base, :getindex), Base, :setindex!)
@test !LoopVectorization.isglobalref(GlobalRef(Core, :getindex), Base, :getindex)
@test !LoopVectorization.isglobalref(:getindex, Base, :getindex)
end