Skip to content

Commit

Permalink
Merge pull request #26079 from JuliaLang/kf/phinode
Browse files Browse the repository at this point in the history
Very WIP: New optimizer
  • Loading branch information
Keno authored Feb 28, 2018
2 parents 13f42e6 + 20e02b8 commit 2345371
Show file tree
Hide file tree
Showing 43 changed files with 2,820 additions and 393 deletions.
10 changes: 10 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ end

copyto!(dest::Array{T}, src::Array{T}) where {T} = copyto!(dest, 1, src, 1, length(src))

# N.B: The generic definition in multidimensional.jl covers, this, this is just here
# for bootstrapping purposes.
function fill!(dest::Array{T}, x) where T
xT = convert(T, x)
for i in 1:length(dest)
@inbounds dest[i] = xT
end
dest
end

"""
copy(x)
Expand Down
14 changes: 13 additions & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@
# label::Int
#end

#struct PiNode
# val
# typ
#end

#struct PhiNode
# edges::Vector{Any}
# values::Vector{Any}
#end

#struct QuoteNode
# value
#end
Expand Down Expand Up @@ -141,7 +151,7 @@ export
TypeError, ArgumentError, MethodError, AssertionError, LoadError, InitError,
UndefKeywordError,
# AST representation
Expr, QuoteNode, LineNumberNode, GlobalRef,
Expr, QuoteNode, LineNumberNode, GlobalRef, PiNode, PhiNode,
# object model functions
fieldtype, getfield, setfield!, nfields, throw, tuple, ===, isdefined, eval,
# sizeof # not exported, to avoid conflicting with Base.sizeof
Expand Down Expand Up @@ -344,6 +354,8 @@ eval(Core, :(LineNumberNode(l::Int, @nospecialize(f)) = $(Expr(:new, :LineNumber
eval(Core, :(GlobalRef(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))))
eval(Core, :(SlotNumber(n::Int) = $(Expr(:new, :SlotNumber, :n))))
eval(Core, :(TypedSlot(n::Int, @nospecialize(t)) = $(Expr(:new, :TypedSlot, :n, :t))))
eval(Core, :(PhiNode(edges::Array{Any, 1}, values::Array{Any, 1}) = $(Expr(:new, :PhiNode, :edges, :values))))
eval(Core, :(PiNode(val, typ) = $(Expr(:new, :PiNode, :val, :typ))))

Module(name::Symbol=:anonymous, std_imports::Bool=true) = ccall(:jl_f_new_module, Ref{Module}, (Any, Bool), name, std_imports)

Expand Down
2 changes: 1 addition & 1 deletion base/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Core.Intrinsics:
checked_srem_int,
checked_uadd_int, checked_usub_int, checked_umul_int, checked_udiv_int,
checked_urem_int
import Base: no_op_err, @_inline_meta, @_noinline_meta
import ..no_op_err, ..@_inline_meta, ..@_noinline_meta

# define promotion behavior for checked operations
checked_add(x::Integer, y::Integer) = checked_add(promote(x,y)...)
Expand Down
2 changes: 0 additions & 2 deletions base/compiler/bootstrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ let fs = Any[typeinf_ext, typeinf, typeinf_edge, pure_eval_call],
end
end
end

ccall(:jl_set_typeinf_func, Cvoid, (Any,), typeinf_ext)
26 changes: 26 additions & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ include("refvalue.jl")
# checked arithmetic
const checked_add = +
const checked_sub = -
const SignedInt = Union{Int8,Int16,Int32,Int64,Int128}
const UnsignedInt = Union{UInt8,UInt16,UInt32,UInt64,UInt128}
sub_with_overflow(x::T, y::T) where {T<:SignedInt} = checked_ssub_int(x, y)
sub_with_overflow(x::T, y::T) where {T<:UnsignedInt} = checked_usub_int(x, y)
sub_with_overflow(x::Bool, y::Bool) = (x-y, false)
add_with_overflow(x::T, y::T) where {T<:SignedInt} = checked_sadd_int(x, y)
add_with_overflow(x::T, y::T) where {T<:UnsignedInt} = checked_uadd_int(x, y)
add_with_overflow(x::Bool, y::Bool) = (x+y, false)

# core array operations
include("indices.jl")
Expand All @@ -66,12 +74,29 @@ include("reduce.jl")
include("bitarray.jl")
include("bitset.jl")
include("abstractdict.jl")
include("abstractset.jl")
include("iterators.jl")
using .Iterators: zip, enumerate
using .Iterators: Flatten, product # for generators
include("namedtuple.jl")

# core docsystem
include("docs/core.jl")

# SubArray
include("subarray.jl")
macro views(x); esc(x); end

# sorting
function sort end
function sort! end
function issorted end
function sortperm end
include("ordering.jl")
using .Order
include("sort.jl")
using .Sort

############
# compiler #
############
Expand All @@ -96,6 +121,7 @@ include("compiler/typeinfer.jl")
include("compiler/optimize.jl") # TODO: break this up further + extract utilities

include("compiler/bootstrap.jl")
ccall(:jl_set_typeinf_func, Cvoid, (Any,), typeinf_ext)

end # baremodule Compiler
))
Loading

0 comments on commit 2345371

Please sign in to comment.