Skip to content

Commit 050b860

Browse files
committed
use the stdlib version of Compiler instead of Core.Compiler
This allows `Compiler.CFG` created from tools like JET to be passed directly to LCU then.
1 parent 9c109e9 commit 050b860

File tree

7 files changed

+26
-23
lines changed

7 files changed

+26
-23
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name = "LoweredCodeUtils"
22
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
3-
version = "3.3.0"
3+
version = "3.4.0"
44
authors = ["Tim Holy <[email protected]>"]
55

66
[deps]
7+
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
78
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
89

910
[compat]
11+
Compiler = "0.1"
1012
JuliaInterpreter = "0.10"
1113
julia = "1.10"
1214

src/codeedges.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ function print_with_code(preprint, postprint, io::IO, src::CodeInfo)
106106
used = BitSet()
107107
cfg = compute_basic_blocks(src.code)
108108
for stmt in src.code
109-
Core.Compiler.scan_ssa_use!(push!, used, stmt)
109+
CC.scan_ssa_use!(push!, used, stmt)
110110
end
111111
@static if isdefined(Base, :__has_internal_change) && Base.__has_internal_change(v"1.12-alpha", :printcodeinfocalls)
112112
sptypes = let parent = src.parent
113113
parent isa MethodInstance ?
114-
Core.Compiler.sptypes_from_meth_instance(parent) :
115-
Core.Compiler.EMPTY_SPTYPES
114+
CC.sptypes_from_meth_instance(parent) :
115+
CC.EMPTY_SPTYPES
116116
end
117117
end
118118
line_info_preprinter = Base.IRShow.lineinfo_disabled
@@ -763,8 +763,6 @@ end
763763

764764
## Add control-flow
765765

766-
using Core: CodeInfo
767-
using Core.Compiler: CFG, BasicBlock, compute_basic_blocks
768766

769767
# The goal of this function is to request concretization of the minimal necessary control
770768
# flow to evaluate statements whose concretization have already been requested.

src/domtree.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
# A few items needed to be added:
77

8-
using Core.Compiler: BasicBlock
98
import Base: length, copy, copy!
109

1110
# END additions

src/packagedef.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ using Core.IR: CodeInfo, GotoIfNot, GotoNode, IR, MethodInstance, ReturnNode
55
@static if isdefined(Core.IR, :EnterNode)
66
using Core.IR: EnterNode
77
end
8-
using Core.Compiler: construct_domtree, construct_postdomtree, nearest_common_dominator,
9-
postdominates
8+
using Compiler: Compiler as CC
9+
using .CC:
10+
BasicBlock, CFG,
11+
compute_basic_blocks, construct_domtree, construct_postdomtree,
12+
nearest_common_dominator, postdominates
1013
using Base.Meta: isexpr
1114

12-
const SSAValues = Union{Core.Compiler.SSAValue, JuliaInterpreter.SSAValue}
15+
const SSAValues = Union{Core.IR.SSAValue, JuliaInterpreter.SSAValue}
1316

1417
const trackedheads = (:method,) # Revise uses this (for now), don't delete; also update test/hastrackedexpr if this list gets expanded
1518
const structdecls = (:_structtype, :_abstracttype, :_primitivetype)

src/utils.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const AnySSAValue = Union{Core.Compiler.SSAValue,JuliaInterpreter.SSAValue}
2-
const AnySlotNumber = Union{Core.Compiler.SlotNumber,JuliaInterpreter.SlotNumber}
1+
const AnySSAValue = Union{Core.IR.SSAValue,JuliaInterpreter.SSAValue}
2+
const AnySlotNumber = Union{Core.IR.SlotNumber,JuliaInterpreter.SlotNumber}
33

44
# to circumvent https://github.com/JuliaLang/julia/issues/37342, we inline these `isa`
55
# condition checks at surface AST level
66
# https://github.com/JuliaLang/julia/pull/38905 will get rid of the need of these hacks
77
macro isssa(stmt)
8-
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SSAValue))) ||
8+
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.IR, :SSAValue))) ||
99
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SSAValue))))
1010
end
1111
macro issslotnum(stmt)
12-
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.Compiler, :SlotNumber))) ||
12+
:($(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(Core.IR, :SlotNumber))) ||
1313
$(GlobalRef(Core, :isa))($(esc(stmt)), $(GlobalRef(JuliaInterpreter, :SlotNumber))))
1414
end
1515

