Skip to content

Commit

Permalink
Merge branch 'master' into source-build--zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
inkydragon committed Jul 7, 2022
2 parents aa7d881 + da13d78 commit 74fe80d
Show file tree
Hide file tree
Showing 76 changed files with 461 additions and 363 deletions.
2 changes: 2 additions & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ const REPL_MODULE_REF = Ref{Module}()

include("checked.jl")
using .Checked
function cld end
function fld end

# Lazy strings
include("strings/lazy.jl")
Expand Down
16 changes: 16 additions & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ include("refvalue.jl")

# the same constructor as defined in float.jl, but with a different name to avoid redefinition
_Bool(x::Real) = x==0 ? false : x==1 ? true : throw(InexactError(:Bool, Bool, x))
# fld(x,y) == div(x,y) - ((x>=0) != (y>=0) && rem(x,y) != 0 ? 1 : 0)
fld(x::T, y::T) where {T<:Unsigned} = div(x, y)
function fld(x::T, y::T) where T<:Integer
d = div(x, y)
return d - (signbit(x y) & (d * y != x))
end
# cld(x,y) = div(x,y) + ((x>0) == (y>0) && rem(x,y) != 0 ? 1 : 0)
function cld(x::T, y::T) where T<:Unsigned
d = div(x, y)
return d + (d * y != x)
end
function cld(x::T, y::T) where T<:Integer
d = div(x, y)
return d + (((x > 0) == (y > 0)) & (d * y != x))
end


# checked arithmetic
const checked_add = +
Expand Down
1 change: 1 addition & 0 deletions base/compiler/ssair/domtree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function compute_domtree_nodes!(domtree::DomTree)
(idx == 1 || idom == 0) && continue
push!(domtree.nodes[idom].children, idx)
end
# n.b. now issorted(domtree.nodes[*].children) since idx is sorted above
# Recursively set level
update_level!(domtree.nodes, 1, 1)
return domtree.nodes
Expand Down
28 changes: 17 additions & 11 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,14 @@ function get(x::LazyDomtree)
end

function perform_lifting!(compact::IncrementalCompact,
visited_phinodes::Vector{AnySSAValue}, @nospecialize(cache_key),
lifting_cache::IdDict{Pair{AnySSAValue, Any}, AnySSAValue},
@nospecialize(result_t), lifted_leaves::LiftedLeaves, @nospecialize(stmt_val),
lazydomtree::Union{LazyDomtree,Nothing})
reverse_mapping = IdDict{AnySSAValue, Int}(ssa => id for (id, ssa) in enumerate(visited_phinodes))
visited_phinodes::Vector{AnySSAValue}, @nospecialize(cache_key),
lifting_cache::IdDict{Pair{AnySSAValue, Any}, AnySSAValue},
@nospecialize(result_t), lifted_leaves::LiftedLeaves, @nospecialize(stmt_val),
lazydomtree::Union{LazyDomtree,Nothing})
reverse_mapping = IdDict{AnySSAValue, Int}()
for id in 1:length(visited_phinodes)
reverse_mapping[visited_phinodes[id]] = id
end

# Check if all the lifted leaves are the same
local the_leaf
Expand Down Expand Up @@ -645,25 +648,28 @@ function perform_lifting!(compact::IncrementalCompact,
end

# Insert PhiNodes
lifted_phis = LiftedPhi[]
for item in visited_phinodes
nphis = length(visited_phinodes)
lifted_phis = Vector{LiftedPhi}(undef, nphis)
for i = 1:nphis
item = visited_phinodes[i]
# FIXME this cache is broken somehow
# ckey = Pair{AnySSAValue, Any}(item, cache_key)
# cached = ckey in keys(lifting_cache)
cached = false
if cached
ssa = lifting_cache[ckey]
push!(lifted_phis, LiftedPhi(ssa, compact[ssa][:inst]::PhiNode, false))
lifted_phis[i] = LiftedPhi(ssa, compact[ssa][:inst]::PhiNode, false)
continue
end
n = PhiNode()
ssa = insert_node!(compact, item, effect_free(NewInstruction(n, result_t)))
# lifting_cache[ckey] = ssa
push!(lifted_phis, LiftedPhi(ssa, n, true))
lifted_phis[i] = LiftedPhi(ssa, n, true)
end

# Fix up arguments
for (old_node_ssa, lf) in zip(visited_phinodes, lifted_phis)
for i = 1:nphis
(old_node_ssa, lf) = visited_phinodes[i], lifted_phis[i]
old_node = compact[old_node_ssa][:inst]::PhiNode
new_node = lf.node
lf.need_argupdate || continue
Expand Down Expand Up @@ -1189,7 +1195,7 @@ function sroa_mutables!(ir::IRCode, defuses::IdDict{Int, Tuple{SPCSet, SSADefUse
if preserve_uses === nothing
preserve_uses = IdDict{Int, Vector{Any}}()
end
push!(get!(()->Any[], preserve_uses, use.idx), newval)
push!(get!(Vector{Any}, preserve_uses, use.idx), newval)
end
else
@assert false "sroa_mutables!: unexpected use"
Expand Down
65 changes: 30 additions & 35 deletions base/compiler/ssair/slot2ssa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ function iterated_dominance_frontier(cfg::CFG, liveness::BlockLiveness, domtree:
phiblocks
end

function rename_incoming_edge(old_edge, old_to, result_order, bb_rename)
function rename_incoming_edge(old_edge::Int, old_to::Int, result_order::Vector{Int}, bb_rename::Vector{Int})
new_edge_from = bb_rename[old_edge]
if old_edge == old_to - 1
# Could have been a crit edge break
Expand All @@ -341,7 +341,7 @@ function rename_incoming_edge(old_edge, old_to, result_order, bb_rename)
new_edge_from
end

function rename_outgoing_edge(old_to, old_from, result_order, bb_rename)
function rename_outgoing_edge(old_to::Int, old_from::Int, result_order::Vector{Int}, bb_rename::Vector{Int})
new_edge_to = bb_rename[old_to]
if old_from == old_to - 1
# Could have been a crit edge break
Expand All @@ -352,12 +352,12 @@ function rename_outgoing_edge(old_to, old_from, result_order, bb_rename)
new_edge_to
end

function rename_phinode_edges(node, bb, result_order, bb_rename)
function rename_phinode_edges(node::PhiNode, bb::Int, result_order::Vector{Int}, bb_rename::Vector{Int})
new_values = Any[]
new_edges = Int32[]
for (idx, edge) in pairs(node.edges)
edge = Int(edge)
(edge == 0 || haskey(bb_rename, edge)) || continue
(edge == 0 || bb_rename[edge] != 0) || continue
new_edge_from = edge == 0 ? 0 : rename_incoming_edge(edge, bb, result_order, bb_rename)
push!(new_edges, new_edge_from)
if isassigned(node.values, idx)
Expand All @@ -380,47 +380,42 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
# First compute the new order of basic blocks
result_order = Int[]
stack = Int[]
bb_rename = zeros(Int, length(ir.cfg.blocks))
node = 1
ncritbreaks = 0
nnewfallthroughs = 0
while node !== -1
push!(result_order, node)
bb_rename[node] = length(result_order)
cs = domtree.nodes[node].children
terminator = ir.stmts[last(ir.cfg.blocks[node].stmts)][:inst]
iscondbr = isa(terminator, GotoIfNot)
let old_node = node + 1
if length(cs) >= 1
# Adding the nodes in reverse sorted order attempts to retain
# the original source order of the nodes as much as possible.
# This is not required for correctness, but is easier on the humans
if old_node in cs
# Schedule the fall through node first,
# so we can retain the fall through
append!(stack, reverse(sort(filter(x -> (x != old_node), cs))))
node = node + 1
else
append!(stack, reverse(sort(cs)))
node = pop!(stack)
end
next_node = node + 1
node = -1
# Adding the nodes in reverse sorted order attempts to retain
# the original source order of the nodes as much as possible.
# This is not required for correctness, but is easier on the humans
for child in Iterators.Reverse(cs)
if child == next_node
# Schedule the fall through node first,
# so we can retain the fall through
node = next_node
else
if isempty(stack)
node = -1
else
node = pop!(stack)
end
push!(stack, child)
end
if node != old_node && !isa(terminator, Union{GotoNode, ReturnNode})
if isa(terminator, GotoIfNot)
# Need to break the critical edge
ncritbreaks += 1
push!(result_order, 0)
else
nnewfallthroughs += 1
end
end
if node == -1 && !isempty(stack)
node = pop!(stack)
end
if node != next_node && !isa(terminator, Union{GotoNode, ReturnNode})
if isa(terminator, GotoIfNot)
# Need to break the critical edge
ncritbreaks += 1
push!(result_order, 0)
else
nnewfallthroughs += 1
end
end
end
bb_rename = IdDict{Int,Int}(i=>x for (x, i) in pairs(result_order) if i !== 0)
new_bbs = Vector{BasicBlock}(undef, length(result_order))
nstmts = 0
for i in result_order
Expand Down Expand Up @@ -496,8 +491,8 @@ function domsort_ssa!(ir::IRCode, domtree::DomTree)
bb_start_off += length(inst_range)
local new_preds, new_succs
let bb = bb, bb_rename = bb_rename, result_order = result_order
new_preds = Int[rename_incoming_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].preds if haskey(bb_rename, i)]
new_succs = Int[rename_outgoing_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].succs if haskey(bb_rename, i)]
new_preds = Int[i == 0 ? 0 : rename_incoming_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].preds]
new_succs = Int[ rename_outgoing_edge(i, bb, result_order, bb_rename) for i in ir.cfg.blocks[bb].succs]
end
new_bbs[new_bb] = BasicBlock(inst_range, new_preds, new_succs)
end
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ function getfield_nothrow(@nospecialize(s00), @nospecialize(name), boundscheck::
elseif isa(s, DataType)
# Can't say anything about abstract types
isabstracttype(s) && return false
s.name.atomicfields == C_NULL || return false # TODO: currently we're only testing for ordering == :not_atomic
s.name.atomicfields == C_NULL || return false # TODO: currently we're only testing for ordering === :not_atomic
# If all fields are always initialized, and bounds check is disabled, we can assume
# we don't throw
if !boundscheck && s.name.n_uninitialized == 0
Expand Down Expand Up @@ -1020,7 +1020,7 @@ function setfield!_nothrow(s00, name, v)
# Can't say anything about abstract types
isabstracttype(s) && return false
ismutabletype(s) || return false
s.name.atomicfields == C_NULL || return false # TODO: currently we're only testing for ordering == :not_atomic
s.name.atomicfields == C_NULL || return false # TODO: currently we're only testing for ordering === :not_atomic
isa(name, Const) || return false
field = try_compute_fieldidx(s, name.val)
field === nothing && return false
Expand Down
2 changes: 1 addition & 1 deletion base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ macro assume_effects(args...)
end
ex = args[end]
isa(ex, Expr) || throw(ArgumentError("Bad expression `$ex` in `@assume_effects [settings] ex`"))
if ex.head === :macrocall && ex.args[1] == Symbol("@ccall")
if ex.head === :macrocall && ex.args[1] === Symbol("@ccall")
ex.args[1] = GlobalRef(Base, Symbol("@ccall_effects"))
insert!(ex.args, 3, Core.Compiler.encode_effects_override(Core.Compiler.EffectsOverride(
consistent, effect_free, nothrow, terminates_globally, terminates_locally, notaskstate
Expand Down
Loading

0 comments on commit 74fe80d

Please sign in to comment.