Skip to content

Commit 7288095

Browse files
Require -g2 for llvm names, set code_llvm to -g2 (#50585)
1 parent b3f766c commit 7288095

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/aotcompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
20962096
// Force at least medium debug info for introspection
20972097
// No debug info = no variable names,
20982098
// max debug info = llvm.dbg.declare/value intrinsics which clutter IR output
2099-
output.debug_level = std::max(1, static_cast<int>(jl_options.debug_level));
2099+
output.debug_level = std::max(2, static_cast<int>(jl_options.debug_level));
21002100
auto decls = jl_emit_code(m, mi, src, jlrettype, output);
21012101
JL_UNLOCK(&jl_codegen_lock); // Might GC
21022102

src/codegen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ void setName(jl_codegen_params_t &params, Value *V, const Twine &Name)
175175
// is not checking that setName is only called for non-folded instructions (e.g. folded bitcasts
176176
// and 0-byte geps), which can result in information loss on the renamed instruction.
177177
assert((isa<Constant>(V) || isa<Instruction>(V)) && "Should only set names on instructions!");
178-
if (params.debug_level && !isa<Constant>(V)) {
178+
if (params.debug_level >= 2 && !isa<Constant>(V)) {
179179
V->setName(Name);
180180
}
181181
}
182182

183183
void setName(jl_codegen_params_t &params, Value *V, std::function<std::string()> GetName)
184184
{
185185
assert((isa<Constant>(V) || isa<Instruction>(V)) && "Should only set names on instructions!");
186-
if (params.debug_level && !isa<Constant>(V)) {
186+
if (params.debug_level >= 2 && !isa<Constant>(V)) {
187187
V->setName(Twine(GetName()));
188188
}
189189
}

test/compiler/codegen.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ function get_llvm(@nospecialize(f), @nospecialize(t), raw=true, dump_module=fals
2222
sprint(print, d)
2323
end
2424

25+
# Some tests assume calls should be stripped out,
26+
# so strip out the calls to debug intrinsics that
27+
# are not actually materialized as call instructions.
28+
strip_debug_calls(ir) = replace(ir, r"call void @llvm\.dbg\.declare.*\n" => "", r"call void @llvm\.dbg\.value.*\n" => "")
29+
2530
if !is_debug_build && opt_level > 0
2631
# Make sure getptls call is removed at IR level with optimization on
27-
@test !occursin(" call ", get_llvm(identity, Tuple{String}))
32+
@test !occursin(" call ", strip_debug_calls(get_llvm(identity, Tuple{String})))
2833
end
2934

3035
jl_string_ptr(s::String) = ccall(:jl_string_ptr, Ptr{UInt8}, (Any,), s)
@@ -114,22 +119,22 @@ end
114119

115120
if !is_debug_build && opt_level > 0
116121
# Make sure `jl_string_ptr` is inlined
117-
@test !occursin(" call ", get_llvm(jl_string_ptr, Tuple{String}))
122+
@test !occursin(" call ", strip_debug_calls(get_llvm(jl_string_ptr, Tuple{String})))
118123
# Make sure `Core.sizeof` call is inlined
119124
s = "aaa"
120125
@test jl_string_ptr(s) == pointer_from_objref(s) + sizeof(Int)
121126
# String
122-
test_loads_no_call(get_llvm(core_sizeof, Tuple{String}), [Iptr])
127+
test_loads_no_call(strip_debug_calls(get_llvm(core_sizeof, Tuple{String})), [Iptr])
123128
# String
124-
test_loads_no_call(get_llvm(core_sizeof, Tuple{Core.SimpleVector}), [Iptr])
129+
test_loads_no_call(strip_debug_calls(get_llvm(core_sizeof, Tuple{Core.SimpleVector})), [Iptr])
125130
# Array
126-
test_loads_no_call(get_llvm(core_sizeof, Tuple{Vector{Int}}), [Iptr])
131+
test_loads_no_call(strip_debug_calls(get_llvm(core_sizeof, Tuple{Vector{Int}})), [Iptr])
127132
# As long as the eltype is known we don't need to load the elsize
128-
test_loads_no_call(get_llvm(core_sizeof, Tuple{Array{Any}}), [Iptr])
133+
test_loads_no_call(strip_debug_calls(get_llvm(core_sizeof, Tuple{Array{Any}})), [Iptr])
129134
# Check that we load the elsize
130-
test_loads_no_call(get_llvm(core_sizeof, Tuple{Vector}), [Iptr, "i16"])
135+
test_loads_no_call(strip_debug_calls(get_llvm(core_sizeof, Tuple{Vector})), [Iptr, "i16"])
131136
# Primitive Type size should be folded to a constant
132-
test_loads_no_call(get_llvm(core_sizeof, Tuple{Ptr}), String[])
137+
test_loads_no_call(strip_debug_calls(get_llvm(core_sizeof, Tuple{Ptr})), String[])
133138

134139
test_jl_dump_compiles()
135140
test_jl_dump_compiles_toplevel_thunks()
@@ -791,7 +796,7 @@ f48085(@nospecialize x...) = length(x)
791796
@test Core.Compiler.get_compileable_sig(which(f48085, (Vararg{Any},)), Tuple{typeof(f48085), Int, Vararg{Int}}, Core.svec()) === Tuple{typeof(f48085), Any, Vararg{Any}}
792797

793798
# Make sure that the bounds check is elided in tuple iteration
794-
@test !occursin("call void @", get_llvm(iterate, Tuple{NTuple{4, Float64}, Int}))
799+
@test !occursin("call void @", strip_debug_calls(get_llvm(iterate, Tuple{NTuple{4, Float64}, Int})))
795800

796801
# issue #34459
797802
function f34459(args...)

0 commit comments

Comments
 (0)