Skip to content

Commit 7132dd3

Browse files
committed
[KeyInstr][Clang] Add Clang option -g[no-]key-instructions
This needs to be driver level to pass an -mllvm flag to LLVM. Keep the flag help-hidden as the feature is under development. --- This patch is part of a stack that teaches Clang to generate Key Instructions metadata for C and C++. The Key Instructions project is introduced, including a "quick summary" section at the top which adds context for this PR, here: https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668 The feature is only functional in LLVM if LLVM is built with CMake flag LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed. The Clang-side work is demoed here: #130943
1 parent 0b206ae commit 7132dd3

File tree

7 files changed

+35
-0
lines changed

7 files changed

+35
-0
lines changed

clang/include/clang/Basic/DebugOptions.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ DEBUGOPT(DebugOmitUnreferencedMethods, 1, 0) ///< Omit unreferenced member
7575
BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,
7676
AssignmentTrackingOpts::Disabled)
7777

78+
/// Whether or not to use Key Instructions to determine breakpoint locations.
79+
BENIGN_DEBUGOPT(DebugKeyInstructions, 1, 0)
80+
7881
DEBUGOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
7982
///< in debug info.
8083

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4588,6 +4588,12 @@ def gembed_source : Flag<["-"], "gembed-source">, Group<g_flags_Group>,
45884588
def gno_embed_source : Flag<["-"], "gno-embed-source">, Group<g_flags_Group>,
45894589
Flags<[NoXarchOption]>,
45904590
HelpText<"Restore the default behavior of not embedding source text in DWARF debug sections">;
4591+
defm key_instructions : BoolGOption<"key-instructions",
4592+
CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
4593+
NegFlag<SetFalse>, PosFlag<SetTrue, [], [],
4594+
"Enable Key Instructions, which reduces the jumpiness of optimized code stepping (DWARF only)."
4595+
" Requires LLVM built with LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS.">,
4596+
BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option]>>;
45914597
def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">;
45924598
def help : Flag<["-", "--"], "help">,
45934599
Visibility<[ClangOption, CC1Option, CC1AsOption,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4767,6 +4767,13 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
47674767
CmdArgs.push_back("-gembed-source");
47684768
}
47694769

4770+
if (Args.hasFlag(options::OPT_gkey_instructions,
4771+
options::OPT_gno_key_instructions, false)) {
4772+
CmdArgs.push_back("-gkey-instructions");
4773+
CmdArgs.push_back("-mllvm");
4774+
CmdArgs.push_back("-dwarf-use-key-instructions");
4775+
}
4776+
47704777
if (EmitCodeView) {
47714778
CmdArgs.push_back("-gcodeview");
47724779

clang/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ llvm_canonicalize_cmake_booleans(
2323
PPC_LINUX_DEFAULT_IEEELONGDOUBLE
2424
LLVM_TOOL_LLVM_DRIVER_BUILD
2525
LLVM_INCLUDE_SPIRV_TOOLS_TESTS
26+
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS
2627
)
2728

2829
configure_lit_site_cfg(

clang/test/KeyInstructions/flag.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang -### -target x86_64 -c -gdwarf -gkey-instructions %s 2>&1 | FileCheck %s --check-prefixes=KEY-INSTRUCTIONS
2+
// RUN: %clang -### -target x86_64 -c -gdwarf -gno-key-instructions %s 2>&1 | FileCheck %s --check-prefixes=NO-KEY-INSTRUCTIONS
3+
//// Default: Off.
4+
// RUN: %clang -### -target x86_64 -c -gdwarf %s 2>&1 | FileCheck %s --check-prefixes=NO-KEY-INSTRUCTIONS
5+
6+
//// Help hidden.
7+
// RUN %clang --help | FileCheck %s --check-prefix=HELP
8+
// HELP-NOT: key-instructions
9+
10+
// KEY-INSTRUCTIONS: "-gkey-instructions"
11+
// KEY-INSTRUCTIONS: "-mllvm" "-dwarf-use-key-instructions"
12+
13+
// NO-KEY-INSTRUCTIONS-NOT: key-instructions
14+
15+
//// TODO: Add smoke test once some functionality has been added.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not config.has_key_instructions:
2+
config.unsupported = True

clang/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
4545
config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
4646
config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
4747
config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
48+
config.has_key_instructions = @LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS@
4849

4950
import lit.llvm
5051
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)