https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/134627
>From 4d6e182ae2b6fea246492cd80c9fce75d1c7397d Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Mon, 31 Mar 2025 15:14:51 +0100 Subject: [PATCH 1/2] [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: https://github.com/llvm/llvm-project/pull/130943 --- clang/include/clang/Basic/DebugOptions.def | 3 +++ clang/include/clang/Driver/Options.td | 6 ++++++ clang/lib/Driver/ToolChains/Clang.cpp | 7 +++++++ clang/test/CMakeLists.txt | 1 + clang/test/KeyInstructions/flag.cpp | 15 +++++++++++++++ clang/test/KeyInstructions/lit.local.cfg | 2 ++ clang/test/lit.site.cfg.py.in | 1 + 7 files changed, 35 insertions(+) create mode 100644 clang/test/KeyInstructions/flag.cpp create mode 100644 clang/test/KeyInstructions/lit.local.cfg diff --git a/clang/include/clang/Basic/DebugOptions.def b/clang/include/clang/Basic/DebugOptions.def index bc96d5dfdf890..7a9d2e838c1ca 100644 --- a/clang/include/clang/Basic/DebugOptions.def +++ b/clang/include/clang/Basic/DebugOptions.def @@ -75,6 +75,9 @@ DEBUGOPT(DebugOmitUnreferencedMethods, 1, 0) ///< Omit unreferenced member BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, AssignmentTrackingOpts::Disabled) +/// Whether or not to use Key Instructions to determine breakpoint locations. +BENIGN_DEBUGOPT(DebugKeyInstructions, 1, 0) + DEBUGOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information ///< in debug info. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index bd8df8f6a749a..9a4253113488d 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -4664,6 +4664,12 @@ def gembed_source : Flag<["-"], "gembed-source">, Group<g_flags_Group>, def gno_embed_source : Flag<["-"], "gno-embed-source">, Group<g_flags_Group>, Flags<[NoXarchOption]>, HelpText<"Restore the default behavior of not embedding source text in DWARF debug sections">; +defm key_instructions : BoolGOption<"key-instructions", + CodeGenOpts<"DebugKeyInstructions">, DefaultFalse, + NegFlag<SetFalse>, PosFlag<SetTrue, [], [], + "Enable Key Instructions, which reduces the jumpiness of optimized code stepping (DWARF only)." + " Requires LLVM built with LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS.">, + BothFlags<[HelpHidden], [ClangOption, CLOption, CC1Option]>>; def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">; def help : Flag<["-", "--"], "help">, Visibility<[ClangOption, CC1Option, CC1AsOption, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a08bdba99bfe0..4b79eef83196e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4776,6 +4776,13 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, CmdArgs.push_back("-gembed-source"); } + if (Args.hasFlag(options::OPT_gkey_instructions, + options::OPT_gno_key_instructions, false)) { + CmdArgs.push_back("-gkey-instructions"); + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("-dwarf-use-key-instructions"); + } + if (EmitCodeView) { CmdArgs.push_back("-gcodeview"); diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt index 0d11fd2c07eb5..35a8042ac0e0a 100644 --- a/clang/test/CMakeLists.txt +++ b/clang/test/CMakeLists.txt @@ -26,6 +26,7 @@ llvm_canonicalize_cmake_booleans( PPC_LINUX_DEFAULT_IEEELONGDOUBLE LLVM_TOOL_LLVM_DRIVER_BUILD LLVM_INCLUDE_SPIRV_TOOLS_TESTS + LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS ) configure_lit_site_cfg( diff --git a/clang/test/KeyInstructions/flag.cpp b/clang/test/KeyInstructions/flag.cpp new file mode 100644 index 0000000000000..93503dd4bdb4c --- /dev/null +++ b/clang/test/KeyInstructions/flag.cpp @@ -0,0 +1,15 @@ +// RUN: %clang -### -target x86_64 -c -gdwarf -gkey-instructions %s 2>&1 | FileCheck %s --check-prefixes=KEY-INSTRUCTIONS +// RUN: %clang -### -target x86_64 -c -gdwarf -gno-key-instructions %s 2>&1 | FileCheck %s --check-prefixes=NO-KEY-INSTRUCTIONS +//// Default: Off. +// RUN: %clang -### -target x86_64 -c -gdwarf %s 2>&1 | FileCheck %s --check-prefixes=NO-KEY-INSTRUCTIONS + +//// Help hidden. +// RUN %clang --help | FileCheck %s --check-prefix=HELP +// HELP-NOT: key-instructions + +// KEY-INSTRUCTIONS: "-gkey-instructions" +// KEY-INSTRUCTIONS: "-mllvm" "-dwarf-use-key-instructions" + +// NO-KEY-INSTRUCTIONS-NOT: key-instructions + +//// TODO: Add smoke test once some functionality has been added. diff --git a/clang/test/KeyInstructions/lit.local.cfg b/clang/test/KeyInstructions/lit.local.cfg new file mode 100644 index 0000000000000..482bd5c8ac251 --- /dev/null +++ b/clang/test/KeyInstructions/lit.local.cfg @@ -0,0 +1,2 @@ +if not config.has_key_instructions: + config.unsupported = True diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in index e73acfc79d9ad..77c5f27f47c92 100644 --- a/clang/test/lit.site.cfg.py.in +++ b/clang/test/lit.site.cfg.py.in @@ -48,6 +48,7 @@ config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@ config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@ config.spirv_tools_tests = @LLVM_INCLUDE_SPIRV_TOOLS_TESTS@ config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@")) +config.has_key_instructions = @LLVM_EXPERIMENTAL_KEY_INSTRUCTIONS@ import lit.llvm lit.llvm.initialize(lit_config, config) >From 5c9d5e03fe0c3ff495aca673279b3e479836b9ad Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 14 May 2025 17:57:43 +0100 Subject: [PATCH 2/2] Move clang/test/KeyInstructions -> clang/test/DebugInfo/KeyInstructions --- clang/test/{ => DebugInfo}/KeyInstructions/flag.cpp | 0 clang/test/{ => DebugInfo}/KeyInstructions/lit.local.cfg | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename clang/test/{ => DebugInfo}/KeyInstructions/flag.cpp (100%) rename clang/test/{ => DebugInfo}/KeyInstructions/lit.local.cfg (100%) diff --git a/clang/test/KeyInstructions/flag.cpp b/clang/test/DebugInfo/KeyInstructions/flag.cpp similarity index 100% rename from clang/test/KeyInstructions/flag.cpp rename to clang/test/DebugInfo/KeyInstructions/flag.cpp diff --git a/clang/test/KeyInstructions/lit.local.cfg b/clang/test/DebugInfo/KeyInstructions/lit.local.cfg similarity index 100% rename from clang/test/KeyInstructions/lit.local.cfg rename to clang/test/DebugInfo/KeyInstructions/lit.local.cfg _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits