Skip to content

Commit 3b53f54

Browse files
authored
codegen: restructure, remove recursion (#25984)
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
1 parent ddf904c commit 3b53f54

33 files changed

+2606
-2338
lines changed

base/compiler/typeinfer.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ end
8484
function cache_result(result::InferenceResult, min_valid::UInt, max_valid::UInt)
8585
def = result.linfo.def
8686
toplevel = !isa(result.linfo.def, Method)
87-
if toplevel
88-
min_valid = UInt(0)
89-
max_valid = UInt(0)
90-
end
9187

9288
# check if the existing linfo metadata is also sufficient to describe the current inference result
9389
# to decide if it is worth caching this
@@ -546,7 +542,7 @@ function typeinf_ext(mi::MethodInstance, params::Params)
546542
tree.pure = true
547543
tree.inlineable = true
548544
tree.parent = mi
549-
tree.rettype = typeof(code.rettype_const)
545+
tree.rettype = Core.Typeof(code.rettype_const)
550546
tree.min_world = code.min_world
551547
tree.max_world = code.max_world
552548
return tree

base/options.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct JLOptions
3636
bindto::Ptr{UInt8}
3737
outputbc::Ptr{UInt8}
3838
outputunoptbc::Ptr{UInt8}
39-
outputjitbc::Ptr{UInt8}
4039
outputo::Ptr{UInt8}
4140
outputji::Ptr{UInt8}
4241
output_code_coverage::Ptr{UInt8}

base/reflection.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,6 @@ default_debug_info_kind() = unsafe_load(cglobal(:jl_default_debug_info_kind, Cin
965965

966966
# this type mirrors jl_cgparams_t (documented in julia.h)
967967
struct CodegenParams
968-
cached::Cint
969-
970968
track_allocations::Cint
971969
code_coverage::Cint
972970
static_alloc::Cint
@@ -980,18 +978,18 @@ struct CodegenParams
980978
emit_function::Any
981979
emitted_function::Any
982980

983-
CodegenParams(;cached::Bool=true,
984-
track_allocations::Bool=true, code_coverage::Bool=true,
981+
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
985982
static_alloc::Bool=true, prefer_specsig::Bool=false,
986983
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
987984
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
988-
emit_function=nothing, emitted_function=nothing) =
989-
new(Cint(cached),
985+
emit_function=nothing, emitted_function=nothing)
986+
return new(
990987
Cint(track_allocations), Cint(code_coverage),
991988
Cint(static_alloc), Cint(prefer_specsig),
992989
Cint(gnu_pubnames), debug_info_kind,
993990
module_setup, module_activation, raise_exception,
994991
emit_function, emitted_function)
992+
end
995993
end
996994

997995
const SLOT_USED = 0x8

contrib/generate_precompile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function generate_precompile_statements()
175175
if have_repl
176176
# Seems like a reasonable number right now, adjust as needed
177177
# comment out if debugging script
178-
@assert n_succeeded > 3500
178+
@assert n_succeeded > 1500
179179
end
180180

181181
print(" $(length(statements)) generated in ")

doc/src/devdocs/llvm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ using:
9797
fun, T = +, Tuple{Int,Int} # Substitute your function of interest here
9898
optimize = false
9999
open("plus.ll", "w") do file
100-
println(file, InteractiveUtils._dump_function(fun, T, false, false, false, true, :att, optimize))
100+
println(file, InteractiveUtils._dump_function(fun, T, false, false, false, true, :att, optimize, :default))
101101
end
102102
```
103103
These files can be processed the same way as the unoptimized sysimg IR shown

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LLVMLINK :=
5252

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

220220
# additional dependency links
221221
$(BUILDDIR)/anticodegen.o $(BUILDDIR)/anticodegen.dbg.obj: $(SRCDIR)/intrinsics.h
222+
$(BUILDDIR)/aotcompile.o $(BUILDDIR)/aotcompile.dbg.obj: $(SRCDIR)/jitlayers.h $(SRCDIR)/codegen_shared.h
222223
$(BUILDDIR)/ast.o $(BUILDDIR)/ast.dbg.obj: $(BUILDDIR)/julia_flisp.boot.inc $(SRCDIR)/flisp/*.h
223224
$(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/iddict.c $(SRCDIR)/builtin_proto.h
224225
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,\

src/abi_ppc64le.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ Type *preferred_llvm_type(jl_datatype_t *dt, bool isret) const override
133133
else {
134134
jl_datatype_t *vecty = (jl_datatype_t*)jl_field_type(ty0, 0);
135135
assert(jl_is_datatype(vecty) && vecty->name == jl_vecelement_typename);
136-
jl_value_t *elemty = jl_tparam0(vecty);
137-
assert(jl_is_primitivetype(elemty));
138-
139-
Type *ety = julia_type_to_llvm(elemty);
136+
Type *ety = bitstype_to_llvm(jl_tparam0(vecty));
140137
Type *vty = VectorType::get(ety, jl_datatype_nfields(ty0));
141138
return ArrayType::get(vty, hfa);
142139
}

src/anticodegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ void jl_write_coverage_data(void) UNAVAILABLE
1717
JL_DLLEXPORT void jl_clear_malloc_data(void) UNAVAILABLE
1818
JL_DLLEXPORT void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE
1919
JL_DLLEXPORT void *jl_function_ptr(jl_function_t *f, jl_value_t *rt, jl_value_t *argt) UNAVAILABLE
20-
JL_DLLEXPORT const jl_value_t *jl_dump_function_asm(void *f, int raw_mc, const char* asm_variant, const char *debuginfo) UNAVAILABLE
20+
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
2121
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
22+
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
2223

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

0 commit comments

Comments
 (0)