Skip to content

Commit 6f0d77f

Browse files
committed
Clean-ups.
1 parent a02c717 commit 6f0d77f

3 files changed

Lines changed: 42 additions & 43 deletions

File tree

src/interface.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,6 @@ the check-and-compile sequence (all back-ends already do, e.g. `mtlfunction_lock
429429
"""
430430
function cached_results end
431431

432-
# Relocation types and the backend lowering hook live in relocation.jl.
433-
#
434-
# Job results attached to CodeInstances are serialized into package images. Store only
435-
# session-portable data there. Generated code is portable iff `supports_relocatable_ir()`
436-
# and the backend preserves relocations with patchable- or imported-symbol lowering. Backends
437-
# using baked lowering must keep generated code in a session-local cache or recompile it.
438432
@static if HAS_INTEGRATED_CACHE
439433

440434
"""

src/mcgen.jl

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
11
# machine code generation
22

3-
# GlobalOpt/DCE cleanup, run before slot collection and again after lowering.
4-
function run_cleanup_pipeline!(@nospecialize(job::CompilerJob), mod::LLVM.Module)
5-
@dispose pb=NewPMPassBuilder() begin
6-
add!(pb, RecomputeGlobalsAAPass())
7-
add!(pb, GlobalOptPass())
8-
add!(pb, GlobalDCEPass())
9-
add!(pb, StripDeadPrototypesPass())
10-
run!(pb, mod, llvm_machine(job.config.target))
11-
end
12-
return
13-
end
14-
15-
# Final preparations for the module to be compiled to machine code. These passes should not
16-
# be run when e.g. compiling to write to disk.
3+
# Finalize the module for backend emission by collecting and lowering all live relocations.
174
function prepare_execution!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
185
relocs::Relocations=Relocations())
196
# Clean up first so only live relocations get lowered.
20-
run_cleanup_pipeline!(job, mod)
7+
function cleanup()
8+
@dispose pb=NewPMPassBuilder() begin
9+
add!(pb, RecomputeGlobalsAAPass())
10+
add!(pb, GlobalOptPass())
11+
add!(pb, GlobalDCEPass())
12+
add!(pb, StripDeadPrototypesPass())
13+
run!(pb, mod, llvm_machine(job.config.target))
14+
end
15+
end
16+
cleanup()
2117
prune_dead_relocations!(mod, relocs)
2218

2319
collect_cglobal_relocations!(mod, relocs)
2420
lower_relocations!(job, mod, relocs)
2521

26-
# Fold constants exposed by eager lowering, and discard slots made dead by either
27-
# lowering strategy.
28-
run_cleanup_pipeline!(job, mod)
22+
# Fold constants exposed by eager lowering, and discard slots made dead by
23+
# either lowering strategy.
24+
cleanup()
2925
prune_dead_relocations!(mod, relocs)
3026

3127
has_unresolved_cglobal_loads(mod, relocs) &&

src/relocation.jl

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
# Relocation model
22
#
33
# A relocation is a site => target pair. Targets are Julia object identities
4-
# (`JuliaValueRef`, like codegen's identity-keyed `global_targets`) or named libjulia
5-
# globals (`CGlobalRef`, like JuliaVariables). Every site names a word at a byte offset in a
6-
# global. Dedicated sites use offset zero in a word-sized declaration (like
7-
# `jl_sysimg_gvars`); other sites are inside defined globals (like
8-
# `gctags_list`/`relocs_list`). Declarations can be baked, patched, or imported; sites in
9-
# definitions can only be baked or patched.
4+
# (`JuliaValueRef`, like codegen's identity-keyed `global_targets`) or named
5+
# libjulia globals (`CGlobalRef`, like JuliaVariables). Every site names a word
6+
# at a byte offset in a global. Dedicated sites use offset zero in a word-sized
7+
# declaration (like `jl_sysimg_gvars`); other sites are inside defined globals
8+
# (like `gctags_list`/`relocs_list`). Declarations can be baked, patched, or
9+
# imported; sites in definitions can only be baked or patched.
1010
#
1111
# produce ──▶ merge (on link) ──▶ prune (after DCE) ──▶ lower (at emit_asm)
1212
#
13-
# Lowering strategy Loader contract Julia analog
14-
# `bake_relocations!` none; current-session words baked JIT address folding
15-
# `emit_patchable_relocations!` patch named globals after load sysimage gvars
13+
# Lowering strategy Loader contract Julia analog
14+
# ----------------- --------------- ------------
15+
# `bake_relocations!` none; current-session words baked JIT address folding
16+
# `emit_patchable_relocations!` patch named globals after load sysimage gvars
1617
#
1718
# The producers are `collect_julia_value_relocations!` during IR generation and
18-
# `collect_cglobal_relocations!` immediately before backend lowering. Names are globally
19-
# unique and assigned once, so linking can merge IR and metadata without renaming.
19+
# `collect_cglobal_relocations!` immediately before backend lowering. Names are
20+
# globally unique and assigned once, so linking can merge IR and metadata
21+
# without renaming.
2022
#
21-
# Generated code is portable only when `supports_relocatable_ir()` and the backend preserves
22-
# these relocations for its loader. The default lowering bakes current-session values.
23+
# Generated code is portable only when `supports_relocatable_ir()` and the
24+
# backend preserves these relocations for its loader. The default lowering bakes
25+
# current-session values.
2326

24-
## Targets
27+
28+
## targets
2529

2630
"""
2731
JuliaValueRef(value)
@@ -79,7 +83,8 @@ function resolve_relocation_target(target::CGlobalRef)
7983
return unsafe_load(address)
8084
end
8185

82-
## The table
86+
87+
## the table
8388

8489
"""
8590
RelocationSite(name, offset)
@@ -172,7 +177,8 @@ function foreach_relocation(f, mod::LLVM.Module, relocs::Relocations)
172177
return
173178
end
174179

175-
## Producers
180+
181+
## producers
176182

177183
function collect_julia_value_relocations!(mod::LLVM.Module,
178184
gv_to_value::Dict{String, Ptr{Cvoid}})
@@ -364,7 +370,8 @@ function has_unresolved_cglobal_loads(mod::LLVM.Module, relocs::Relocations)
364370
return false
365371
end
366372

367-
## Bookkeeping
373+
374+
## bookkeeping
368375

369376
function link_relocatable!(dest_mod::LLVM.Module, dest_relocs::Relocations,
370377
src_mod::LLVM.Module, src_relocs::Relocations;
@@ -422,7 +429,8 @@ function prune_dead_relocations!(mod::LLVM.Module, relocs::Relocations)
422429
return
423430
end
424431

425-
## Lowering
432+
433+
## lowering
426434

427435
"""
428436
lower_relocations!(job, mod, relocs)
@@ -487,7 +495,8 @@ function emit_patchable_relocations!(mod::LLVM.Module, relocs::Relocations)
487495
return
488496
end
489497

490-
## Introspection
498+
499+
## introspection
491500

492501
function referenced_object(value, relocs::Relocations)
493502
# This is best-effort: optimized shapes fall back to the unknown-binding error path.

0 commit comments

Comments
 (0)