Skip to content

Commit 0da46e2

Browse files
Name LLVM variables from codegen (#50094)
1 parent 427b123 commit 0da46e2

File tree

9 files changed

+506
-112
lines changed

9 files changed

+506
-112
lines changed

src/aotcompile.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
305305
jl_codegen_params_t params(ctxt, std::move(target_info.first), std::move(target_info.second));
306306
params.params = cgparams;
307307
params.imaging = imaging;
308+
params.debug_level = jl_options.debug_level;
308309
params.external_linkage = _external_linkage;
309310
size_t compile_for[] = { jl_typeinf_world, _world };
310311
for (int worlds = 0; worlds < 2; worlds++) {
@@ -2082,6 +2083,16 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
20822083
jl_codegen_params_t output(*ctx, std::move(target_info.first), std::move(target_info.second));
20832084
output.world = world;
20842085
output.params = &params;
2086+
output.imaging = imaging_default();
2087+
// This would be nice, but currently it causes some assembly regressions that make printed output
2088+
// differ very significantly from the actual non-imaging mode code.
2089+
// // Force imaging mode for names of pointers
2090+
// output.imaging = true;
2091+
// This would also be nice, but it seems to cause OOMs on the windows32 builder
2092+
// // Force at least medium debug info for introspection
2093+
// No debug info = no variable names,
2094+
// max debug info = llvm.dbg.declare/value intrinsics which clutter IR output
2095+
output.debug_level = jl_options.debug_level;
20852096
auto decls = jl_emit_code(m, mi, src, jlrettype, output);
20862097
JL_UNLOCK(&jl_codegen_lock); // Might GC
20872098

src/ccall.cpp

Lines changed: 53 additions & 4 deletions
Large diffs are not rendered by default.

src/cgutils.cpp

Lines changed: 121 additions & 24 deletions
Large diffs are not rendered by default.

src/codegen.cpp

Lines changed: 114 additions & 24 deletions
Large diffs are not rendered by default.

src/intrinsics.cpp

Lines changed: 79 additions & 31 deletions
Large diffs are not rendered by default.

src/jitlayers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ static jl_callptr_t _jl_compile_codeinst(
195195
jl_codegen_params_t params(std::move(context), jl_ExecutionEngine->getDataLayout(), jl_ExecutionEngine->getTargetTriple()); // Locks the context
196196
params.cache = true;
197197
params.world = world;
198+
params.imaging = imaging_default();
199+
params.debug_level = jl_options.debug_level;
198200
jl_workqueue_t emitted;
199201
{
200202
orc::ThreadSafeModule result_m =
@@ -358,6 +360,8 @@ int jl_compile_extern_c_impl(LLVMOrcThreadSafeModuleRef llvmmod, void *p, void *
358360
return std::make_pair(M.getDataLayout(), Triple(M.getTargetTriple()));
359361
});
360362
jl_codegen_params_t params(into->getContext(), std::move(target_info.first), std::move(target_info.second));
363+
params.imaging = imaging_default();
364+
params.debug_level = jl_options.debug_level;
361365
if (pparams == NULL)
362366
pparams = &params;
363367
assert(pparams->tsctx.getContext() == into->getContext().getContext());

src/jitlayers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ typedef struct _jl_codegen_params_t {
237237
bool cache = false;
238238
bool external_linkage = false;
239239
bool imaging;
240+
int debug_level;
240241
_jl_codegen_params_t(orc::ThreadSafeContext ctx, DataLayout DL, Triple triple)
241242
: tsctx(std::move(ctx)), tsctx_lock(tsctx.getLock()),
242243
DL(std::move(DL)), TargetTriple(std::move(triple)), imaging(imaging_default()) {}

test/cmdlineargs.jl

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -519,29 +519,34 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
519519

520520
# -g
521521
@test readchomp(`$exename -E "Base.JLOptions().debug_level" -g`) == "2"
522-
let code = writereadpipeline("code_llvm(stdout, +, (Int64, Int64), raw=true, dump_module=true)", `$exename -g0`)
523-
@test code[2]
524-
code = code[1]
525-
@test occursin("llvm.module.flags", code)
526-
@test !occursin("llvm.dbg.cu", code)
527-
@test !occursin("int.jl", code)
528-
@test !occursin("Int64", code)
529-
end
530-
let code = writereadpipeline("code_llvm(stdout, +, (Int64, Int64), raw=true, dump_module=true)", `$exename -g1`)
531-
@test code[2]
532-
code = code[1]
533-
@test occursin("llvm.module.flags", code)
534-
@test occursin("llvm.dbg.cu", code)
535-
@test occursin("int.jl", code)
536-
@test !occursin("Int64", code)
537-
end
538-
let code = writereadpipeline("code_llvm(stdout, +, (Int64, Int64), raw=true, dump_module=true)", `$exename -g2`)
539-
@test code[2]
540-
code = code[1]
541-
@test occursin("llvm.module.flags", code)
542-
@test occursin("llvm.dbg.cu", code)
543-
@test occursin("int.jl", code)
544-
@test occursin("\"Int64\"", code)
522+
# --print-before/--print-after with pass names is broken on Windows due to no-gnu-unique issues
523+
if !Sys.iswindows()
524+
withenv("JULIA_LLVM_ARGS" => "--print-before=FinalLowerGC") do
525+
let code = readchomperrors(`$exename -g0 -E "@eval Int64(1)+Int64(1)"`)
526+
@test code[1]
527+
code = code[3]
528+
@test occursin("llvm.module.flags", code)
529+
@test !occursin("llvm.dbg.cu", code)
530+
@test !occursin("int.jl", code)
531+
@test !occursin("\"Int64\"", code)
532+
end
533+
let code = readchomperrors(`$exename -g1 -E "@eval Int64(1)+Int64(1)"`)
534+
@test code[1]
535+
code = code[3]
536+
@test occursin("llvm.module.flags", code)
537+
@test occursin("llvm.dbg.cu", code)
538+
@test occursin("int.jl", code)
539+
@test !occursin("\"Int64\"", code)
540+
end
541+
let code = readchomperrors(`$exename -g2 -E "@eval Int64(1)+Int64(1)"`)
542+
@test code[1]
543+
code = code[3]
544+
@test occursin("llvm.module.flags", code)
545+
@test occursin("llvm.dbg.cu", code)
546+
@test occursin("int.jl", code)
547+
@test occursin("\"Int64\"", code)
548+
end
549+
end
545550
end
546551

547552
# --check-bounds

test/llvmpasses/llvmcall.jl

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,109 @@ end
1313
@generated foo(x)=:(ccall("extern foo", llvmcall, $x, ($x,), x))
1414
bar(x) = ntuple(i -> VecElement{Float16}(x[i]), 2)
1515

16-
# CHECK: call half @foo(half %{{[0-9]+}})
16+
# CHECK: define
17+
# CHECK-SAME: half @julia_foo
18+
# CHECK-SAME: {
19+
# CHECK-NOT: define
20+
# CHECK: [[FOO_RET:%.*]] = call half @foo(half [[FOO_ARG:%.*]])
21+
# CHECK-NOT: define
22+
# CHECK: ret half
23+
# CHECK-NOT: define
24+
# CHECK: }
1725
emit(foo, Float16)
1826

19-
# CHECK: call [2 x half] @foo([2 x half] %{{[0-9]+}})
27+
# COM: Make sure that we don't miss a function by accident (helps localize errors)
28+
# CHECK-NOT: {
29+
# CHECK-NOT: }
30+
# CHECK: define
31+
# CHECK-SAME: nonnull {} addrspace(10)* @jfptr
32+
# CHECK-SAME: {
33+
34+
# CHECK: define
35+
# CHECK-SAME: [2 x half] @julia_foo
36+
# CHECK-SAME: {
37+
# CHECK-NOT: define
38+
# CHECK: [[FOO_RET:%.*]] = call [2 x half] @foo([2 x half] [[FOO_ARG:%.*]])
39+
# CHECK-NOT: define
40+
# CHECK: ret [2 x half]
41+
# CHECK-NOT: define
42+
# CHECK: }
2043
emit(foo, NTuple{2, Float16})
2144

22-
# CHECK: call <2 x half> @foo(<2 x half> %{{[0-9]+}})
45+
# COM: Make sure that we don't miss a function by accident (helps localize errors)
46+
# CHECK-NOT: {
47+
# CHECK-NOT: }
48+
# CHECK: define
49+
# CHECK-SAME: nonnull {} addrspace(10)* @jfptr
50+
# CHECK-SAME: {
51+
52+
# CHECK: define
53+
# CHECK-SAME: <2 x half> @julia_foo
54+
# CHECK-SAME: {
55+
# CHECK-NOT: define
56+
# CHECK: [[FOO_RET:%.*]] call <2 x half> @foo(<2 x half> [[FOO_ARG:%.*]])
57+
# CHECK-NOT: define
58+
# CHECK: ret <2 x half>
59+
# CHECK-NOT: define
60+
# CHECK: }
2361
emit(foo, NTuple{2, VecElement{Float16}})
2462

25-
# CHECK: call i8 addrspace(3)* @foo(i8 addrspace(3)* %{{[0-9]+}})
63+
# COM: Make sure that we don't miss a function by accident (helps localize errors)
64+
# CHECK-NOT: {
65+
# CHECK-NOT: }
66+
# CHECK: define
67+
# CHECK-SAME: nonnull {} addrspace(10)* @jfptr
68+
# CHECK-SAME: {
69+
70+
# CHECK: define
71+
# CHECK-SAME: i8 addrspace(3)* @julia_foo
72+
# CHECK-SAME: {
73+
# CHECK-NOT: define
74+
# CHECK: [[FOO_RET:%.*]] call i8 addrspace(3)* @foo(i8 addrspace(3)* [[FOO_ARG:%.*]])
75+
# CHECK-NOT: define
76+
# CHECK: ret i8 addrspace(3)*
77+
# CHECK-NOT: define
78+
# CHECK: }
2679
emit(foo, Core.LLVMPtr{Float32, 3})
2780

28-
# CHECK: call { i32, i32 } @foo({ i32, i32 } %{{[0-9]+}})
81+
# COM: Make sure that we don't miss a function by accident (helps localize errors)
82+
# CHECK-NOT: {
83+
# CHECK-NOT: }
84+
# CHECK: define
85+
# CHECK-SAME: nonnull {} addrspace(10)* @jfptr
86+
# CHECK-SAME: {
87+
88+
# CHECK: define
89+
# CHECK-SAME: [2 x i32] @julia_foo
90+
# CHECK-SAME: {
91+
# CHECK-NOT: define
92+
# CHECK: [[FOO_RET:%.*]] call { i32, i32 } @foo({ i32, i32 } [[FOO_ARG:%.*]])
93+
# CHECK-NOT: define
94+
# CHECK: ret [2 x i32]
95+
# CHECK-NOT: define
96+
# CHECK: }
2997
emit(foo, Foo)
3098

31-
# CHECK: define {{(swiftcc )?}}<2 x half> @julia_bar_{{[0-9]+}}(
99+
# COM: Make sure that we don't miss a function by accident (helps localize errors)
100+
# CHECK-NOT: {
101+
# CHECK-NOT: }
102+
# CHECK: define
103+
# CHECK-SAME: nonnull {} addrspace(10)* @jfptr
104+
# CHECK-SAME: {
105+
106+
# CHECK: define
107+
# CHECK-SAME: <2 x half> @julia_bar
108+
# CHECK-SAME: [2 x half]
109+
# CHECK-SAME: {
110+
# CHECK-NOT: define
111+
# CHECK: ret <2 x half>
112+
# CHECK-NOT: define
113+
# CHECK: }
32114
emit(bar, NTuple{2, Float16})
115+
116+
# COM: Make sure that we don't miss a function by accident (helps localize errors)
117+
# CHECK-NOT: {
118+
# CHECK-NOT: }
119+
# CHECK: define
120+
# CHECK-SAME: nonnull {} addrspace(10)* @jfptr
121+
# CHECK-SAME: {

0 commit comments

Comments
 (0)