Skip to content

Commit

Permalink
StmtInfo WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Jun 29, 2020
1 parent 438ed91 commit f192ead
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 173 deletions.
344 changes: 182 additions & 162 deletions base/compiler/abstractinterpretation.jl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ include("compiler/typeutils.jl")
include("compiler/typelimits.jl")
include("compiler/typelattice.jl")
include("compiler/tfuncs.jl")
include("compiler/stmtinfo.jl")

include("compiler/abstractinterpretation.jl")
include("compiler/typeinfer.jl")
Expand Down
1 change: 1 addition & 0 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ mutable struct InferenceState

nssavalues = src.ssavaluetypes::Int
src.ssavaluetypes = Any[ NOT_FOUND for i = 1:nssavalues ]
src.stmtinfo = Any[ nothing for i = 1:length(code) ]

n = length(code)
s_edges = Any[ nothing for i = 1:n ]
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 @@ -101,7 +101,7 @@ function convert_to_ircode(ci::CodeInfo, code::Vector{Any}, coverage::Bool, narg
strip_trailing_junk!(ci, code, flags)
cfg = compute_basic_blocks(code)
types = Any[]
stmts = InstructionStream(code, types, ci.codelocs, flags)
stmts = InstructionStream(code, types, ci.stmtinfo, ci.codelocs, flags)
ir = IRCode(stmts, cfg, collect(LineInfoNode, ci.linetable), sv.slottypes, meta, sv.sptypes)
return ir
end
Expand Down
10 changes: 8 additions & 2 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,18 @@ end
struct InstructionStream
inst::Vector{Any}
type::Vector{Any}
info::Vector{Any}
line::Vector{Int32}
flag::Vector{UInt8}
end
function InstructionStream(len::Int)
insts = Array{Any}(undef, len)
types = Array{Any}(undef, len)
info = Array{Any}(undef, len)
fill!(info, nothing)
lines = fill(Int32(0), len)
flags = fill(0x00, len)
return InstructionStream(insts, types, lines, flags)
return InstructionStream(insts, types, info, lines, flags)
end
InstructionStream() = InstructionStream(0)
length(is::InstructionStream) = length(is.inst)
Expand All @@ -177,6 +180,7 @@ function add!(is::InstructionStream)
ninst = length(is) + 1
resize!(is.inst, ninst)
resize!(is.type, ninst)
resize!(is.info, ninst)
resize!(is.line, ninst)
resize!(is.flag, ninst)
return ninst
Expand All @@ -192,16 +196,17 @@ function resize!(stmts::InstructionStream, len)
old_length = length(stmts)
resize!(stmts.inst, len)
resize!(stmts.type, len)
resize!(stmts.info, len)
resize!(stmts.line, len)
resize!(stmts.flag, len)
for i in (old_length + 1):len
stmts.line[i] = 0
stmts.flag[i] = 0x00
stmts.info[i] = nothing
end
return stmts
end


struct Instruction
data::InstructionStream
idx::Int
Expand All @@ -221,6 +226,7 @@ end
function setindex!(is::InstructionStream, newval::Instruction, idx::Int)
is.inst[idx] = newval[:inst]
is.type[idx] = newval[:type]
#is.info[idx] = newval[:info]
is.line[idx] = newval[:line]
is.flag[idx] = newval[:flag]
return is
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function inflate_ir(ci::CodeInfo, sptypes::Vector{Any}, argtypes::Vector{Any})
ssavaluetypes = ci.ssavaluetypes
nstmts = length(code)
ssavaluetypes = ci.ssavaluetypes isa Vector{Any} ? copy(ci.ssavaluetypes) : Any[ Any for i = 1:(ci.ssavaluetypes::Int) ]
stmts = InstructionStream(code, ssavaluetypes, copy(ci.codelocs), copy(ci.ssaflags))
stmts = InstructionStream(code, ssavaluetypes, copy(ci.stmtinfo), copy(ci.codelocs), copy(ci.ssaflags))
ir = IRCode(stmts, cfg, collect(LineInfoNode, ci.linetable), argtypes, Any[], sptypes)
return ir
end
Expand Down
7 changes: 7 additions & 0 deletions base/compiler/stmtinfo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct MethodMatchInfo
applicable::Vector{Any}
end

struct UnionSplitInfo
matches::Vector{MethodMatchInfo}
end
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, v
if contains_is(argtypes_vec, Union{})
return Const(Union{})
end
rt = abstract_call(interp, nothing, argtypes_vec, vtypes, sv, -1)
rt , _ = abstract_call(interp, nothing, argtypes_vec, vtypes, sv, -1)
if isa(rt, Const)
# output was computed to be constant
return Const(typeof(rt.val))
Expand Down
1 change: 1 addition & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6186,6 +6186,7 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
};
std::vector<DebugLineTable> linetable;
{
assert(jl_is_array(src->linetable));
size_t nlocs = jl_array_len(src->linetable);
std::map<std::tuple<StringRef, StringRef>, DISubprogram*> subprograms;
linetable.resize(nlocs + 1);
Expand Down
6 changes: 3 additions & 3 deletions src/ircode.c
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,13 @@ JL_DLLEXPORT jl_array_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code)
// by the various jl_ir_ accessors. Make sure to adjust those if you change
// the data layout.

