Skip to content

Commit 8f03e1a

Browse files
authored
[KeyInstr][Clang] Add Clang option -g[no-]key-instructions (#134627)
This needs to be driver level to pass an -mllvm flag to LLVM, though this may change soon as the -mllvm flag will soon not be necessary. 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++. RFC: 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.
1 parent 0c82e06 commit 8f03e1a

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
@@ -4664,6 +4664,12 @@ def gembed_source : Flag<["-"], "gembed-source">, Group<g_flags_Group>,
46644664
def gno_embed_source : Flag<["-"], "gno-embed-source">, Group<g_flags_Group>,
46654665
Flags<[NoXarchOption]>,
46664666
HelpText<"Restore the default behavior of not embedding source text in DWARF debug sections">;
4667+
defm key_instructions : BoolGOption<"key-instructions",
4668+
CodeGenOpts<"DebugKeyInstructions">, DefaultFalse,
4669+
NegFlag<SetFalse>, PosFlag<SetTrue, [], [],
4670+
"Enable Key Instructions, which reduces the jumpiness of optimized code stepping (DWARF only)."
4671+
" Requires LLVM built with LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS.">,
4672+
BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option]>>;
46674673
def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">;
46684674
def help : Flag<["-", "--"], "help">,
46694675
Visibility<[ClangOption, CC1Option, CC1AsOption,

clang/lib/Driver/ToolChains/Clang.cpp

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

4779+
if (Args.hasFlag(options::OPT_gkey_instructions,
4780+
options::OPT_gno_key_instructions, false)) {
4781+
CmdArgs.push_back("-gkey-instructions");
4782+
CmdArgs.push_back("-mllvm");
4783+
CmdArgs.push_back("-dwarf-use-key-instructions");
4784+
}
4785+
47794786
if (EmitCodeView) {
47804787
CmdArgs.push_back("-gcodeview");
47814788

clang/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ llvm_canonicalize_cmake_booleans(
2626
PPC_LINUX_DEFAULT_IEEELONGDOUBLE
2727
LLVM_TOOL_LLVM_DRIVER_BUILD
2828
LLVM_INCLUDE_SPIRV_TOOLS_TESTS
29+
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS
2930
)
3031

3132
configure_lit_site_cfg(
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
@@ -48,6 +48,7 @@ config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
4848
config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
4949
config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@
5050
config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
51+
config.has_key_instructions = @LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS@
5152

5253
import lit.llvm
5354
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)