@@ -211,8 +211,8 @@ end
211211

212212
showempty(list) = isempty(list) ? '' : list
213213

214-
# Smooth the transition between Core.Compiler and Base
215-
rng(bb::Core.Compiler.BasicBlock) = (r = bb.stmts; return Core.Compiler.first(r):Core.Compiler.last(r))
214+
# Smooth the transition between CC and Base (not requried for v1.12 and above)
215+
rng(bb::BasicBlock) = (r = bb.stmts; return CC.first(r):CC.last(r))
216216

217217
function pushall!(dest, src)
218218
for item in src
@@ -224,7 +224,7 @@ end
224224
# computes strongly connected components of a control flow graph `cfg`
225225
# NOTE adapted from https://github.com/JuliaGraphs/Graphs.jl/blob/5878e7be4d68b2a1c179d1367aea670db115ebb5/src/connectivity.jl#L265-L357
226226
# since to load an entire Graphs.jl is a bit cost-ineffective in terms of a trade-off of latency vs. maintainability
227-
function strongly_connected_components(g::Core.Compiler.CFG)
227+
function strongly_connected_components(g::CFG)
228228
T = Int
229229
zero_t = zero(T)
230230
one_t = one(T)
@@ -322,12 +322,12 @@ function strongly_connected_components(g::Core.Compiler.CFG)
322322
end
323323

324324
# compatibility with Graphs.jl interfaces
325-
@inline nv(cfg::Core.Compiler.CFG) = length(cfg.blocks)
326-
@inline vertices(cfg::Core.Compiler.CFG) = 1:nv(cfg)
327-
@inline outneighbors(cfg::Core.Compiler.CFG, v) = cfg.blocks[v].succs
325+
@inline nv(cfg::CFG) = length(cfg.blocks)
326+
@inline vertices(cfg::CFG) = 1:nv(cfg)
327+
@inline outneighbors(cfg::CFG, v) = cfg.blocks[v].succs
328328

329329
# using Graphs: SimpleDiGraph, add_edge!, strongly_connected_components as oracle_scc
330-
# function cfg_to_sdg(cfg::Core.Compiler.CFG)
330+
# function cfg_to_sdg(cfg::CFG)
331331
# g = SimpleDiGraph(length(cfg.blocks))
332332
# for (v, block) in enumerate(cfg.blocks)
333333
# for succ in block.succs

test/codeedges.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module codeedges
22

33
using LoweredCodeUtils
44
using LoweredCodeUtils.JuliaInterpreter
5+
using LoweredCodeUtils: CC
56
using LoweredCodeUtils: callee_matches, istypedef, exclude_named_typedefs
67
using JuliaInterpreter: is_global_ref, is_quotenode
78
using Test
@@ -324,7 +325,7 @@ module ModSelective end
324325
src = frame.framecode.src
325326
edges = CodeEdges(ModEval, src)
326327
isrequired = minimal_evaluation(@nospecialize(stmt)->(LoweredCodeUtils.ismethod3(stmt),false), src, edges; norequire=exclude_named_typedefs(src, edges)) # initially mark only the constructor
327-
bbs = Core.Compiler.compute_basic_blocks(src.code)
328+
bbs = CC.compute_basic_blocks(src.code)
328329
for (iblock, block) in enumerate(bbs.blocks)
329330
r = LoweredCodeUtils.rng(block)
330331
if iblock == length(bbs.blocks)

test/signatures.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ bodymethtest5(x, y=Dict(1=>2)) = 5
319319
methoddefs!(signatures, frame; define=false)
320320
@test !isempty(signatures)
321321

322-
# Inner methods in structs. Comes up in, e.g., Core.Compiler.Params.
322+
# Inner methods in structs. Comes up in, e.g., CC.Params.
323323
# The body of CustomMS is an SSAValue.
324324
ex = quote
325325
struct MyStructWithMeth

0 commit comments

Comments
 (0)