for (i = 0; i < 6; i++) {
for (i = 0; i < 7; i++) {
int copy = 1;
if (i == 1) { // skip codelocs
assert(jl_field_offset(jl_code_info_type, i) == offsetof(jl_code_info_t, codelocs));
continue;
}
if (i == 4) { // don't copy contents of method_for_inference_limit_heuristics field
if (i == 5) { // don't copy contents of method_for_inference_limit_heuristics field
assert(jl_field_offset(jl_code_info_type, i) == offsetof(jl_code_info_t, method_for_inference_limit_heuristics));
copy = 0;
}
Expand Down Expand Up @@ -787,7 +787,7 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t
code->slotflags = jl_alloc_array_1d(jl_array_uint8_type, nslots);
ios_readall(s.s, (char*)jl_array_data(code->slotflags), nslots);

for (i = 0; i < 6; i++) {
for (i = 0; i < 7; i++) {
if (i == 1) // skip codelocs
continue;
assert(jl_field_isptr(jl_code_info_type, i));
Expand Down
8 changes: 5 additions & 3 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,11 +2232,12 @@ void jl_init_types(void) JL_GC_DISABLED
jl_code_info_type =
jl_new_datatype(jl_symbol("CodeInfo"), core,
jl_any_type, jl_emptysvec,
jl_perm_symsvec(18,
jl_perm_symsvec(19,
"code",
"codelocs",
"ssavaluetypes",
"ssaflags",
"stmtinfo",
"method_for_inference_limit_heuristics",
"linetable",
"slotnames",
Expand All @@ -2251,11 +2252,12 @@ void jl_init_types(void) JL_GC_DISABLED
"inlineable",
"propagate_inbounds",
"pure"),
jl_svec(18,
jl_svec(19,
jl_array_any_type,
jl_any_type,
jl_any_type,
jl_array_uint8_type,
jl_array_any_type,
jl_any_type,
jl_any_type,
jl_array_symbol_type,
Expand All @@ -2270,7 +2272,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_bool_type,
jl_bool_type,
jl_bool_type),
0, 1, 18);
0, 1, 19);

jl_method_type =
jl_new_datatype(jl_symbol("Method"), core,
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ typedef struct _jl_code_info_t {
// 4-6 = <unused>
// 7 = has out-of-band info
// miscellaneous data:
jl_array_t *stmtinfo; // side-channel information from inference to optimize
jl_value_t *method_for_inference_limit_heuristics; // optional method used during inference
jl_value_t *linetable; // Table of locations [TODO: make this volatile like slotnames]
jl_array_t *slotnames; // names of local variables
Expand Down
1 change: 1 addition & 0 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ JL_DLLEXPORT jl_code_info_t *jl_new_code_info_uninit(void)
src->codelocs = jl_nothing;
src->ssavaluetypes = NULL;
src->ssaflags = NULL;
src->stmtinfo = NULL;
src->method_for_inference_limit_heuristics = jl_nothing;
src->linetable = jl_nothing;
src->slotflags = NULL;
Expand Down

0 comments on commit f192ead

Please sign in to comment.