Skip to content

Commit

Permalink
codegen: restructure, remove recursion (#25984)
Browse files Browse the repository at this point in the history
also provides support for using a different code_native format,
as a fallback, later we'll want to make this more configurable

there are now several primary interfaces to native code:
 - codegen: mostly internal, support for translating IR to LLVM
 - jitlayers: manages runtime codegen results and executable memory
 - aotcompile: support for managing external code output
 - disasm: pretty-printer for code objects
 - debuginfo: tracking for unwind info

also removes the global type caches and
move all codegen pass handling to aotcompile.cpp
  • Loading branch information
vtjnash authored and KristofferC committed Apr 11, 2020
1 parent d6d8370 commit 8a6527d
Show file tree
Hide file tree
Showing 33 changed files with 2,606 additions and 2,338 deletions.
6 changes: 1 addition & 5 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ end
function cache_result(result::InferenceResult, min_valid::UInt, max_valid::UInt)
def = result.linfo.def
toplevel = !isa(result.linfo.def, Method)
if toplevel
min_valid = UInt(0)
max_valid = UInt(0)
end

# check if the existing linfo metadata is also sufficient to describe the current inference result
# to decide if it is worth caching this
Expand Down Expand Up @@ -546,7 +542,7 @@ function typeinf_ext(mi::MethodInstance, params::Params)
tree.pure = true
tree.inlineable = true
tree.parent = mi
tree.rettype = typeof(code.rettype_const)
tree.rettype = Core.Typeof(code.rettype_const)
tree.min_world = code.min_world
tree.max_world = code.max_world
return tree
Expand Down
1 change: 0 additions & 1 deletion base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ struct JLOptions
bindto::Ptr{UInt8}
outputbc::Ptr{UInt8}
outputunoptbc::Ptr{UInt8}
outputjitbc::Ptr{UInt8}
outputo::Ptr{UInt8}
outputji::Ptr{UInt8}
output_code_coverage::Ptr{UInt8}
Expand Down
10 changes: 4 additions & 6 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,6 @@ default_debug_info_kind() = unsafe_load(cglobal(:jl_default_debug_info_kind, Cin

# this type mirrors jl_cgparams_t (documented in julia.h)
struct CodegenParams
cached::Cint

track_allocations::Cint
code_coverage::Cint
static_alloc::Cint
Expand All @@ -980,18 +978,18 @@ struct CodegenParams
emit_function::Any
emitted_function::Any

CodegenParams(;cached::Bool=true,
track_allocations::Bool=true, code_coverage::Bool=true,
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
static_alloc::Bool=true, prefer_specsig::Bool=false,
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
emit_function=nothing, emitted_function=nothing) =
new(Cint(cached),
emit_function=nothing, emitted_function=nothing)
return new(
Cint(track_allocations), Cint(code_coverage),
Cint(static_alloc), Cint(prefer_specsig),
Cint(gnu_pubnames), debug_info_kind,
module_setup, module_activation, raise_exception,
emit_function, emitted_function)
end
end

const SLOT_USED = 0x8
Expand Down
2 changes: 1 addition & 1 deletion contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function generate_precompile_statements()
if have_repl
# Seems like a reasonable number right now, adjust as needed
# comment out if debugging script
@assert n_succeeded > 3500
@assert n_succeeded > 1500
end

print(" $(length(statements)) generated in ")
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/llvm.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ using:
fun, T = +, Tuple{Int,Int} # Substitute your function of interest here
optimize = false
open("plus.ll", "w") do file
println(file, InteractiveUtils._dump_function(fun, T, false, false, false, true, :att, optimize))
println(file, InteractiveUtils._dump_function(fun, T, false, false, false, true, :att, optimize, :default))
end
```
These files can be processed the same way as the unoptimized sysimg IR shown
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ LLVMLINK :=

ifeq ($(JULIACODEGEN),LLVM)
SRCS += codegen llvm-ptls
RUNTIME_SRCS += jitlayers debuginfo disasm llvm-simdloop llvm-muladd \
RUNTIME_SRCS += jitlayers aotcompile debuginfo disasm llvm-simdloop llvm-muladd \
llvm-final-gc-lowering llvm-pass-helpers llvm-late-gc-lowering \
llvm-lower-handlers llvm-gc-invariant-verifier llvm-propagate-addrspaces \
llvm-multiversioning llvm-alloc-opt cgmemmgr llvm-api
Expand Down Expand Up @@ -219,6 +219,7 @@ $(BUILDDIR)/julia_flisp.boot: $(addprefix $(SRCDIR)/,jlfrontend.scm flisp/aliase

# additional dependency links
$(BUILDDIR)/anticodegen.o $(BUILDDIR)/anticodegen.dbg.obj: $(SRCDIR)/intrinsics.h
$(BUILDDIR)/aotcompile.o $(BUILDDIR)/aotcompile.dbg.obj: $(SRCDIR)/jitlayers.h $(SRCDIR)/codegen_shared.h
$(BUILDDIR)/ast.o $(BUILDDIR)/ast.dbg.obj: $(BUILDDIR)/julia_flisp.boot.inc $(SRCDIR)/flisp/*.h
$(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/iddict.c $(SRCDIR)/builtin_proto.h
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,\
Expand Down
5 changes: 1 addition & 4 deletions src/abi_ppc64le.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret) const override
else {
jl_datatype_t *vecty = (jl_datatype_t*)jl_field_type(ty0, 0);
assert(jl_is_datatype(vecty) && vecty->name == jl_vecelement_typename);
jl_value_t *elemty = jl_tparam0(vecty);
assert(jl_is_primitivetype(elemty));

Type *ety = julia_type_to_llvm(elemty);
Type *ety = bitstype_to_llvm(jl_tparam0(vecty));
Type *vty = VectorType::get(ety, jl_datatype_nfields(ty0));
return ArrayType::get(vty, hfa);
}
Expand Down
3 changes: 2 additions & 1 deletion src/anticodegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ void jl_write_coverage_data(void) UNAVAILABLE
JL_DLLEXPORT void jl_clear_malloc_data(void) UNAVAILABLE
JL_DLLEXPORT void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
JL_DLLEXPORT void *jl_function_ptr(jl_function_t *f, jl_value_t *rt, jl_value_t *argt) UNAVAILABLE
JL_DLLEXPORT const jl_value_t *jl_dump_function_asm(void *f, int raw_mc, const char* asm_variant, const char *debuginfo) UNAVAILABLE
JL_DLLEXPORT jl_value_t *jl_dump_method_asm(jl_method_instance_t *linfo, size_t world, int raw_mc, char getwrapper, const char* asm_variant, const char *debuginfo) UNAVAILABLE
JL_DLLEXPORT const jl_value_t *jl_dump_function_ir(void *f, uint8_t strip_ir_metadata, uint8_t dump_module, const char *debuginfo) UNAVAILABLE
JL_DLLEXPORT void *jl_get_llvmf_defn(jl_method_instance_t *linfo, size_t world, char getwrapper, char optimize, const jl_cgparams_t params) UNAVAILABLE

JL_DLLEXPORT void *jl_LLVMCreateDisasm(const char *TripleName, void *DisInfo, int TagType, void *GetOpInfo, void *SymbolLookUp) UNAVAILABLE
JL_DLLEXPORT size_t jl_LLVMDisasmInstruction(void *DC, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize) UNAVAILABLE
Expand Down
Loading

0 comments on commit 8a6527d

Please sign in to comment.