Skip to content
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

[new IR] line numbers #26782

Merged
merged 2 commits into from
Apr 11, 2018
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
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function optimize(me::InferenceState)
reindex_labels!(opt)
nargs = Int(opt.nargs) - 1
if def isa Method
topline = LineInfoNode(opt.mod, def.name, def.file, Int(def.line), Int(0))
topline = LineInfoNode(opt.mod, def.name, def.file, Int(def.line), 0)
else
topline = LineInfoNode(opt.mod, NullLineInfo.method, NullLineInfo.file, 0, 0)
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ function run_passes(ci::CodeInfo, nargs::Int, linetable::Vector{LineInfoNode}, s
@timeit "compact 2" ir = compact!(ir)
@timeit "type lift" ir = type_lift_pass!(ir)
@timeit "compact 3" ir = compact!(ir)
#@timeit "verify 3" verify_ir(ir)
#@timeit "verify 3" (verify_ir(ir); verify_linetable(linetable))
return ir
end
5 changes: 4 additions & 1 deletion base/compiler/ssair/inlining2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ function batch_inline!(todo, ir, domtree, linetable, sv)
inline_cfg = inline_ir.cfg
linetable_offset = length(linetable)
# Append the linetable of the inlined function to our line table
inlined_at = compact.result_lines[idx]
for entry in inline_linetable
push!(linetable, LineInfoNode(entry.mod, entry.method, entry.file, entry.line, compact.result_lines[idx]))
push!(linetable, LineInfoNode(entry.mod, entry.method, entry.file, entry.line, (entry.inlined_at > 0 ? entry.inlined_at + linetable_offset : inlined_at)))
end
# If the iterator already moved on to the next basic block,
# temorarily re-open in again.
Expand Down Expand Up @@ -261,6 +262,7 @@ function batch_inline!(todo, ir, domtree, linetable, sv)
end

ir = finish(compact)
return ir
end

function spec_lambda(@nospecialize(atype), sv::OptimizationState, @nospecialize(invoke_data))
Expand Down Expand Up @@ -313,6 +315,7 @@ function maybe_make_invoke!(ir, idx, @nospecialize(etype), atypes::Vector{Any},
ex.typ = etype
ex.args = argexprs
ir[SSAValue(idx)] = ex
nothing
end

function exprtype_func(@nospecialize(arg1), ir)
Expand Down
3 changes: 2 additions & 1 deletion base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ mutable struct IncrementalCompact
new_len = length(code.stmts) + length(code.new_nodes)
result = Array{Any}(undef, new_len)
result_types = Array{Any}(undef, new_len)
result_lines = Array{Int}(undef, new_len)
result_lines = fill(0, new_len)
used_ssas = fill(0, new_len)
ssa_rename = Any[SSAValue(i) for i = 1:new_len]
late_fixup = Vector{Int}()
Expand Down Expand Up @@ -546,6 +546,7 @@ function resize!(compact::IncrementalCompact, nnewnodes)
resize!(compact.result_lines, nnewnodes)
resize!(compact.used_ssas, nnewnodes)
compact.used_ssas[(old_length+1):nnewnodes] = 0
nothing
end

function finish_current_bb!(compact, old_result_idx=compact.result_idx)
Expand Down
17 changes: 17 additions & 0 deletions base/compiler/ssair/verify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function verify_ir(ir::IRCode)
# Verify statements
domtree = construct_domtree(ir.cfg)
for (bb, idx, stmt) in bbidxstmt(ir)
stmt === nothing && continue
if isa(stmt, PhiNode)
@assert length(stmt.edges) == length(stmt.values)
for i = 1:length(stmt.edges)
Expand Down Expand Up @@ -110,10 +111,26 @@ function verify_ir(ir::IRCode)
end
end
else
if isa(stmt, Expr) || isa(stmt, ReturnNode) # TODO: make sure everything has line info
if !(stmt isa ReturnNode && !isdefined(stmt, :val)) # not actually a return node, but an unreachable marker
if ir.lines[idx] <= 0
@verify_error "Missing line number information for statement $idx of $ir"
end
end
end
for op in userefs(stmt)
op = op[]
check_op(ir, domtree, op, bb, idx)
end
end
end
end

function verify_linetable(linetable::Vector{LineInfoNode})
for i in 1:length(linetable)
line = linetable[i]
if i <= line.inlined_at
@verify_error "Misordered linetable"
end
end
end
4 changes: 3 additions & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,10 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
}

CallInst *inst = ctx.builder.CreateCall(f, ArrayRef<Value*>(&argvals[0], nargt));
if (isString)
if (isString) {
f->addFnAttr(Attribute::AlwaysInline);
inst->setAttributes(f->getAttributes());
}

JL_GC_POP();

Expand Down
Loading