Skip to content

Commit aee2628

Browse files
authored
Reduce breakage (#404)
1 parent 38b4dd5 commit aee2628

File tree

12 files changed

+46
-32
lines changed

12 files changed

+46
-32
lines changed

examples/kernel.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function main()
2020
target = NativeCompilerTarget()
2121
params = TestCompilerParams()
2222
config = CompilerConfig(target, params)
23-
job = CompilerJob(config, source)
23+
job = CompilerJob(source, config)
2424

2525
println(GPUCompiler.compile(:asm, job)[1])
2626
end

src/cache.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ end
170170
ft::Type, tt::Type, world,
171171
compiler::Function, linker::Function)
172172
src = FunctionSpec(ft, tt, world)
173-
job = CompilerJob(cfg, src)
173+
job = CompilerJob(src, cfg)
174174

175175
asm = nothing
176176
# TODO: consider loading the assembly from an on-disk cache here

src/driver.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ const __llvm_initialized = Ref(false)
301301
# get a job in the appopriate world
302302
dyn_job = if dyn_val isa CompilerJob
303303
dyn_src = FunctionSpec(dyn_val.source; world=job.source.world)
304-
CompilerJob(dyn_val.config, dyn_src)
304+
CompilerJob(dyn_src, dyn_val.config)
305305
elseif dyn_val isa FunctionSpec
306306
dyn_src = FunctionSpec(dyn_val; world=job.source.world)
307-
CompilerJob(job.config, dyn_src)
307+
CompilerJob(dyn_src, job.config)
308308
else
309309
error("invalid deferred job type $(typeof(dyn_val))")
310310
end

src/interface.jl

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,47 +105,57 @@ export CompilerConfig
105105
# the configuration of the compiler
106106

107107
"""
108-
CompilerConfig(target, params; kernel=true, entry_abi=:specfunc, always_inline=false)
108+
CompilerConfig(target, params; kernel=true, entry_abi=:specfunc, entry_name=nothing,
109+
always_inline=false)
109110
110111
Construct a `CompilerConfig` that will be used to drive compilation for the given `target`
111112
and `params`.
112113
113-
The `entry_abi` can be either `:specfunc` the default, or `:func`. `:specfunc` expects the
114-
arguments to be passed in registers, simple return values are returned in registers as well,
115-
and complex return values are returned on the stack using `sret`, the calling convention is
116-
`fastcc`. The `:func` abi is simpler with a calling convention of the first argument being
117-
the function itself (to support closures), the second argument being a pointer to a vector
118-
of boxed Julia values and the third argument being the number of values, the return value
119-
will also be boxed. The `:func` abi will internally call the `:specfunc` abi, but is
120-
generally easier to invoke directly.
121-
122-
`always_inline` specifies if the Julia front-end should inline all functions into one if
123-
possible.
114+
Several keyword arguments can be used to customize the compilation process:
115+
116+
- `kernel`: specifies if the function should be compiled as a kernel, or as a regular
117+
function. This is used to determine the calling convention and for validation purposes.
118+
- `entry_abi`: can be either `:specfunc` the default, or `:func`. `:specfunc` expects the
119+
arguments to be passed in registers, simple return values are returned in registers as
120+
well, and complex return values are returned on the stack using `sret`, the calling
121+
convention is `fastcc`. The `:func` abi is simpler with a calling convention of the first
122+
argument being the function itself (to support closures), the second argument being a
123+
pointer to a vector of boxed Julia values and the third argument being the number of
124+
values, the return value will also be boxed. The `:func` abi will internally call the
125+
`:specfunc` abi, but is generally easier to invoke directly.
126+
- `entry_name`: the name that will be used for the entrypoint function. If `nothing` (the
127+
default), the name will be generated automatically.
128+
- `always_inline` specifies if the Julia front-end should inline all functions into one if
129+
possible.
124130
"""
125131
struct CompilerConfig{T,P}
126132
target::T
127133
params::P
128134

129135
kernel::Bool
136+
name::Union{Nothing,String}
130137
entry_abi::Symbol
131138
always_inline::Bool
132139

133140
function CompilerConfig(target::AbstractCompilerTarget,
134141
params::AbstractCompilerParams;
135-
kernel::Bool=true,
136-
entry_abi::Symbol=:specfunc,
142+
kernel=true,
143+
name=nothing,
144+
entry_abi=:specfunc,
137145
always_inline=false)
138146
if entry_abi (:specfunc, :func)
139147
error("Unknown entry_abi=$entry_abi")
140148
end
141-
new{typeof(target), typeof(params)}(target, params, kernel, entry_abi, always_inline)
149+
new{typeof(target), typeof(params)}(target, params, kernel, name, entry_abi,
150+
always_inline)
142151
end
143152
end
144153

145154
# copy constructor
146155
CompilerConfig(cfg::CompilerConfig; target=cfg.target, params=cfg.params,
147-
kernel=cfg.kernel, entry_abi=cfg.entry_abi, always_inline=cfg.always_inline) =
148-
CompilerConfig(target, params; kernel, entry_abi, always_inline)
156+
kernel=cfg.kernel, name=cfg.name, entry_abi=cfg.entry_abi,
157+
always_inline=cfg.always_inline) =
158+
CompilerConfig(target, params; kernel, entry_abi, name, always_inline)
149159

150160
function Base.show(io::IO, @nospecialize(cfg::CompilerConfig{T})) where {T}
151161
print(io, "CompilerConfig for ", T)
@@ -156,6 +166,7 @@ function Base.hash(cfg::CompilerConfig, h::UInt)
156166
h = hash(cfg.params, h)
157167

158168
h = hash(cfg.kernel, h)
169+
h = hash(cfg.name, h)
159170
h = hash(cfg.entry_abi, h)
160171
h = hash(cfg.always_inline, h)
161172

@@ -170,11 +181,11 @@ export CompilerJob
170181
# a specific invocation of the compiler, bundling everything needed to generate code
171182

172183
struct CompilerJob{T,P}
173-
config::CompilerConfig{T,P}
174184
source::FunctionSpec
185+
config::CompilerConfig{T,P}
175186

176-
CompilerJob(cfg::CompilerConfig{T,P}, src::FunctionSpec) where {T,P} =
177-
new{T,P}(cfg, src)
187+
CompilerJob(src::FunctionSpec, cfg::CompilerConfig{T,P}) where {T,P} =
188+
new{T,P}(src, cfg)
178189
end
179190

180191

src/irgen.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ function irgen(@nospecialize(job::CompilerJob), method_instance::Core.MethodInst
6060
end
6161

6262
# rename and process the entry point
63+
if job.config.name !== nothing
64+
LLVM.name!(entry, safe_name(string("julia_", job.config.name)))
65+
end
6366
if job.config.kernel
6467
LLVM.name!(entry, mangle_call(entry, job.source.tt))
6568
end

src/rtlib.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ end
6666
function emit_function!(mod, config::CompilerConfig, f, method, world; ctx::JuliaContextType)
6767
tt = Base.to_tuple_type(method.types)
6868
source = FunctionSpec(f, tt, world)
69-
new_mod, meta = codegen(:llvm, CompilerJob(config, source);
69+
new_mod, meta = codegen(:llvm, CompilerJob(source, config);
7070
optimize=false, libraries=false, validate=false, ctx)
7171
ft = eltype(llvmtype(meta.entry))
7272
expected_ft = convert(LLVM.FunctionType, method; ctx=context(new_mod))

test/definitions/bpf.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function bpf_job(@nospecialize(func), @nospecialize(types);
1313
target = BPFCompilerTarget()
1414
params = TestCompilerParams()
1515
config = CompilerConfig(target, params; kernel, always_inline)
16-
CompilerJob(config, source), kwargs
16+
CompilerJob(source, config), kwargs
1717
end
1818

1919
function bpf_code_llvm(@nospecialize(func), @nospecialize(types); kwargs...)

test/definitions/gcn.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function gcn_job(@nospecialize(func), @nospecialize(types);
1313
target = GCNCompilerTarget(dev_isa="gfx900")
1414
params = TestCompilerParams()
1515
config = CompilerConfig(target, params; kernel, always_inline)
16-
CompilerJob(config, source), kwargs
16+
CompilerJob(source, config), kwargs
1717
end
1818

1919
function gcn_code_typed(@nospecialize(func), @nospecialize(types); kwargs...)

test/definitions/metal.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function metal_job(@nospecialize(func), @nospecialize(types);
1313
target = MetalCompilerTarget(; macos=v"12.2")
1414
params = TestCompilerParams()
1515
config = CompilerConfig(target, params; kernel, always_inline)
16-
CompilerJob(config, source), kwargs
16+
CompilerJob(source, config), kwargs
1717
end
1818

1919
function metal_code_typed(@nospecialize(func), @nospecialize(types); kwargs...)

test/definitions/native.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function native_job(@nospecialize(func), @nospecialize(types); kernel::Bool=fals
3535
target = NativeCompilerTarget()
3636
params = NativeCompilerParams(entry_safepoint, method_table)
3737
config = CompilerConfig(target, params; kernel, entry_abi, always_inline)
38-
CompilerJob(config, source), kwargs
38+
CompilerJob(source, config), kwargs
3939
end
4040

4141
function native_code_typed(@nospecialize(func), @nospecialize(types); kwargs...)
@@ -271,7 +271,7 @@ module LazyCodegen
271271
# with jlruntime=false, we reach an unreachable.
272272
params = NativeCompilerParams()
273273
config = CompilerConfig(target, params; kernel=false)
274-
job = CompilerJob(config, source)
274+
job = CompilerJob(source, config)
275275

276276
addr = get_trampoline(job)
277277
trampoline = pointer(addr)

0 commit comments

Comments
 (0)