[llvm-branch-commits] [mlir] [mlir][memref] Check memory space before lowering alloc ops (PR #134427)

2025-04-07 Thread Matthias Springer via llvm-branch-commits

https://github.com/matthias-springer updated 
https://github.com/llvm/llvm-project/pull/134427

>From bd104624a51dc315b94f651271b95b8b438a8146 Mon Sep 17 00:00:00 2001
From: Matthias Springer 
Date: Fri, 4 Apr 2025 19:59:28 +0200
Subject: [PATCH 1/2] [mlir][memref] Check memory space before lowering alloc
 ops

---
 mlir/include/mlir/Conversion/LLVMCommon/Pattern.h| 8 +---
 mlir/lib/Conversion/LLVMCommon/Pattern.cpp   | 9 ++---
 mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp | 7 +--
 mlir/test/Conversion/MemRefToLLVM/invalid.mlir   | 3 +--
 4 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h 
b/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
index c65f7d7217be5..6f7811acec939 100644
--- a/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
+++ b/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
@@ -75,9 +75,11 @@ class ConvertToLLVMPattern : public ConversionPattern {
  ValueRange indices,
  ConversionPatternRewriter &rewriter) const;
 
-  /// Returns if the given memref has identity maps and the element type is
-  /// convertible to LLVM.
-  bool isConvertibleAndHasIdentityMaps(MemRefType type) const;
+  /// Returns if the given memref type is convertible to LLVM and has an
+  /// identity layout map. If `verifyMemorySpace` is set to "false", the memory
+  /// space of the memref type is ignored.
+  bool isConvertibleAndHasIdentityMaps(MemRefType type,
+   bool verifyMemorySpace = true) const;
 
   /// Returns the type of a pointer to an element of the memref.
   Type getElementPtrType(MemRefType type) const;
diff --git a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp 
b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
index 71b68619cc793..d11de1f44250c 100644
--- a/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/Pattern.cpp
@@ -98,10 +98,13 @@ Value ConvertToLLVMPattern::getStridedElementPtr(
 // Check if the MemRefType `type` is supported by the lowering. We currently
 // only support memrefs with identity maps.
 bool ConvertToLLVMPattern::isConvertibleAndHasIdentityMaps(
-MemRefType type) const {
-  if (!typeConverter->convertType(type.getElementType()))
+MemRefType type, bool verifyMemorySpace) const {
+  if (!type.getLayout().isIdentity())
 return false;
-  return type.getLayout().isIdentity();
+  // If the memory space should not be verified, just check the element type.
+  Type typeToVerify =
+  verifyMemorySpace ? static_cast(type) : type.getElementType();
+  return static_cast(typeConverter->convertType(typeToVerify));
 }
 
 Type ConvertToLLVMPattern::getElementPtrType(MemRefType type) const {
diff --git a/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp 
b/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
index c5b2e83df93dc..bad209a4ddecf 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
@@ -73,12 +73,7 @@ std::tuple 
AllocationOpLLVMLowering::allocateBufferManuallyAlign(
   MemRefType memRefType = getMemRefResultType(op);
   // Allocate the underlying buffer.
   Type elementPtrType = this->getElementPtrType(memRefType);
-  if (!elementPtrType) {
-emitError(loc, "conversion of memref memory space ")
-<< memRefType.getMemorySpace()
-<< " to integer address space "
-   "failed. Consider adding memory space conversions.";
-  }
+  assert(elementPtrType && "could not compute element ptr type");
   FailureOr allocFuncOp = getNotalignedAllocFn(
   getTypeConverter(), op->getParentWithTrait(),
   getIndexType());
diff --git a/mlir/test/Conversion/MemRefToLLVM/invalid.mlir 
b/mlir/test/Conversion/MemRefToLLVM/invalid.mlir
index 61c67005a08fc..0d04bba96bcdb 100644
--- a/mlir/test/Conversion/MemRefToLLVM/invalid.mlir
+++ b/mlir/test/Conversion/MemRefToLLVM/invalid.mlir
@@ -22,7 +22,7 @@ func.func @bad_address_space(%a: memref<2xindex, "foo">) {
 
 // CHECK-LABEL: @invalid_int_conversion
 func.func @invalid_int_conversion() {
- // expected-error@+1 {{conversion of memref memory space 1 : ui64 to 
integer address space failed. Consider adding memory space conversions.}}
+ // expected-error@unknown{{conversion of memref memory space 1 : ui64 to 
integer address space failed. Consider adding memory space conversions.}}
  %alloc = memref.alloc() {alignment = 64 : i64} : memref<10xf32, 1 : ui64> 
 return
 }
@@ -32,7 +32,6 @@ func.func @invalid_int_conversion() {
 // expected-error@unknown{{conversion of memref memory space 
#gpu.address_space to integer address space failed. Consider adding 
memory space conversions}}
 // CHECK-LABEL: @issue_70160
 func.func @issue_70160() {
-  // expected-error@+1{{conversion of memref memory space 
#gpu.address_space to integer address space failed. Consider adding 
memory space conversion

[llvm-branch-commits] [mlir] [mlir][memref] Check memory space before lowering alloc ops (PR #134427)

2025-04-07 Thread Matthias Springer via llvm-branch-commits


@@ -75,9 +75,11 @@ class ConvertToLLVMPattern : public ConversionPattern {
  ValueRange indices,
  ConversionPatternRewriter &rewriter) const;
 
-  /// Returns if the given memref has identity maps and the element type is
-  /// convertible to LLVM.
-  bool isConvertibleAndHasIdentityMaps(MemRefType type) const;
+  /// Returns if the given memref type is convertible to LLVM and has an
+  /// identity layout map. If `verifyMemorySpace` is set to "false", the memory
+  /// space of the memref type is ignored.
+  bool isConvertibleAndHasIdentityMaps(MemRefType type,
+   bool verifyMemorySpace = true) const;

matthias-springer wrote:

Done.

I added it because it is public API. But users downstream users can easily 
switch back to the original behavior if needed by adding a helper function 
somewhere. It's just 2 lines of code.


https://github.com/llvm/llvm-project/pull/134427
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -16,34 +16,94 @@
 #define LLVM_MC_MCSECTIONGOFF_H
 
 #include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/MC/MCGOFFAttributes.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
 class MCExpr;
 
 class MCSectionGOFF final : public MCSection {
-private:
-  MCSection *Parent;
-  uint32_t Subsection;
+  // Parent of this section. Implies that the parent is emitted first.
+  MCSectionGOFF *Parent;
+
+  // The attributes of the GOFF symbols.
+  GOFF::SDAttr SDAttributes;
+  GOFF::EDAttr EDAttributes;
+  GOFF::PRAttr PRAttributes;
+
+  // The type of this section.
+  GOFF::ESDSymbolType SymbolType;
+
+  // Indicates that the PR symbol needs to set the length of the section to a
+  // non-zero value. This is only a problem with the ADA PR - the binder will
+  // generate an error in this case.
+  unsigned RequiresNonZeroLength : 1;
 
   friend class MCContext;
-  MCSectionGOFF(StringRef Name, SectionKind K, MCSection *P, uint32_t Sub)
+  MCSectionGOFF(StringRef Name, SectionKind K, GOFF::ESDSymbolType SymbolType,
+GOFF::SDAttr SDAttributes, GOFF::EDAttr EDAttributes,
+GOFF::PRAttr PRAttributes, MCSectionGOFF *Parent = nullptr)
   : MCSection(SV_GOFF, Name, K.isText(), /*IsVirtual=*/false, nullptr),
-Parent(P), Subsection(Sub) {}
+Parent(Parent), SDAttributes(SDAttributes), EDAttributes(EDAttributes),
+PRAttributes(PRAttributes), SymbolType(SymbolType) {}
 
 public:
   void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
 raw_ostream &OS,
-uint32_t /*Subsection*/) const override {
-OS << "\t.section\t\"" << getName() << "\"\n";
+uint32_t Subsection) const override {
+switch (SymbolType) {
+case GOFF::ESD_ST_SectionDefinition:
+  OS << Name << " CSECT\n";
+  break;
+case GOFF::ESD_ST_ElementDefinition:
+  getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+  OS << Name << " CATTR\n";
+  break;
+case GOFF::ESD_ST_PartReference:
+  getParent()->printSwitchToSection(MAI, T, OS, Subsection);
+  OS << Name << " XATTR\n";

redstar wrote:

Yes, true, I need to update my HLASM skills.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)

2025-04-07 Thread Sander de Smalen via llvm-branch-commits


@@ -5039,10 +5039,25 @@ calculateRegisterUsage(VPlan &Plan, 
ArrayRef VFs,
 // even in the scalar case.
 RegUsage[ClassID] += 1;
   } else {
+// The output from scaled phis and scaled reductions actually have
+// fewer lanes than the VF.
+ElementCount VF = VFs[J];
+if (auto *ReductionR = dyn_cast(R))
+  VF = VF.divideCoefficientBy(ReductionR->getVFScaleFactor());
+else if (auto *PartialReductionR =
+ dyn_cast(R))
+  VF = 
VF.divideCoefficientBy(PartialReductionR->getVFScaleFactor());
+
+LLVM_DEBUG(if (VF != VFs[J]) {
+  dbgs() << "LV(REG): Scaled down VF from " << VFs[J] << " to "
+ << VF << " for ";
+  R->dump();

sdesmalen-arm wrote:

minor nit: Is it worth creating a `operator<<` for VPDef, so that you can write:
```suggestion
 << VF << " for " << *R << "\n";
```
?

https://github.com/llvm/llvm-project/pull/133090
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Ulrich Weigand via llvm-branch-commits


@@ -16,34 +16,95 @@
 #define LLVM_MC_MCSECTIONGOFF_H
 
 #include "llvm/BinaryFormat/GOFF.h"
+#include "llvm/MC/MCGOFFAttributes.h"
 #include "llvm/MC/MCSection.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace llvm {
 
 class MCExpr;
 
 class MCSectionGOFF final : public MCSection {
-private:
-  MCSection *Parent;
-  uint32_t Subsection;
+  // Parent of this section. Implies that the parent is emitted first.
+  MCSectionGOFF *Parent;
+
+  // The attributes of the GOFF symbols.
+  GOFF::SDAttr SDAttributes;
+  GOFF::EDAttr EDAttributes;
+  GOFF::PRAttr PRAttributes;

uweigand wrote:

union might be better?

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [compiler-rt] compiler-rt: Introduce runtime functions for emulated PAC. (PR #133530)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133530

>From b37a44fff650b06eda249060277d0c007226cad2 Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Thu, 3 Apr 2025 21:51:44 -0700
Subject: [PATCH] Fix CMake build

Created using spr 1.3.6-beta.1
---
 compiler-rt/cmake/Modules/AddCompilerRT.cmake | 8 +++-
 compiler-rt/cmake/builtin-config-ix.cmake | 1 +
 compiler-rt/lib/builtins/CMakeLists.txt   | 8 ++--
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake 
b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index c3e734f72392f..2f6fd4ba1e4c9 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -172,7 +172,7 @@ function(add_compiler_rt_runtime name type)
   cmake_parse_arguments(LIB
 ""
 "PARENT_TARGET"
-
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS"
+
"OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;DEPS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;EXTENSIONS;C_STANDARD;CXX_STANDARD"
 ${ARGN})
   set(libnames)
   # Until we support this some other way, build compiler-rt runtime without LTO
@@ -360,6 +360,12 @@ function(add_compiler_rt_runtime name type)
   set_target_link_flags(${libname} ${extra_link_flags_${libname}})
   set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+  if(LIB_C_STANDARD)
+set_property(TARGET ${libname} PROPERTY C_STANDARD ${LIB_C_STANDARD})
+  endif()
+  if(LIB_CXX_STANDARD)
+set_property(TARGET ${libname} PROPERTY CXX_STANDARD 
${LIB_CXX_STANDARD})
+  endif()
   set_target_output_directories(${libname} ${output_dir_${libname}})
   install(TARGETS ${libname}
 ARCHIVE DESTINATION ${install_dir_${libname}}
diff --git a/compiler-rt/cmake/builtin-config-ix.cmake 
b/compiler-rt/cmake/builtin-config-ix.cmake
index 7bd3269bd999d..7bdd30ee67f3d 100644
--- a/compiler-rt/cmake/builtin-config-ix.cmake
+++ b/compiler-rt/cmake/builtin-config-ix.cmake
@@ -26,6 +26,7 @@ builtin_check_c_compiler_flag("-Xclang 
-mcode-object-version=none" COMPILER_RT_H
 builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch 
COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG)
 builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG)
 builtin_check_c_compiler_flag(-fcf-protection=full 
COMPILER_RT_HAS_FCF_PROTECTION_FLAG)
+builtin_check_c_compiler_flag(-nostdinc++  
COMPILER_RT_HAS_NOSTDINCXX_FLAG)
 
 builtin_check_c_compiler_source(COMPILER_RT_HAS_ATOMIC_KEYWORD
 "
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index e6c3273eb2859..ca5cc7d218223 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -6,7 +6,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   cmake_minimum_required(VERSION 3.20.0)
 
   set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-  project(CompilerRTBuiltins C ASM)
+  project(CompilerRTBuiltins C CXX ASM)
   set(COMPILER_RT_STANDALONE_BUILD TRUE)
   set(COMPILER_RT_BUILTINS_STANDALONE_BUILD TRUE)
 
@@ -64,6 +64,8 @@ include(CMakePushCheckState)
 option(COMPILER_RT_BUILTINS_HIDE_SYMBOLS
   "Do not export any symbols from the static library." ON)
 
+include_directories(../../../third-party/siphash/include)
+
 # TODO: Need to add a mechanism for logging errors when builtin source files 
are
 # added to a sub-directory and not this CMakeLists file.
 set(GENERIC_SOURCES
@@ -803,7 +805,7 @@ else ()
 append_list_if(COMPILER_RT_ENABLE_CET -fcf-protection=full BUILTIN_CFLAGS)
   endif()
 
-  append_list_if(COMPILER_RT_HAS_STD_C11_FLAG -std=c11 BUILTIN_CFLAGS)
+  append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ BUILTIN_CFLAGS)
   append_list_if(COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG 
-Werror=builtin-declaration-mismatch BUILTIN_CFLAGS)
 
   # Don't embed directives for picking any specific CRT
@@ -918,6 +920,8 @@ else ()
   SOURCES ${${arch}_SOURCES}
   DEFS ${BUILTIN_DEFS}
   CFLAGS ${BUILTIN_CFLAGS_${arch}}
+  C_STANDARD 11
+  CXX_STANDARD 17
   PARENT_TARGET builtins)
   cmake_pop_check_state()
 endif ()

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [AArch64AsmPrinter]Place jump tables into hot/unlikely-prefixed data sections for aarch64 (PR #126018)

2025-04-07 Thread Wei Xiao via llvm-branch-commits

https://github.com/williamweixiao approved this pull request.


https://github.com/llvm/llvm-project/pull/126018
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [ctxprof] Use the flattened contextual profile pre-thinlink (PR #134723)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-pgo

Author: Mircea Trofin (mtrofin)


Changes

Flatten the profile pre-thinlink so that ThinLTO has something to work with for 
the parts of the binary that aren't covered by contextual profiles. 
Post-thinlink, the flattener is re-run and will actually change profile info, 
but just for the modules containing contextual trees ("specialized modules"). 
For the rest, the flattener just yanks out the instrumentation.

---

Patch is 21.36 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/134723.diff


12 Files Affected:

- (modified) llvm/include/llvm/Analysis/CtxProfAnalysis.h (+1-1) 
- (modified) llvm/include/llvm/Analysis/ProfileSummaryInfo.h (+1-1) 
- (modified) 
llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h (+4-1) 
- (modified) llvm/lib/Analysis/CtxProfAnalysis.cpp (+28-10) 
- (modified) llvm/lib/Analysis/ProfileSummaryInfo.cpp (+5-1) 
- (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+4-2) 
- (modified) llvm/lib/Passes/PassRegistry.def (+3-1) 
- (modified) llvm/lib/Transforms/Instrumentation/PGOCtxProfFlattening.cpp 
(+23-14) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-and-annotate.ll 
(+39-22) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-check-path.ll (+3-3) 
- (modified) llvm/test/Analysis/CtxProfAnalysis/flatten-zero-path.ll (+2-2) 
- (removed) llvm/test/Transforms/PGOProfile/ctx-prof-use-prelink.ll (-44) 


``diff
diff --git a/llvm/include/llvm/Analysis/CtxProfAnalysis.h 
b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
index f7f65458c16a9..f5410238d9f42 100644
--- a/llvm/include/llvm/Analysis/CtxProfAnalysis.h
+++ b/llvm/include/llvm/Analysis/CtxProfAnalysis.h
@@ -59,7 +59,7 @@ class PGOContextualProfile {
 
   // True if this module is a post-thinlto module containing just functions
   // participating in one or more contextual profiles.
-  bool isInSpecializedModule() const { return IsInSpecializedModule; }
+  bool isInSpecializedModule() const;
 
   bool isFunctionKnown(const Function &F) const {
 return getDefinedFunctionGUID(F) != 0;
diff --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h 
b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
index ceae3e8a0ddb9..2e32878760b79 100644
--- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
+++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
@@ -64,7 +64,7 @@ class ProfileSummaryInfo {
   ProfileSummaryInfo(ProfileSummaryInfo &&Arg) = default;
 
   /// If no summary is present, attempt to refresh.
-  void refresh();
+  void refresh(std::unique_ptr &&Other = nullptr);
 
   /// Returns true if profile summary is available.
   bool hasProfileSummary() const { return Summary != nullptr; }
diff --git 
a/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h 
b/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h
index 0eab3aaf6fcad..96ff265af4371 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/PGOCtxProfFlattening.h
@@ -17,8 +17,11 @@ namespace llvm {
 
 class PGOCtxProfFlatteningPass
 : public PassInfoMixin {
+  const bool IsPreThinlink;
+
 public:
-  explicit PGOCtxProfFlatteningPass() = default;
+  explicit PGOCtxProfFlatteningPass(bool IsPreThinlink)
+  : IsPreThinlink(IsPreThinlink) {}
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
 };
 } // namespace llvm
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp 
b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index 3ae333b09d0ce..4042c87369462 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -39,6 +39,11 @@ static cl::opt 
PrintLevel(
   "just the yaml representation of the profile")),
 cl::desc("Verbosity level of the contextual profile printer pass."));
 
+static cl::opt ForceIsInSpecializedModule(
+"ctx-profile-force-is-specialized", cl::init(false),
+cl::desc("Treat the given module as-if it were containing the "
+ "post-thinlink module containing the root"));
+
 const char *AssignGUIDPass::GUIDMetadataName = "guid";
 
 PreservedAnalyses AssignGUIDPass::run(Module &M, ModuleAnalysisManager &MAM) {
@@ -278,6 +283,12 @@ void PGOContextualProfile::initIndex() {
   });
 }
 
+bool PGOContextualProfile::isInSpecializedModule() const {
+  return ForceIsInSpecializedModule.getNumOccurrences() > 0
+ ? ForceIsInSpecializedModule
+ : IsInSpecializedModule;
+}
+
 void PGOContextualProfile::update(Visitor V, const Function &F) {
   assert(isFunctionKnown(F));
   GlobalValue::GUID G = getDefinedFunctionGUID(F);
@@ -299,20 +310,27 @@ void PGOContextualProfile::visit(ConstVisitor V, const 
Function *F) const {
 
 const CtxProfFlatProfile PGOContextualProfile::flatten() const {
   CtxProfFlatProfile Flat;
+  auto Accummulate = +[](SmallVectorImpl &Into,
+ const

[llvm-branch-commits] [llvm] [ctxprof] Use the flattened contextual profile pre-thinlink (PR #134723)

2025-04-07 Thread Mircea Trofin via llvm-branch-commits

https://github.com/mtrofin ready_for_review 
https://github.com/llvm/llvm-project/pull/134723
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] release/20.x: [fatlto] Add coroutine passes when using FatLTO with ThinLTO (#134434) (PR #134711)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (llvmbot)


Changes

Backport 268c065eab06b81a0d7256ac62c0865b3781e236

Requested by: @nikic

---
Full diff: https://github.com/llvm/llvm-project/pull/134711.diff


2 Files Affected:

- (added) clang/test/CodeGenCoroutines/pr134409.cpp (+43) 
- (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+13) 


``diff
diff --git a/clang/test/CodeGenCoroutines/pr134409.cpp 
b/clang/test/CodeGenCoroutines/pr134409.cpp
new file mode 100644
index 0..142962d44ede4
--- /dev/null
+++ b/clang/test/CodeGenCoroutines/pr134409.cpp
@@ -0,0 +1,43 @@
+// An end-to-end test to make sure coroutine passes are added for thinlto.
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++23 
-ffat-lto-objects -flto=thin -emit-llvm %s -O3 -o - \
+// RUN:  | FileCheck %s
+
+#include "Inputs/coroutine.h"
+
+class BasicCoroutine {
+public:
+struct Promise {
+BasicCoroutine get_return_object() { return BasicCoroutine {}; }
+
+void unhandled_exception() noexcept { }
+
+void return_void() noexcept { }
+
+std::suspend_never initial_suspend() noexcept { return {}; }
+std::suspend_never final_suspend() noexcept { return {}; }
+};
+using promise_type = Promise;
+};
+
+// COM: match the embedded module, so we don't match something in it by 
accident.
+// CHECK: @llvm.embedded.object = {{.*}}
+// CHECK: @llvm.compiler.used = {{.*}}
+
+BasicCoroutine coro() {
+// CHECK: define {{.*}} void @_Z4corov() {{.*}} {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+// CHECK-NEXT: }
+co_return;
+}
+
+int main() {
+// CHECK: define {{.*}} i32 @main() {{.*}} {
+// CHECK-NEXT: entry:
+// CHECK-NEXT: tail call void @_Z4corov()
+// CHECK-NEXT: ret i32 0
+// CHECK-NEXT: }
+coro();
+}
+
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp 
b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 17ff3bd37884b..d195619f32d0b 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1660,6 +1660,19 @@ 
PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO,
   if (ThinLTO && PGOOpt && PGOOpt->Action == PGOOptions::SampleUse)
 MPM.addPass(buildThinLTODefaultPipeline(Level, /*ImportSummary=*/nullptr));
   else {
+// ModuleSimplification does not run the coroutine passes for
+// ThinLTOPreLink, so we need the coroutine passes to run for ThinLTO
+// builds, otherwise they will miscompile.
+if (ThinLTO) {
+  // TODO: replace w/ buildCoroWrapper() when it takes phase and level into
+  // consideration.
+  CGSCCPassManager CGPM;
+  CGPM.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
+  CGPM.addPass(CoroAnnotationElidePass());
+  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
+  MPM.addPass(CoroCleanupPass());
+}
+
 // otherwise, just use module optimization
 MPM.addPass(
 buildModuleOptimizationPipeline(Level, ThinOrFullLTOPhase::None));

``




https://github.com/llvm/llvm-project/pull/134711
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] OMPIRBuilder: Do not try to expand uses of ConstantData (PR #134584)

2025-04-07 Thread Shilei Tian via llvm-branch-commits

https://github.com/shiltian approved this pull request.

Seems to be very mechanical.

https://github.com/llvm/llvm-project/pull/134584
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] gn build: Add check-builtins target. (PR #134482)

2025-04-07 Thread Peter Collingbourne via llvm-branch-commits

https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/134482

>From bc8dda56bcfadc6d7312b53313159a978d71f4fb Mon Sep 17 00:00:00 2001
From: Peter Collingbourne 
Date: Fri, 4 Apr 2025 22:10:52 -0700
Subject: [PATCH] Remove unnecessary code

Created using spr 1.3.6-beta.1
---
 .../gn/secondary/compiler-rt/test/builtins/BUILD.gn | 13 -
 1 file changed, 13 deletions(-)

diff --git a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn 
b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
index 20618fb8da360..87848075a804e 100644
--- a/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/test/builtins/BUILD.gn
@@ -6,18 +6,6 @@ import("//llvm/utils/gn/build/toolchain/compiler.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 import("//llvm/version.gni")
 
-if (current_toolchain == host_toolchain) {
-  write_cmake_config("builtins_cfg") {
-input = "lit.site.cfg.py.in"
-output = "$target_gen_dir/lit.site.cfg.py"
-values = [
-  "BUILTINS_LIT_SOURCE_DIR=" + rebase_path("."),
-  "COMPILER_RT_BINARY_DIR=" + rebase_path("$root_gen_dir/compiler-rt"),
-  "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
-]
-  }
-}
-
 write_cmake_config("builtins_mode_cfg") {
   input = "Unit/lit.site.cfg.py.in"
   output =
@@ -54,7 +42,6 @@ write_cmake_config("builtins_mode_cfg") {
 if (current_toolchain != host_toolchain) {
   group("builtins_toolchain") {
 deps = [
-  ":builtins_cfg($host_toolchain)",
   ":builtins_mode_cfg",
   "//compiler-rt/include($host_toolchain)",
   "//compiler-rt/lib/builtins",

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

> Or, in the alternative, should we simply not set the ADA link if the target 
> section is empty? If an ADA section, it cannot actually be used for anything, 
> so do we even need to register it as ADA for a text section?

That is a simple solution, too. I am not sure if this works with the HLASM 
output. 

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] LICM: Avoid looking at use list of constant data (PR #134690)

2025-04-07 Thread Jay Foad via llvm-branch-commits


@@ -2294,10 +2294,14 @@ collectPromotionCandidates(MemorySSA *MSSA, 
AliasAnalysis *AA, Loop *L) {
   AliasSetTracker AST(BatchAA);
 
   auto IsPotentiallyPromotable = [L](const Instruction *I) {
-if (const auto *SI = dyn_cast(I))
-  return L->isLoopInvariant(SI->getPointerOperand());
-if (const auto *LI = dyn_cast(I))
-  return L->isLoopInvariant(LI->getPointerOperand());
+if (const auto *SI = dyn_cast(I)) {
+  const Value *PtrOp = SI->getPointerOperand();
+  return !isa(PtrOp) && L->isLoopInvariant(PtrOp);

jayfoad wrote:

Surely ConstantData is just constant, so it is guaranteed to be loop-invariant, 
so this should be:
```suggestion
  return isa(PtrOp) || L->isLoopInvariant(PtrOp);
```
And couldn't the ConstantData check be done inside of isLoopInvariant?

https://github.com/llvm/llvm-project/pull/134690
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect signing oracles (PR #134146)

2025-04-07 Thread Kristof Beyls via llvm-branch-commits


@@ -622,6 +628,40 @@ class MCPlusBuilder {
 return std::make_pair(getNoRegister(), getNoRegister());
   }
 
+  /// Analyzes if a pointer is checked to be valid by the end of BB.
+  ///
+  /// It is possible for pointer authentication instructions not to terminate
+  /// the program abnormally on authentication failure and return some *invalid
+  /// pointer* instead (like it is done on AArch64 when FEAT_FPAC is not
+  /// implemented). This might be enough to crash on invalid memory access
+  /// when the pointer is later used as the destination of load/store or branch
+  /// instruction. On the other hand, when the pointer is not used right away,
+  /// it may be important for the compiler to check the address explicitly not
+  /// to introduce signing or authentication oracle.
+  ///
+  /// If this function returns a (Reg, Inst) pair, then it is known that in any
+  /// successor of BB either
+  /// * Reg is trusted, provided it was safe-to-dereference before Inst, or

kbeyls wrote:

I think that "trusted" isn't defined before this sentence?
I'm assuming that "trusted" means "has been authenticated and program 
termination is guaranteed if authentication failed"?
Maybe we should have a specific term for that?
It seems to me that "trusted" might be a too-generic term, and becomes too 
confusing to use for this.
Off the top of my head, I'm thinking maybe "fully-authenticated" might work? 
Not sure if @jacobbramley has a better suggestion?

https://github.com/llvm/llvm-project/pull/134146
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

2025-04-07 Thread Kai Nacke via llvm-branch-commits


@@ -239,6 +298,63 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
 : OS(OS), Asm(Asm) {}
 
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+  if (Section.isSD()) {
+GOFFSymbol SD(Section.getName(), Section.getId(),
+  Section.getSDAttributes());
+writeSymbol(SD);
+  }
+
+  if (Section.isED()) {
+GOFFSymbol ED(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getEDAttributes());
+if (Section.requiresLength())
+  ED.SectionLength = Asm.getSectionAddressSize(Section);
+writeSymbol(ED);
+  }
+
+  if (Section.isPR()) {
+GOFFSymbol PR(Section.getName(), Section.getId(),
+  Section.getParent()->getId(), Section.getPRAttributes());
+PR.SectionLength = Asm.getSectionAddressSize(Section);
+if (Section.requiresNonZeroLength()) {

redstar wrote:

PR sections of size zero are allowed. However, if a text section is associated 
with an data section (the ADAEsdId field of the LD symbol of the text section 
is set to the PR symbol of the ADA) then the binder produces an error. This is 
a work-around for that situation.

https://github.com/llvm/llvm-project/pull/133799
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] SeparateConstOffsetFromGEP: Avoid looking at constant uses (PR #134685)

2025-04-07 Thread Florian Hahn via llvm-branch-commits

https://github.com/fhahn approved this pull request.

LGTM ,thanks!

https://github.com/llvm/llvm-project/pull/134685
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134688?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134692** https://app.graphite.dev/github/pr/llvm/llvm-project/134692?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134691** https://app.graphite.dev/github/pr/llvm/llvm-project/134691?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134690** https://app.graphite.dev/github/pr/llvm/llvm-project/134690?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134689** https://app.graphite.dev/github/pr/llvm/llvm-project/134689?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134688** https://app.graphite.dev/github/pr/llvm/llvm-project/134688?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134688?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134275** https://app.graphite.dev/github/pr/llvm/llvm-project/134275?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134274** https://app.graphite.dev/github/pr/llvm/llvm-project/134274?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/134688
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] LICM: Avoid looking at use list of constant data (PR #134690)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

arsenm wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134690?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134692** https://app.graphite.dev/github/pr/llvm/llvm-project/134692?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134691** https://app.graphite.dev/github/pr/llvm/llvm-project/134691?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134690** https://app.graphite.dev/github/pr/llvm/llvm-project/134690?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134690?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134689** https://app.graphite.dev/github/pr/llvm/llvm-project/134689?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134688** https://app.graphite.dev/github/pr/llvm/llvm-project/134688?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134275** https://app.graphite.dev/github/pr/llvm/llvm-project/134275?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134274** https://app.graphite.dev/github/pr/llvm/llvm-project/134274?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


https://github.com/llvm/llvm-project/pull/134690
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] SimplifyLibCalls: Skip sincospi optimization for ConstantData (PR #134688)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/134688
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] llvm-reduce: Support exotic terminators in instructions-to-return (PR #134794)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm ready_for_review 
https://github.com/llvm/llvm-project/pull/134794
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] llvm-reduce: Reduce with early return of arguments (PR #133627)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/133627

>From b77ade49fa87432ea501e1a50c2d4e59dedb2039 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 24 Mar 2025 14:33:36 +0700
Subject: [PATCH 1/2] llvm-reduce: Reduce with early return of arguments

Extend the instruction -> return reduction with one that inserts
return of function arguments. Not sure how useful this really is. This
has more freedom since we could insert the return anywhere in the function,
but this just inserts the return in the entry block.
---
 .../reduce-values-to-return-args.ll   | 77 +++
 ...-values-to-return-nonvoid-noncallee-use.ll |  2 +-
 .../llvm-reduce/reduce-values-to-return.ll|  2 +-
 llvm/tools/llvm-reduce/DeltaPasses.def|  5 +-
 .../deltas/ReduceValuesToReturn.cpp   | 42 +-
 .../llvm-reduce/deltas/ReduceValuesToReturn.h |  3 +-
 6 files changed, 124 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll

diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll
new file mode 100644
index 0..abbc643822033
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll
@@ -0,0 +1,77 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=arguments-to-return --test FileCheck --test-arg 
--check-prefixes=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefixes=RESULT %s < %t
+
+
+; INTERESTING-LABEL: @move_entry_block_use_argument_to_return(i32 %arg, ptr 
%ptr) {
+; INTERESTING: %arg
+
+; RESULT-LABEL: define i32 @move_entry_block_use_argument_to_return(
+; RESULT-NEXT: ret i32 %arg
+; RESULT-NEXT: }
+define void @move_entry_block_use_argument_to_return(i32 %arg, ptr %ptr) {
+  store i32 %arg, ptr %ptr
+  ret void
+}
+
+; INTERESTING-LABEL: @move_entry_block_use_argument_to_return_existing_ret(i32 
%arg, ptr %ptr) {
+; INTERESTING: %arg
+
+; RESULT-LABEL: define i32 
@move_entry_block_use_argument_to_return_existing_ret(
+; RESULT-NEXT: ret i32 %arg
+; RESULT-NEXT: }
+define i32 @move_entry_block_use_argument_to_return_existing_ret(i32 %arg, ptr 
%ptr) {
+  store i32 %arg, ptr %ptr
+  ret i32 0
+}
+
+; INTERESTING-LABEL: @move_phi_block_use_argument_to_return(i32 %arg, ptr 
%ptr0, ptr %ptr1, i1 %cond0, i1 %cond1) {
+; INTERESTING: %arg
+
+; RESULT-LABEL: define i32 @move_phi_block_use_argument_to_return(
+; RESULT-NEXT: entry:
+; RESULT-NEXT: ret i32 %arg
+define void @move_phi_block_use_argument_to_return(i32 %arg, ptr %ptr0, ptr 
%ptr1, i1 %cond0, i1 %cond1) {
+entry:
+  br i1 %cond0, label %bb0, label %bb1
+
+bb0:
+  %phi = phi i32 [ %arg, %entry ], [ 123, %bb1 ]
+  store i32 %arg, ptr %ptr0
+  store i32 %phi, ptr %ptr1
+  br label %bb1
+
+bb1:
+  br i1 %cond1, label %bb0, label %bb2
+
+bb2:
+  ret void
+}
+
+; INTERESTING-LABEL: define {{.*}} @keep_second_arg(i32 %arg0, ptr %arg1) {
+; INTERESTING: %arg1
+
+; RESULT-LABEL: define ptr @keep_second_arg(
+; RESULT-NEXT: ret ptr %arg1
+; RESULT-NEXT: }
+define void @keep_second_arg(i32 %arg0, ptr %arg1) {
+  store i32 %arg0, ptr %arg1
+  ret void
+}
+
+; INTERESTING-LABEL: @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) {
+; INTERESTING: i32 %arg2
+
+; RESULT-LABEL: define i32 @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 
%arg2) {
+; RESULT-NEXT: entry:
+; RESULT-NEXT: ret i32 %arg2
+define void @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) {
+entry:
+  br i1 %arg0, label %bb0, label %bb1
+
+bb0:
+  store i32 %arg2, ptr %arg1
+  ret void
+
+bb1:
+  ret void
+}
diff --git 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll
index 215ea97a8be91..11166479318c6 100644
--- 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll
+++ 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll
@@ -1,7 +1,7 @@
 ; Make sure we don't break on non-callee uses of funtions with a
 ; non-void return type.
 
-; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=values-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=instructions-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
 ; RUN: FileCheck --check-prefix=RESULT %s < %t
 
 ; INTERESTING-LABEL: @interesting(
diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll
index 0c36db8ebc278..2af87aad05169 100644
--- a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll
@@ -1,7 +1,7 @@
 ; Test that llvm-reduce can move intermediate values by inserting
 ;

[llvm-branch-commits] [llvm] llvm-reduce: Change function return types if function is not called (PR #134035)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/134035

>From 11103055b02ead4e9d843a7e4e70b2ec22210485 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 2 Apr 2025 11:45:24 +0700
Subject: [PATCH 1/4] llvm-reduce: Change function return types if function is
 not called

Extend the early return on value reduction to mutate the function return
type if the function has no call uses. This could be generalized to rewrite
cases where all callsites are used, but it turns out that complicates the
visitation order given we try to compute all opportunities up front.

This is enough to cleanup the common case where we end up with one
function with a return of an uninteresting constant.
---
 ...reduce-values-to-return-new-return-type.ll | 95 +++
 .../llvm-reduce/reduce-values-to-return.ll| 20 +++-
 .../deltas/ReduceValuesToReturn.cpp   |  7 +-
 3 files changed, 118 insertions(+), 4 deletions(-)
 create mode 100644 
llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll

diff --git 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
new file mode 100644
index 0..9ddbbe3def44f
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-new-return-type.ll
@@ -0,0 +1,95 @@
+; Test that llvm-reduce can move intermediate values by inserting
+; early returns when the function already has a different return type
+;
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=instructions-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=RESULT %s < %t
+
+
+@gv = global i32 0, align 4
+@ptr_array = global [2 x ptr] [ptr 
@inst_to_return_has_different_type_but_no_func_call_use,
+   ptr @multiple_callsites_wrong_return_type]
+
+; Should rewrite this return from i64 to i32 since the function has no
+; uses.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_no_func_call_use(
+; RESULT-LABEL: define i32 
@inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+; RESULT-NEXT: %load = load i32, ptr %arg, align 4
+; RESULT-NEXT: ret i32 %load
+define i64 @inst_to_return_has_different_type_but_no_func_call_use(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @callsite_different_type_unused_0(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-NEXT: %load = load i32, ptr %arg
+; RESULT-NEXT: store i32 %load, ptr @gv
+; RESULT-NEXT: ret i64 0
+define void @callsite_different_type_unused_0(ptr %arg) {
+  %unused0 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr %arg)
+  %unused1 = call i64 
@inst_to_return_has_different_type_but_call_result_unused(ptr null)
+  ret void
+}
+
+; TODO: Could rewrite this return from i64 to i32 since the callsite is unused.
+; INTERESTING-LABEL: @inst_to_return_has_different_type_but_call_result_unused(
+; RESULT-LABEL: define i64 
@inst_to_return_has_different_type_but_call_result_unused(
+; RESULT: ret i64 0
+define i64 @inst_to_return_has_different_type_but_call_result_unused(ptr %arg) 
{
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @multiple_callsites_wrong_return_type(
+; RESULT-LABEL: define i64 @multiple_callsites_wrong_return_type(
+; RESULT: ret i64 0
+define i64 @multiple_callsites_wrong_return_type(ptr %arg) {
+  %load = load i32, ptr %arg
+  store i32 %load, ptr @gv
+  ret i64 0
+}
+
+; INTERESTING-LABEL: @unused_with_wrong_return_types(
+; RESULT-LABEL: define i64 @unused_with_wrong_return_types(
+; RESULT-NEXT: %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr 
%arg)
+; RESULT-NEXT: ret i64 %unused0
+define void @unused_with_wrong_return_types(ptr %arg) {
+  %unused0 = call i64 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused1 = call i32 @multiple_callsites_wrong_return_type(ptr %arg)
+  %unused2 = call ptr @multiple_callsites_wrong_return_type(ptr %arg)
+  ret void
+}
+
+; INTERESTING-LABEL: @multiple_returns_wrong_return_type(
+; INTERESTING: %load0 = load i32,
+
+; RESULT-LABEL: define i32 @multiple_returns_wrong_return_type(
+; RESULT: ret i32
+; RESULT: ret i32
+; RESULT: ret i32
+define i32 @multiple_returns_wrong_return_type(ptr %arg, i1 %cond, i32 %arg2) {
+entry:
+  br i1 %cond, label %bb0, label %bb1
+
+bb0:
+  %load0 = load i32, ptr %arg
+  store i32 %load0, ptr @gv
+  ret i32 234
+
+bb1:
+  ret i32 %arg2
+
+bb2:
+  ret i32 34
+}
+
+; INTERESTING-LABEL: @call_multiple_returns_wrong_return_type(
+; RESULT-LABEL: define <2 x i32> @call_multiple_returns_wrong_return_type(
+; RESULT-NEXT: %unused = call <2 x i32> @multiple_returns_wrong_return_type(
+; RESULT-NEXT: ret <2 x i32> %unused
+define void @call_multiple_returns_wrong_return_type

[llvm-branch-commits] [llvm] llvm-reduce: Reduce with early return of arguments (PR #133627)

2025-04-07 Thread Matt Arsenault via llvm-branch-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/133627

>From b77ade49fa87432ea501e1a50c2d4e59dedb2039 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Mon, 24 Mar 2025 14:33:36 +0700
Subject: [PATCH 1/2] llvm-reduce: Reduce with early return of arguments

Extend the instruction -> return reduction with one that inserts
return of function arguments. Not sure how useful this really is. This
has more freedom since we could insert the return anywhere in the function,
but this just inserts the return in the entry block.
---
 .../reduce-values-to-return-args.ll   | 77 +++
 ...-values-to-return-nonvoid-noncallee-use.ll |  2 +-
 .../llvm-reduce/reduce-values-to-return.ll|  2 +-
 llvm/tools/llvm-reduce/DeltaPasses.def|  5 +-
 .../deltas/ReduceValuesToReturn.cpp   | 42 +-
 .../llvm-reduce/deltas/ReduceValuesToReturn.h |  3 +-
 6 files changed, 124 insertions(+), 7 deletions(-)
 create mode 100644 llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll

diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll
new file mode 100644
index 0..abbc643822033
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return-args.ll
@@ -0,0 +1,77 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=arguments-to-return --test FileCheck --test-arg 
--check-prefixes=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefixes=RESULT %s < %t
+
+
+; INTERESTING-LABEL: @move_entry_block_use_argument_to_return(i32 %arg, ptr 
%ptr) {
+; INTERESTING: %arg
+
+; RESULT-LABEL: define i32 @move_entry_block_use_argument_to_return(
+; RESULT-NEXT: ret i32 %arg
+; RESULT-NEXT: }
+define void @move_entry_block_use_argument_to_return(i32 %arg, ptr %ptr) {
+  store i32 %arg, ptr %ptr
+  ret void
+}
+
+; INTERESTING-LABEL: @move_entry_block_use_argument_to_return_existing_ret(i32 
%arg, ptr %ptr) {
+; INTERESTING: %arg
+
+; RESULT-LABEL: define i32 
@move_entry_block_use_argument_to_return_existing_ret(
+; RESULT-NEXT: ret i32 %arg
+; RESULT-NEXT: }
+define i32 @move_entry_block_use_argument_to_return_existing_ret(i32 %arg, ptr 
%ptr) {
+  store i32 %arg, ptr %ptr
+  ret i32 0
+}
+
+; INTERESTING-LABEL: @move_phi_block_use_argument_to_return(i32 %arg, ptr 
%ptr0, ptr %ptr1, i1 %cond0, i1 %cond1) {
+; INTERESTING: %arg
+
+; RESULT-LABEL: define i32 @move_phi_block_use_argument_to_return(
+; RESULT-NEXT: entry:
+; RESULT-NEXT: ret i32 %arg
+define void @move_phi_block_use_argument_to_return(i32 %arg, ptr %ptr0, ptr 
%ptr1, i1 %cond0, i1 %cond1) {
+entry:
+  br i1 %cond0, label %bb0, label %bb1
+
+bb0:
+  %phi = phi i32 [ %arg, %entry ], [ 123, %bb1 ]
+  store i32 %arg, ptr %ptr0
+  store i32 %phi, ptr %ptr1
+  br label %bb1
+
+bb1:
+  br i1 %cond1, label %bb0, label %bb2
+
+bb2:
+  ret void
+}
+
+; INTERESTING-LABEL: define {{.*}} @keep_second_arg(i32 %arg0, ptr %arg1) {
+; INTERESTING: %arg1
+
+; RESULT-LABEL: define ptr @keep_second_arg(
+; RESULT-NEXT: ret ptr %arg1
+; RESULT-NEXT: }
+define void @keep_second_arg(i32 %arg0, ptr %arg1) {
+  store i32 %arg0, ptr %arg1
+  ret void
+}
+
+; INTERESTING-LABEL: @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) {
+; INTERESTING: i32 %arg2
+
+; RESULT-LABEL: define i32 @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 
%arg2) {
+; RESULT-NEXT: entry:
+; RESULT-NEXT: ret i32 %arg2
+define void @multi_void_return_arg(i1 %arg0, ptr %arg1, i32 %arg2) {
+entry:
+  br i1 %arg0, label %bb0, label %bb1
+
+bb0:
+  store i32 %arg2, ptr %arg1
+  ret void
+
+bb1:
+  ret void
+}
diff --git 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll
index 215ea97a8be91..11166479318c6 100644
--- 
a/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll
+++ 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return-nonvoid-noncallee-use.ll
@@ -1,7 +1,7 @@
 ; Make sure we don't break on non-callee uses of funtions with a
 ; non-void return type.
 
-; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=values-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
+; RUN: llvm-reduce --abort-on-invalid-reduction 
--delta-passes=instructions-to-return --test FileCheck --test-arg 
--check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t
 ; RUN: FileCheck --check-prefix=RESULT %s < %t
 
 ; INTERESTING-LABEL: @interesting(
diff --git a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll 
b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll
index 0c36db8ebc278..2af87aad05169 100644
--- a/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll
+++ b/llvm/test/tools/llvm-reduce/reduce-values-to-return.ll
@@ -1,7 +1,7 @@
 ; Test that llvm-reduce can move intermediate values by inserting
 ;

[llvm-branch-commits] [llvm] 1fcb75a - Revert "[SLP]Support revectorization of the previously vectorized scalars"

2025-04-07 Thread via llvm-branch-commits

Author: Alexander Kornienko
Date: 2025-04-07T12:04:36+02:00
New Revision: 1fcb75a5c050228b31eaeebdf56a47f53998b27b

URL: 
https://github.com/llvm/llvm-project/commit/1fcb75a5c050228b31eaeebdf56a47f53998b27b
DIFF: 
https://github.com/llvm/llvm-project/commit/1fcb75a5c050228b31eaeebdf56a47f53998b27b.diff

LOG: Revert "[SLP]Support revectorization of the previously vectorized scalars"

This reverts commit 0e3049c562ccdea288c3b1f3b3d1ce5992d284b0.

Added: 


Modified: 
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/AArch64/reused-scalar-repeated-in-node.ll
llvm/test/Transforms/SLPVectorizer/AArch64/transpose-inseltpoison.ll
llvm/test/Transforms/SLPVectorizer/AArch64/transpose.ll
llvm/test/Transforms/SLPVectorizer/AArch64/vec3-reorder-reshuffle.ll
llvm/test/Transforms/SLPVectorizer/X86/cast-operand-extracted.ll
llvm/test/Transforms/SLPVectorizer/X86/scatter-vectorize-reorder.ll
llvm/test/Transforms/SLPVectorizer/X86/vec3-reorder-reshuffle.ll

Removed: 




diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp 
b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index e2031df810573..b58cf19d9b28a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3783,6 +3783,11 @@ class BoUpSLP {
 if (isa(V))
   continue;
 auto It = ScalarToTreeEntries.find(V);
+assert(
+(It == ScalarToTreeEntries.end() ||
+ (It->getSecond().size() == 1 && It->getSecond().front() == Last) 
||
+ doesNotNeedToBeScheduled(V)) &&
+"Scalar already in tree!");
 if (It == ScalarToTreeEntries.end()) {
   
ScalarToTreeEntries.try_emplace(V).first->getSecond().push_back(Last);
   (void)Processed.insert(V);
@@ -4042,9 +4047,6 @@ class BoUpSLP {
   private:
 /// Used for getting a "good" final ordering of instructions.
 int SchedulingPriority = 0;
-/// True if this instruction (or bundle) is scheduled (or considered as
-/// scheduled in the dry-run).
-bool IsScheduled = false;
 /// The kind of the ScheduleEntity.
 const Kind K = Kind::ScheduleData;
 
@@ -4058,10 +4060,6 @@ class BoUpSLP {
 return SD->isReady();
   return cast(this)->isReady();
 }
-/// Gets/sets if the bundle is scheduled.
-bool isScheduled() const { return IsScheduled; }
-void setScheduled(bool Scheduled) { IsScheduled = Scheduled; }
-
 static bool classof(const ScheduleEntity *) { return true; }
   };
 
@@ -4134,6 +4132,10 @@ class BoUpSLP {
   IsScheduled = false;
 }
 
+/// Gets/sets if the bundle is scheduled.
+bool isScheduled() const { return IsScheduled; }
+void setScheduled(bool Scheduled) { IsScheduled = Scheduled; }
+
 /// Gets the number of unscheduled dependencies.
 int getUnscheduledDeps() const { return UnscheduledDeps; }
 /// Gets the number of dependencies.
@@ -4208,6 +4210,10 @@ class BoUpSLP {
 /// for scheduling.
 /// Note that this is negative as long as Dependencies is not calculated.
 int UnscheduledDeps = InvalidDeps;
+
+/// True if this instruction is scheduled (or considered as scheduled in 
the
+/// dry-run).
+bool IsScheduled = false;
   };
 
 #ifndef NDEBUG
@@ -4252,6 +4258,11 @@ class BoUpSLP {
   }
 }
 
+bool isScheduled() const {
+  return all_of(Bundle,
+[](const ScheduleData *SD) { return SD->isScheduled(); });
+}
+
 /// Returns the number of unscheduled dependencies in the bundle.
 int unscheduledDepsInBundle() const {
   assert(*this && "bundle must not be empty");
@@ -4508,22 +4519,12 @@ class BoUpSLP {
 ProcessBundleMember(SD, nullptr);
   } else {
 ScheduleBundle &Bundle = *cast(Data);
-Bundle.setScheduled(/*Scheduled=*/true);
+for_each(Bundle.getBundle(), [](ScheduleData *SD) {
+  SD->setScheduled(/*Scheduled=*/true);
+});
 LLVM_DEBUG(dbgs() << "SLP:   schedule " << Bundle << "\n");
-auto AreAllBundlesScheduled = [&](const ScheduleData *SD) {
-  ArrayRef SDBundles =
-  getScheduleBundles(SD->getInst());
-  return !SDBundles.empty() &&
- all_of(SDBundles, [&](const ScheduleBundle *SDBundle) {
-   return SDBundle->isScheduled();
- });
-};
-for (ScheduleData *SD : Bundle.getBundle()) {
-  if (AreAllBundlesScheduled(SD)) {
-SD->setScheduled(/*Scheduled=*/true);
-ProcessBundleMember(SD, &Bundle);
-  }
-}
+for (ScheduleData *SD : Bundle.getBundle())
+  ProcessBundleMember(SD, &Bundle);
   }
 }
 
@@ -4554,11 +4555,10 @@ class BoUpSLP {
 SD->verify();
   }
 
-  assert(all_of(ReadyInsts,
-[](const Schedul

[llvm-branch-commits] [clang] [KeyInstr][Clang] Catch variable init atom (PR #134641)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134641.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/ItaniumCXXABI.cpp (+1) 
- (added) clang/test/KeyInstructions/try-catch.cpp (+20) 


``diff
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 77e995b4c933a..b3f1e208fa318 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -5051,6 +5051,7 @@ void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF,
 
   // Emit the local.
   CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam);
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF), 
S->getBeginLoc());
   CGF.EmitAutoVarCleanups(var);
 }
diff --git a/clang/test/KeyInstructions/try-catch.cpp 
b/clang/test/KeyInstructions/try-catch.cpp
new file mode 100644
index 0..3d1080aca2f07
--- /dev/null
+++ b/clang/test/KeyInstructions/try-catch.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - -fexceptions \
+// RUN: | FileCheck %s
+
+void except() {
+  // FIXME(OCH): Should `store i32 32, ptr %exception` be key?
+  throw 32;
+}
+
+void attempt() {
+  try { except(); }
+// CHECK: catch:
+// CHECK: %4 = call ptr @__cxa_begin_catch(ptr %exn)
+// CHECK: %5 = load i32{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store i32 %5, ptr %e{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: call void @__cxa_end_catch()
+  catch (int e) { }
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134641
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign vector element atom (PR #134649)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134649.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+3-2) 
- (modified) clang/test/KeyInstructions/agg.c (+9-1) 


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a5e113a1a4397..bacf5730065c5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2456,8 +2456,9 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
 Vec = Builder.CreateBitCast(Vec, IRStoreTy);
   }
 
-  Builder.CreateStore(Vec, Dst.getVectorAddress(),
-  Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(Vec, Dst.getVectorAddress(),
+Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, Vec);
   return;
 }
 
diff --git a/clang/test/KeyInstructions/agg.c b/clang/test/KeyInstructions/agg.c
index 177e1ea8b9fc1..c9d3857043915 100644
--- a/clang/test/KeyInstructions/agg.c
+++ b/clang/test/KeyInstructions/agg.c
@@ -1,9 +1,10 @@
 // RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
-// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o - \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
+__attribute__((ext_vector_type(1))) char c;
 typedef struct { int a, b, c; } Struct;
 void fun(Struct a) {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
@@ -11,7 +12,14 @@ void fun(Struct a) {
 
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G2R1:!.*]]
   b = a;
+
+// CHECK: %2 = load <1 x i8>, ptr @c
+// CHECK: %vecins = insertelement <1 x i8> %2, i8 0, i32 0, !dbg [[G3R2:!.*]]
+// CHECK: store <1 x i8> %vecins, ptr @c{{.*}}, !dbg [[G3R1:!.*]]
+  c[0] = 0;
 }
 
 // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
 // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134649
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] While stmt atom (PR #134645)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134645

See test comment for possible future improvement.

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

>From 38f3eec43ee39196ee24800daeb1abe09f989b18 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 18:49:32 +0100
Subject: [PATCH] [KeyInstr][Clang] While stmt atom

See test comment for possible future improvement.

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/lib/CodeGen/CGStmt.cpp   |  9 +++-
 clang/test/KeyInstructions/while.c | 34 ++
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/KeyInstructions/while.c

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index e46cfb433ab89..d9fd406ad64ee 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1130,7 +1130,14 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
 if (!Weights && CGM.getCodeGenOpts().OptimizationLevel)
   BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
   BoolCondVal, Stmt::getLikelihood(S.getBody()));
-Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock, Weights);
+auto *I = Builder.CreateCondBr(BoolCondVal, LoopBody, ExitBlock, Weights);
+// Key Instructions: Emit the condition and branch as separate atoms to
+// match existing loop stepping behaviour. FIXME: We could have the branch
+// as the backup location for the condition, which would probably be a
+// better experience. Explore this later.
+if (auto *I = dyn_cast(BoolCondVal))
+  addInstToNewSourceAtom(I, nullptr);
+addInstToNewSourceAtom(I, nullptr);
 
 if (ExitBlock != LoopExit.getBlock()) {
   EmitBlock(ExitBlock);
diff --git a/clang/test/KeyInstructions/while.c 
b/clang/test/KeyInstructions/while.c
new file mode 100644
index 0..f1bb91520315a
--- /dev/null
+++ b/clang/test/KeyInstructions/while.c
@@ -0,0 +1,34 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Perennial quesiton: should the `dec` be in its own source atom or not
+// (currently it is).
+
+// We've made the cmp and br separate source atoms for now, to match existing
+// behaviour in this case:
+// 1. while (
+// 2.   int i = --End
+// 3.   ) {
+// 4.   useValue(i);
+// 5. }
+// Without Key Instructions we go: 2, 1[, 4, 2, 1]+
+// Without separating cmp and br with Key Instructions we'd get:
+// 1[, 4, 1]+. If we made the cmp higher precedence than the
+// br and had them in the same group, we could get:
+// 2, [4, 2]+ which might be nicer. FIXME: do that later.
+
+void a(int A) {
+// CHECK: %dec = add nsw i32 %0, -1, !dbg [[G1R2:!.*]]
+// CHECK: store i32 %dec, ptr %A.addr{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: %tobool = icmp ne i32 %dec, 0, !dbg [[G2R1:!.*]]
+// CHECK: br i1 %tobool, label %while.body, label %while.end, !dbg [[G3R1:!.*]]
+while (--A) { };
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Add ApplyAtomGroup (PR #134632)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** http

[llvm-branch-commits] [clang] [KeyInstr] Complex assignment atoms (PR #134638)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134638

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

>From 8ce070ebddf8c59e58a8be3983add5b01728f50f Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 13:36:59 +0100
Subject: [PATCH] [KeyInstr] Complex assignment atoms

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/lib/CodeGen/CGExprComplex.cpp  | 10 +--
 clang/test/KeyInstructions/complex.c | 40 
 2 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/KeyInstructions/complex.c

diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index a7c8b96da6853..ff960e76e8693 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -456,8 +456,12 @@ void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy 
Val, LValue lvalue,
   Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
   Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
 
-  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
-  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
+  auto *R =
+  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
+  CGF.addInstToCurrentSourceAtom(R, Val.first);
+  auto *I =
+  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
+  CGF.addInstToCurrentSourceAtom(I, Val.second);
 }
 
 
@@ -1204,6 +1208,7 @@ LValue ComplexExprEmitter::
 EmitCompoundAssignLValue(const CompoundAssignOperator *E,
   ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
  RValue &Val) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   TestAndClearIgnoreReal();
   TestAndClearIgnoreImag();
   QualType LHSTy = E->getLHS()->getType();
@@ -1351,6 +1356,7 @@ LValue ComplexExprEmitter::EmitBinAssignLValue(const 
BinaryOperator *E,
 }
 
 ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   ComplexPairTy Val;
   LValue LV = EmitBinAssignLValue(E, Val);
 
diff --git a/clang/test/KeyInstructions/complex.c 
b/clang/test/KeyInstructions/complex.c
new file mode 100644
index 0..b97314e815bdc
--- /dev/null
+++ b/clang/test/KeyInstructions/complex.c
@@ -0,0 +1,40 @@
+
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm 
-o - -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o 
- -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+_Complex float ci;
+void test() {
+// CHECK: %ci.real = load float, ptr @ci{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: %ci.imag = load float, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G1R2]]
+// CHECK: store float %ci.real, ptr %lc.realp{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: store float %ci.imag, ptr %lc.imagp{{.*}}, !dbg [[G1R1]]
+  _Complex float lc = ci;
+
+// CHECK: %ci.real1 = load float, ptr @ci{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: %ci.imag2 = load float, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R2]]
+// CHECK: store float %ci.real1, ptr @ci{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: store float %ci.imag2, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R1]]
+  ci = ci;
+
+// CHECK: %add.r = fadd float %ci.real5, %ci.real3, !dbg [[G3R2:!.*]]
+// CHECK: %add.i = fadd float %ci.imag6, %ci.imag4, !dbg [[G3R2]]
+// CHECK: store float %add.r, ptr @ci{{.*}}, !dbg [[G3R1:!.*]]
+// CHECK: store float %add.i, ptr getelementptr inbounds nuw ({ float, float 
}, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G3R1]]
+  ci += ci;
+
+// CHECK: %add = fadd float %0, %1

[llvm-branch-commits] [clang] [KeyInstr][Clang] Assignment atom group (PR #134637)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134637

[KeyInstr][Clang] Assignment atom group

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

[KeyInstr][Clang] Multiple assignment  (x = y = z)

Compound assign

Pre/Post Inc/Dec

Rename test & run C & C++

>From cdf3eef4a2c3d46687b6b2e49d02b7e7152f2d5e Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Wed, 2 Apr 2025 18:01:48 +0100
Subject: [PATCH 1/5] [KeyInstr][Clang] Assignment atom group

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/lib/CodeGen/CGExpr.cpp  | 9 +
 clang/test/KeyInstructions/assign.cpp | 9 +
 2 files changed, 18 insertions(+)
 create mode 100644 clang/test/KeyInstructions/assign.cpp

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a00a8ba2cd5cb..7408c498b3a1a 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5814,6 +5814,15 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
 
   assert(E->getOpcode() == BO_Assign && "unexpected binary l-value");
 
+  // This covers both LHS and RHS expressions, though nested RHS
+  // expressions may get subsequently separately grouped.
+  // FIXME(OCH): Not clear yet if we've got fine enough control
+  // to pick and choose when we need to. Currently looks ok:
+  // a = b = c  -> Two atoms.
+  // x = new(1) -> One atom (for both addr store and value store).
+  // Complex and agg assignment -> One atom.
+  ApplyAtomGroup Grp(getDebugInfo());
+
   // Note that in all of these cases, __block variables need the RHS
   // evaluated first just in case the variable gets moved by the RHS.
 
diff --git a/clang/test/KeyInstructions/assign.cpp 
b/clang/test/KeyInstructions/assign.cpp
new file mode 100644
index 0..b09137430156f
--- /dev/null
+++ b/clang/test/KeyInstructions/assign.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - 
-Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+unsigned long long g;
+void fun() { g = 0; }
+
+// CHECK: store i64 0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

>From b6f42ab8be5aee4c27e5f540b203e40eb7decc94 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Wed, 2 Apr 2025 18:27:59 +0100
Subject: [PATCH 2/5] [KeyInstr][Clang] Multiple assignment  (x = y = z)

---
 clang/lib/CodeGen/CGExprScalar.cpp|  1 +
 clang/test/KeyInstructions/assign.cpp | 18 --
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 140a12d384502..0019edf3e7552 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4973,6 +4973,7 @@ llvm::Value 
*CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment(
 }
 
 Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   bool Ignore = TestAndClearIgnoreResultAssign();
 
   Value *RHS;
diff --git a/clang/test/KeyInstructions/assign.cpp 
b/clang/test/KeyInstructions/assign.cpp
index b09137430156f..d50062d21935b 100644
--- a/clang/test/KeyInstructions/assign.cpp
+++ b/clang/test/KeyInstructions/assign.cpp
@@ -2,8 +2,22 @@
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
 unsigned long long g;
-void fun() { g = 0; }
-
+void fun() {
 // CHECK: store i64 0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+g = 0;
+
+// Treat the two assignments as two atoms.
+//
+// FIXME: Because of the atomGroup implementation the load can only be
+// associated with one of the two stores, despite being a good backup
+// loction for both.
+// CHECK-NEXT: %0 = load i64, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G3R1:!.*]]
+// CHECK-NEXT: store i64 %0, ptr 

[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect signing oracles (PR #134146)

2025-04-07 Thread Kristof Beyls via llvm-branch-commits

https://github.com/kbeyls edited 
https://github.com/llvm/llvm-project/pull/134146
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Scalar init atom (PR #134633)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134633

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

>From 29d5428307acc1493f2bb2819b627688b4917c07 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 14:50:41 +0100
Subject: [PATCH] [KeyInstr][Clang] Scalar init atom

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/lib/CodeGen/CGDecl.cpp |  1 +
 clang/lib/CodeGen/CGExpr.cpp |  2 ++
 clang/test/KeyInstructions/init-scalar.c | 19 +++
 3 files changed, 22 insertions(+)
 create mode 100644 clang/test/KeyInstructions/init-scalar.c

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index eab1ebfb2369b..96d217b0a13cc 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1921,6 +1921,7 @@ void CodeGenFunction::EmitAutoVarInit(const 
AutoVarEmission &emission) {
 
   const VarDecl &D = *emission.Variable;
   auto DL = ApplyDebugLocation::CreateDefaultArtificial(*this, 
D.getLocation());
+  ApplyAtomGroup Grp(getDebugInfo());
   QualType type = D.getType();
 
   // If this local has an initializer, emit it now.
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 5943ff9294e1a..a00a8ba2cd5cb 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2180,6 +2180,8 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value 
*Value, Address Addr,
   }
 
   llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
+  addInstToCurrentSourceAtom(Store, Value);
+
   if (isNontemporal) {
 llvm::MDNode *Node =
 llvm::MDNode::get(Store->getContext(),
diff --git a/clang/test/KeyInstructions/init-scalar.c 
b/clang/test/KeyInstructions/init-scalar.c
new file mode 100644
index 0..c212c2a4fd623
--- /dev/null
+++ b/clang/test/KeyInstructions/init-scalar.c
@@ -0,0 +1,19 @@
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm 
-o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+void a() {
+// CHECK: store i32 0, ptr %A{{.*}}, !dbg [[G1R1:!.*]]
+int A = 0;
+// CHECK: %add = add {{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %add, ptr %B, align 4, !dbg [[G2R1:!.*]]
+int B = 2 * A + 1;
+// CHECK-TODO: ret{{.*}}, !dbg [[G3R1:!.*]]
+}
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK-TODO: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect signing oracles (PR #134146)

2025-04-07 Thread Kristof Beyls via llvm-branch-commits


@@ -622,6 +628,40 @@ class MCPlusBuilder {
 return std::make_pair(getNoRegister(), getNoRegister());
   }
 
+  /// Analyzes if a pointer is checked to be valid by the end of BB.
+  ///
+  /// It is possible for pointer authentication instructions not to terminate
+  /// the program abnormally on authentication failure and return some *invalid
+  /// pointer* instead (like it is done on AArch64 when FEAT_FPAC is not
+  /// implemented). This might be enough to crash on invalid memory access
+  /// when the pointer is later used as the destination of load/store or branch
+  /// instruction. On the other hand, when the pointer is not used right away,
+  /// it may be important for the compiler to check the address explicitly not
+  /// to introduce signing or authentication oracle.

kbeyls wrote:

either "a signing..." or "oracles"?

https://github.com/llvm/llvm-project/pull/134146
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect signing oracles (PR #134146)

2025-04-07 Thread Kristof Beyls via llvm-branch-commits


@@ -622,6 +628,40 @@ class MCPlusBuilder {
 return std::make_pair(getNoRegister(), getNoRegister());
   }
 
+  /// Analyzes if a pointer is checked to be valid by the end of BB.

kbeyls wrote:

"a pointer being valid" could mean many things in this target-agnostic header 
file.
Maybe the words "pointer authentication" and "correctly authenticated" or 
something similar should be used in this first sentence?
Maybe
`/// Analyzes if this basic block fully authenticates a signed pointer, 
including triggering program termination when invalidly signed` or something 
along those lines?

https://github.com/llvm/llvm-project/pull/134146
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect signing oracles (PR #134146)

2025-04-07 Thread Kristof Beyls via llvm-branch-commits

https://github.com/kbeyls commented:

I only reviewed a small part of this PR so far, but will probably not have more 
time today or tomorrow to review further, so I thought I'd share my thoughts so 
far.

I think that the documentation at 
https://github.com/llvm/llvm-project/blob/main/bolt/docs/BinaryAnalysis.md 
should probably be updated to describe the added functionality in this, and 
maybe also some earlier, PRs.

https://github.com/llvm/llvm-project/pull/134146
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign vector element atom (PR #134649)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134649

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

>From 85936471fcc02aecc188c6e7ec11f12dee407efb Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 21:56:37 +0100
Subject: [PATCH] [KeyInstr][Clang] Assign vector element atom

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/lib/CodeGen/CGExpr.cpp |  5 +++--
 clang/test/KeyInstructions/agg.c | 10 +-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a5e113a1a4397..bacf5730065c5 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2456,8 +2456,9 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
 Vec = Builder.CreateBitCast(Vec, IRStoreTy);
   }
 
-  Builder.CreateStore(Vec, Dst.getVectorAddress(),
-  Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(Vec, Dst.getVectorAddress(),
+Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, Vec);
   return;
 }
 
diff --git a/clang/test/KeyInstructions/agg.c b/clang/test/KeyInstructions/agg.c
index 177e1ea8b9fc1..c9d3857043915 100644
--- a/clang/test/KeyInstructions/agg.c
+++ b/clang/test/KeyInstructions/agg.c
@@ -1,9 +1,10 @@
 // RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
-// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o - \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
+__attribute__((ext_vector_type(1))) char c;
 typedef struct { int a, b, c; } Struct;
 void fun(Struct a) {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
@@ -11,7 +12,14 @@ void fun(Struct a) {
 
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G2R1:!.*]]
   b = a;
+
+// CHECK: %2 = load <1 x i8>, ptr @c
+// CHECK: %vecins = insertelement <1 x i8> %2, i8 0, i32 0, !dbg [[G3R2:!.*]]
+// CHECK: store <1 x i8> %vecins, ptr @c{{.*}}, !dbg [[G3R1:!.*]]
+  c[0] = 0;
 }
 
 // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
 // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Member initalization atom (PR #134640)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign matrix element atom (PR #134650)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134650

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

>From eb1927780336aa90ac66a2e858cfde411a559216 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 22:05:32 +0100
Subject: [PATCH] [KeyInstr][Clang] Assign matrix element atom

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/lib/CodeGen/CGExpr.cpp |  5 +++--
 clang/test/KeyInstructions/agg.c | 13 +++--
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bacf5730065c5..d5dd0bdd2612b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2480,8 +2480,9 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, 
LValue Dst,
   llvm::Instruction *Load = Builder.CreateLoad(Dst.getMatrixAddress());
   llvm::Value *Vec =
   Builder.CreateInsertElement(Load, Src.getScalarVal(), Idx, "matins");
-  Builder.CreateStore(Vec, Dst.getMatrixAddress(),
-  Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(Vec, Dst.getMatrixAddress(),
+Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, Vec);
   return;
 }
 
diff --git a/clang/test/KeyInstructions/agg.c b/clang/test/KeyInstructions/agg.c
index c9d3857043915..6caf84e89537f 100644
--- a/clang/test/KeyInstructions/agg.c
+++ b/clang/test/KeyInstructions/agg.c
@@ -1,10 +1,12 @@
-// RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - \
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - 
-fenable-matrix \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
-// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o - \
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o - 
-fenable-matrix \
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
 __attribute__((ext_vector_type(1))) char c;
+typedef float m5x5 __attribute__((matrix_type(5, 5)));
+m5x5 m;
 typedef struct { int a, b, c; } Struct;
 void fun(Struct a) {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
@@ -17,9 +19,16 @@ void fun(Struct a) {
 // CHECK: %vecins = insertelement <1 x i8> %2, i8 0, i32 0, !dbg [[G3R2:!.*]]
 // CHECK: store <1 x i8> %vecins, ptr @c{{.*}}, !dbg [[G3R1:!.*]]
   c[0] = 0;
+
+// CHECK: %3 = load <25 x float>, ptr @m, align 4
+// CHECK: %matins = insertelement <25 x float> %3, float 0.00e+00, i64 0, 
!dbg [[G4R2:!.*]]
+// CHECK: store <25 x float> %matins, ptr @m{{.*}}, !dbg [[G4R1:!.*]]
+  m[0][0] = 0;
 }
 
 // CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
 // CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
 // CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
 // CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] If stmt atom (PR #134642)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Add ApplyAtomGroup (PR #134632)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-debuginfo

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

This is a scoped helper similar to ApplyDebugLocation that creates a new source
atom group which instructions can be added to.

A source atom is a source construct that is "interesting" for debug stepping
purposes. We use an atom group number to track the instruction(s) that implement
the functionality for the atom, plus backup instructions/source locations.

---

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134632.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+118-1) 
- (modified) clang/lib/CodeGen/CGDebugInfo.h (+50) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+14) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 54025b767dc81..9fe1f24317b8a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -43,6 +43,7 @@
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Metadata.h"
@@ -52,6 +53,7 @@
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/SHA256.h"
 #include "llvm/Support/TimeProfiler.h"
+#include 
 #include 
 using namespace clang;
 using namespace clang::CodeGen;
@@ -119,6 +121,114 @@ CGDebugInfo::~CGDebugInfo() {
  "Region stack mismatch, stack not empty!");
 }
 
+void CGDebugInfo::addInstSourceAtomMetadata(llvm::Instruction *I,
+uint64_t Group, uint8_t Rank) {
+  if (!I->getDebugLoc() || Group == 0 || !I->getDebugLoc()->getLine())
+return;
+
+  // Saturate the 3-bit rank.
+  Rank = std::min(Rank, 7);
+
+  const llvm::DebugLoc &DL = I->getDebugLoc();
+
+  // Each instruction can only be attributed to one source atom (a limitation 
of
+  // the implementation). If this instruction is already part of a source atom,
+  // pick the group in which it has highest precedence (lowest rank).
+  if (DL.get()->getAtomGroup() && DL.get()->getAtomRank() &&
+  DL.get()->getAtomRank() < Rank) {
+Group = DL.get()->getAtomGroup();
+Rank = DL.get()->getAtomRank();
+  }
+
+  // Update the function-local watermark so we don't reuse this number for
+  // another atom.
+  KeyInstructionsInfo.HighestEmittedAtom =
+  std::max(Group, KeyInstructionsInfo.HighestEmittedAtom);
+
+  // Apply the new DILocation to the instruction.
+  llvm::DILocation *NewDL = llvm::DILocation::get(
+  I->getContext(), DL.getLine(), DL.getCol(), DL.getScope(),
+  DL.getInlinedAt(), DL.isImplicitCode(), Group, Rank);
+  I->setDebugLoc(NewDL);
+};
+
+void CGDebugInfo::addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction,
+ llvm::Value *Backup) {
+  if (!CGM.getCodeGenOpts().DebugKeyInstructions)
+return;
+
+  uint64_t Group = KeyInstructionsInfo.CurrentAtom;
+  if (!Group)
+return;
+
+  addInstSourceAtomMetadata(KeyInstruction, Group, /*Rank=*/1);
+
+  llvm::Instruction *BackupI =
+  llvm::dyn_cast_or_null(Backup);
+  if (!BackupI)
+return;
+
+  // Add the backup instruction to the group.
+  addInstSourceAtomMetadata(BackupI, Group, /*Rank=*/2);
+
+  // Look through chains of casts too, as they're probably going to evaporate.
+  // FIXME: And other nops like zero length geps?
+  // FIXME: Should use Cast->isNoopCast()?
+  uint8_t Rank = 3;
+  while (auto *Cast = dyn_cast(BackupI)) {
+BackupI = dyn_cast(Cast->getOperand(0));
+if (!BackupI)
+  break;
+addInstSourceAtomMetadata(BackupI, Group, Rank++);
+  }
+}
+
+void CGDebugInfo::addRetToOverrideOrNewSourceAtom(llvm::ReturnInst *Ret,
+  llvm::Value *Backup) {
+  if (KeyInstructionsInfo.RetAtomOverride) {
+uint64_t CurrentAtom = KeyInstructionsInfo.CurrentAtom;
+KeyInstructionsInfo.CurrentAtom = KeyInstructionsInfo.RetAtomOverride;
+addInstToCurrentSourceAtom(Ret, Backup);
+KeyInstructionsInfo.CurrentAtom = CurrentAtom;
+KeyInstructionsInfo.RetAtomOverride = 0;
+  } else {
+auto Grp = ApplyAtomGroup(this);
+addInstToCurrentSourceAtom(Ret, Backup);
+  }
+}
+
+void CGDebugInfo::setRetInstSourceAtomOverride(uint64_t Group) {
+  assert(KeyInstructionsInfo.RetAtomOverride == 0);
+  KeyInstructionsInfo.RetA

[llvm-branch-commits] [clang] [KeyInstr][Clang] Scalar init atom (PR #134633)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** http

[llvm-branch-commits] [clang] [Clang][NFC] Move some static functions into CodeGenFunction (PR #134634)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Coerced store atoms (PR #134653)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134653

[KeyInstr][Clang] Coerced store atoms

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

[KeyInstr][Clang] Coerced to int atom

[KeyInstr][Clang] Coerced ptr to int atom

[KeyInstr][Clang] Coerce packed struct atom

[KeyInstr][Clang] Coerce through memory atom

>From a33199f7fb7fca02440009401e70fea93af26906 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Mon, 7 Apr 2025 08:59:09 +0100
Subject: [PATCH 1/5] [KeyInstr][Clang] Coerced store atoms

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/lib/CodeGen/CGCall.cpp |  3 ++-
 clang/test/KeyInstructions/coerced.c | 24 
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/KeyInstructions/coerced.c

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index dba3fadba4f60..85984314fdfa7 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1408,7 +1408,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
   for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
 Address EltPtr = Builder.CreateStructGEP(Dst, i);
 llvm::Value *Elt = Builder.CreateExtractValue(Src, i);
-Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
+auto *I = Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
+addInstToCurrentSourceAtom(I, Elt);
   }
 } else {
   Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
diff --git a/clang/test/KeyInstructions/coerced.c 
b/clang/test/KeyInstructions/coerced.c
new file mode 100644
index 0..0e2a6464bb906
--- /dev/null
+++ b/clang/test/KeyInstructions/coerced.c
@@ -0,0 +1,24 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o - -target x86_64-unknown-linux \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o - -target x86_64-unknown-linux \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+typedef struct {
+  void* a;
+  void* b;
+} Struct;
+
+Struct get();
+void store() {
+  // CHECK: %1 = extractvalue { ptr, ptr } %call, 0, !dbg [[G1R2:!.*]]
+  // CHECK: store ptr %1, ptr {{.*}}, !dbg [[G1R1:!.*]]
+  // CHECK: %3 = extractvalue { ptr, ptr } %call, 1, !dbg [[G1R2]]
+  // CHECK: store ptr %3, ptr {{.*}}, !dbg [[G1R1:!.*]]
+  Struct s = get();
+  // CHECK: ret void, !dbg [[G2R1:!.*]]
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)

>From 195697274e71e403f1ec89e75b92cac68662d565 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Mon, 7 Apr 2025 10:23:55 +0100
Subject: [PATCH 2/5] [KeyInstr][Clang] Coerced to int atom

---
 clang/lib/CodeGen/CGCall.cpp |  3 ++-
 clang/test/KeyInstructions/coerced.c | 34 
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 85984314fdfa7..fd8118dd2b197 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1412,7 +1412,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
 addInstToCurrentSourceAtom(I, Elt);
   }
 } else {
-  Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
+  auto * I = Builder.CreateStore(Src, Dst.withElementType(SrcTy), 
DstIsVolatile);
+  addInstToCurrentSourceAtom(I, Src);
 }
   } else if (SrcTy->isIntegerTy()) {
 // If the source is a simple integer, coerce it directly.
diff --git a/clang/test/KeyInstructions/coerced.c 
b/clang/test/KeyInstructions/coerced.c
index 0e2a6464bb906..db5707

[llvm-branch-commits] [llvm] [BOLT] Gadget scanner: detect signing oracles (PR #134146)

2025-04-07 Thread Kristof Beyls via llvm-branch-commits


@@ -622,6 +628,40 @@ class MCPlusBuilder {
 return std::make_pair(getNoRegister(), getNoRegister());
   }
 
+  /// Analyzes if a pointer is checked to be valid by the end of BB.
+  ///
+  /// It is possible for pointer authentication instructions not to terminate
+  /// the program abnormally on authentication failure and return some *invalid
+  /// pointer* instead (like it is done on AArch64 when FEAT_FPAC is not
+  /// implemented). This might be enough to crash on invalid memory access
+  /// when the pointer is later used as the destination of load/store or branch
+  /// instruction. On the other hand, when the pointer is not used right away,
+  /// it may be important for the compiler to check the address explicitly not
+  /// to introduce signing or authentication oracle.
+  ///
+  /// If this function returns a (Reg, Inst) pair, then it is known that in any
+  /// successor of BB either
+  /// * Reg is trusted, provided it was safe-to-dereference before Inst, or
+  /// * the program is terminated abnormally without introducing any signing
+  ///   or authentication oracles
+  virtual std::optional>

kbeyls wrote:

Before reading the rest of this patch, I would guess that in theory there could 
be multiple such (Reg, Inst) pairs in a single basic block? If so, should this 
return a list/vector/... instead of an optional?

https://github.com/llvm/llvm-project/pull/134146
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [Clang][NFC] Move some static functions into CodeGenFunction (PR #134634)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134634

The next patch in the stack needs to access CGF in these functions. 2
CGF fields are passed to these functions already; at this point it
felt natural to promote them to CGF methods.

>From a644c795b12da626627c1d4042f969978c66ce6d Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 15:20:22 +0100
Subject: [PATCH] [Clang][NFC] Move some static functions into CodeGenFunction

The next patch in the stack needs to access CGF in these functions. 2
CGF fields are passed to these functions already; at this point it
felt natural to promote them to CGF methods.
---
 clang/lib/CodeGen/CGDecl.cpp| 52 +
 clang/lib/CodeGen/CodeGenFunction.h | 11 ++
 2 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 96d217b0a13cc..6aa9f3fa27c87 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -928,10 +928,9 @@ static bool 
canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
 
 /// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit
 /// the scalar stores that would be required.
-static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
-llvm::Constant *Init, Address Loc,
-bool isVolatile, CGBuilderTy &Builder,
-bool IsAutoInit) {
+void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
+  Address Loc, bool isVolatile,
+  bool IsAutoInit) {
   assert(!Init->isNullValue() && !isa(Init) &&
  "called emitStoresForInitAfterBZero for zero or undef value.");
 
@@ -952,8 +951,8 @@ static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
   // If necessary, get a pointer to the element and emit it.
   if (!Elt->isNullValue() && !isa(Elt))
 emitStoresForInitAfterBZero(
-CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), 
isVolatile,
-Builder, IsAutoInit);
+Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile,
+IsAutoInit);
 }
 return;
   }
@@ -966,9 +965,9 @@ static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
 
 // If necessary, get a pointer to the element and emit it.
 if (!Elt->isNullValue() && !isa(Elt))
-  emitStoresForInitAfterBZero(CGM, Elt,
+  emitStoresForInitAfterBZero(Elt,
   Builder.CreateConstInBoundsGEP2_32(Loc, 0, 
i),
-  isVolatile, Builder, IsAutoInit);
+  isVolatile, IsAutoInit);
   }
 }
 
@@ -1169,10 +1168,10 @@ static Address 
createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM,
   return SrcPtr.withElementType(CGM.Int8Ty);
 }
 
-static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D,
-  Address Loc, bool isVolatile,
-  CGBuilderTy &Builder,
-  llvm::Constant *constant, bool IsAutoInit) {
+void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
+bool isVolatile,
+llvm::Constant *constant,
+bool IsAutoInit) {
   auto *Ty = constant->getType();
   uint64_t ConstantSize = CGM.getDataLayout().getTypeAllocSize(Ty);
   if (!ConstantSize)
@@ -1201,8 +1200,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
 constant->isNullValue() || isa(constant);
 if (!valueAlreadyCorrect) {
   Loc = Loc.withElementType(Ty);
-  emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder,
-  IsAutoInit);
+  emitStoresForInitAfterBZero(constant, Loc, isVolatile, IsAutoInit);
 }
 return;
   }
@@ -1240,7 +1238,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
   CharUnits::fromQuantity(Layout->getElementOffset(i));
   Address EltPtr = Builder.CreateConstInBoundsByteGEP(
   Loc.withElementType(CGM.Int8Ty), CurOff);
-  emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
+  emitStoresForConstant(D, EltPtr, isVolatile,
 constant->getAggregateElement(i), IsAutoInit);
 }
 return;
@@ -1251,7 +1249,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
 for (unsigned i = 0; i != ATy->getNumElements(); i++) {
   Address EltPtr = Builder.CreateConstGEP(
   Loc.withElementType(ATy->getElementType()), i);
-  emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
+  emitStoresForConst

[llvm-branch-commits] [clang] [KeyInstr][Clang] Add ApplyAtomGroup (PR #134632)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134632

This is a scoped helper similar to ApplyDebugLocation that creates a new source
atom group which instructions can be added to.

A source atom is a source construct that is "interesting" for debug stepping
purposes. We use an atom group number to track the instruction(s) that implement
the functionality for the atom, plus backup instructions/source locations.

---

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

>From 856f99ea6b9daa095733d107915a02722ba9403d Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 11:59:24 +0100
Subject: [PATCH] [KeyInstr][Clang] Add ApplyAtomGroup

This is a scoped helper similar to ApplyDebugLocation that creates a new source
atom group which instructions can be added to.

A source atom is a source construct that is "interesting" for debug stepping
purposes. We use an atom group number to track the instruction(s) that implement
the functionality for the atom, plus backup instructions/source locations.

---

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/lib/CodeGen/CGDebugInfo.cpp   | 119 +++-
 clang/lib/CodeGen/CGDebugInfo.h |  50 
 clang/lib/CodeGen/CodeGenFunction.h |  14 
 3 files changed, 182 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 54025b767dc81..9fe1f24317b8a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -43,6 +43,7 @@
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Metadata.h"
@@ -52,6 +53,7 @@
 #include "llvm/Support/SHA1.h"
 #include "llvm/Support/SHA256.h"
 #include "llvm/Support/TimeProfiler.h"
+#include 
 #include 
 using namespace clang;
 using namespace clang::CodeGen;
@@ -119,6 +121,114 @@ CGDebugInfo::~CGDebugInfo() {
  "Region stack mismatch, stack not empty!");
 }
 
+void CGDebugInfo::addInstSourceAtomMetadata(llvm::Instruction *I,
+uint64_t Group, uint8_t Rank) {
+  if (!I->getDebugLoc() || Group == 0 || !I->getDebugLoc()->getLine())
+return;
+
+  // Saturate the 3-bit rank.
+  Rank = std::min(Rank, 7);
+
+  const llvm::DebugLoc &DL = I->getDebugLoc();
+
+  // Each instruction can only be attributed to one source atom (a limitation 
of
+  // the implementation). If this instruction is already part of a source atom,
+  // pick the group in which it has highest precedence (lowest rank).
+  if (DL.get()->getAtomGroup() && DL.get()->getAtomRank() &&
+  DL.get()->getAtomRank() < Rank) {
+Group = DL.get()->getAtomGroup();
+Rank = DL.get()->getAtomRank();
+  }
+
+  // Update the function-local watermark so we don't reuse this number for
+  // another atom.
+  KeyInstructionsInfo.HighestEmittedAtom =
+  std::max(Group, KeyInstructionsInfo.HighestEmittedAtom);
+
+  // Apply the new DILocation to the instruction.
+  llvm::DILocation *NewDL = llvm::DILocation::get(
+  I->getContext(), DL.getLine(), DL.getCol(), DL.getScope(),
+  DL.getInlinedAt(), DL.isImplicitCode(), Group, Rank);
+  I->setDebugLoc(NewDL);
+};
+
+void CGDebugInfo::addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction,
+ llvm::Value *Backup) {
+  if (!CGM.getCodeGenOpts().DebugKeyInstructions)
+return;
+
+  uint64_t Group = KeyInstructionsInfo.CurrentAtom;
+  if (!Group)
+return;
+
+  addInstSourceAtomMetadata(KeyInstruction, Group, /*Rank=*/1);
+
+  llvm::Instruction *BackupI =
+  llvm::dyn_cast_or_null(Backup);
+  if (!BackupI)
+return;
+
+  // Add the backup instruction to the group.
+  addInstSourceAtomMetadata(BackupI, Group, /*Rank=*/2);
+
+  // Look through chains of casts too, as 

[llvm-branch-commits] [clang] [KeyInstr][Clang] Aggregate init + copy (PR #134639)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134639

[KeyInstr][Clang] Aggregate init + copy

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

[KeyInstr][Clang] Agg copy atom

>From c1ec75f22a662c0a48666c1fae24048fd2bb62f4 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 15:15:39 +0100
Subject: [PATCH 1/2] [KeyInstr][Clang] Aggregate init + copy

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/lib/CodeGen/CGExprAgg.cpp   |  3 ++-
 clang/test/KeyInstructions/agg.c  | 12 
 clang/test/KeyInstructions/init-agg.c |  2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/KeyInstructions/agg.c

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index c8bdda375d1b1..53858932ede04 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -2394,7 +2394,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, 
LValue Src, QualType Ty,
 }
   }
 
-  auto Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
+  auto *Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
+  addInstToCurrentSourceAtom(Inst, nullptr);
 
   // Determine the metadata to describe the position of any padding in this
   // memcpy, as well as the TBAA tags for the members of the struct, in case
diff --git a/clang/test/KeyInstructions/agg.c b/clang/test/KeyInstructions/agg.c
new file mode 100644
index 0..5990859a5b548
--- /dev/null
+++ b/clang/test/KeyInstructions/agg.c
@@ -0,0 +1,12 @@
+
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+typedef struct { int a, b, c; } Struct;
+void fun(Struct a) {
+// CHECK: call void @llvm.memcpy{{.*}}, !dbg  [[G1R1:!.*]]
+  Struct b = a;
+}
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+
diff --git a/clang/test/KeyInstructions/init-agg.c 
b/clang/test/KeyInstructions/init-agg.c
index ad298715286cd..dc3ccaedc57b5 100644
--- a/clang/test/KeyInstructions/init-agg.c
+++ b/clang/test/KeyInstructions/init-agg.c
@@ -9,6 +9,8 @@
 // store locations to be included in the atom group.
 
 int g;
+typedef struct { int a, b, c; } Struct;
+Struct g2;
 void a() {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
 int A[] = { 1, 2, 3 };

>From 77f91f53a7731547e5af4196299c2648dbfc20a4 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 16:00:26 +0100
Subject: [PATCH 2/2] [KeyInstr][Clang] Agg copy atom

---
 clang/lib/CodeGen/CGExprAgg.cpp |  1 +
 clang/lib/CodeGen/CodeGenFunction.h |  1 +
 clang/test/KeyInstructions/agg.c| 11 ---
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 53858932ede04..26bc2666d9759 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1332,6 +1332,7 @@ static bool isBlockVarRef(const Expr *E) {
 }
 
 void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   // For an assignment to work, the value on the right has
   // to be compatible with the value on the left.
   assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d8b1c4e4efb77..0a72784f311e5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3042,6 +3042,7 @@ class CodeGenFunction : public CodeGenTypeCache {
 
   /// Emit an aggregate assignment.
   void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy) {
+ApplyAtomGroup Grp(getDebugInfo());
 bool IsVolatile = hasVolatileMember(EltTy);
 EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
   }
diff --git a/clang/test/KeyI

[llvm-branch-commits] [clang] [KeyInstr][Clang] Agg init atom (PR #134635)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Aggregate init + copy (PR #134639)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** https://app.graphite.dev/github/pr/llvm/llvm-project/133487?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133486** https://app.graphite.dev/github/pr/llvm/llvm-project/133486?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133485** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Agg init atom (PR #134635)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134635

[KeyInstr][Clang] Agg init atom

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

shouldUseBZeroPlusStoresToInitialize

[KeyInstr] init-agg pattern

[KeyInstr][Clang] Init pattern atom

>From 06b9688ecb5d25d47fc2d2cbd40f257dfb9edea6 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 15:40:58 +0100
Subject: [PATCH 1/4] [KeyInstr][Clang] Agg init atom

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/lib/CodeGen/CGDecl.cpp|  2 ++
 clang/test/KeyInstructions/init-agg.cpp | 22 ++
 2 files changed, 24 insertions(+)
 create mode 100644 clang/test/KeyInstructions/init-agg.cpp

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 6aa9f3fa27c87..045ac7361cf5c 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1263,6 +1263,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
createUnnamedGlobalForMemcpyFrom(
CGM, D, Builder, constant, Loc.getAlignment()),
SizeVal, isVolatile);
+  addInstToCurrentSourceAtom(I, nullptr);
+
   if (IsAutoInit)
 I->addAnnotationMetadata("auto-init");
 }
diff --git a/clang/test/KeyInstructions/init-agg.cpp 
b/clang/test/KeyInstructions/init-agg.cpp
new file mode 100644
index 0..b96256b532f3e
--- /dev/null
+++ b/clang/test/KeyInstructions/init-agg.cpp
@@ -0,0 +1,22 @@
+
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// The implicit-check-not is important; we don't want the GEPs created for the
+// store locations to be included in the atom group.
+
+int g;
+void a() {
+// CHECK: _Z1av()
+// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
+int A[] = { 1, 2, 3 };
+// CHECK: store i32 1, ptr %{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: store i32 2, ptr %{{.*}}, !dbg [[G2R1]]
+// CHECK: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr %{{.*}}, !dbg [[G2R1]]
+int B[] = { 1, 2, g };
+}
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)

>From 1f1f1d5d88b26177614d7a9abbe7200528895e6a Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 16:45:47 +0100
Subject: [PATCH 2/4] shouldUseBZeroPlusStoresToInitialize

---
 clang/lib/CodeGen/CGDecl.cpp|  3 +++
 clang/test/KeyInstructions/init-agg.cpp | 12 +++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 045ac7361cf5c..c43c547efbcaa 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -938,6 +938,7 @@ void 
CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
   isa(Init) || isa(Init) ||
   isa(Init)) {
 auto *I = Builder.CreateStore(Init, Loc, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1193,6 +1194,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
   if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
 auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
SizeVal, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
+
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 
diff --git a/clang/test/KeyInstructions/init-agg.cpp 
b/clang/test/KeyInstructions/init-agg.cpp
index b96256b532f3e..854af3237ed98 100644
--- a/clang/test/KeyInstructions/init-agg.cpp
+++ b/clang/test/KeyInstructions/init-agg.cpp
@@ -1,22 +1,32 @

[llvm-branch-commits] [clang] [KeyInstr][Clang] Member initalization atom (PR #134640)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134640

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

>From c25359bdebc67e0f48c96a468fd665d6a6130219 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 17:00:09 +0100
Subject: [PATCH] [KeyInstr][Clang] Member initalization atom

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/lib/CodeGen/CGClass.cpp  |  1 +
 clang/test/KeyInstructions/init-member.cpp | 22 ++
 2 files changed, 23 insertions(+)
 create mode 100644 clang/test/KeyInstructions/init-member.cpp

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 98c93b5bb4883..8ef795bfee410 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1338,6 +1338,7 @@ void CodeGenFunction::EmitCtorPrologue(const 
CXXConstructorDecl *CD,
 assert(!Member->isBaseInitializer());
 assert(Member->isAnyMemberInitializer() &&
"Delegating initializer on non-delegating constructor");
+ApplyAtomGroup Grp(getDebugInfo());
 CM.addMemberInitializer(Member);
   }
   CM.finish();
diff --git a/clang/test/KeyInstructions/init-member.cpp 
b/clang/test/KeyInstructions/init-member.cpp
new file mode 100644
index 0..60949bd8a604a
--- /dev/null
+++ b/clang/test/KeyInstructions/init-member.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s
+
+struct B {
+  float y;
+};
+
+class Cls {
+  public:
+int x = 1;
+B b = {5.f};
+};
+
+void fun() {
+  Cls c;
+}
+
+// CHECK: store i32 1, ptr %x{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: store float 5.00e+00, ptr %y{{.*}}, !dbg [[G2R1:!.*]]
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Static variable init atom (PR #134636)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134636

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

>From a92afbf589152ebb3f98802a81186792d3e911ee Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Wed, 2 Apr 2025 17:42:48 +0100
Subject: [PATCH] [KeyInstr][Clang] Static variable init atom

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/lib/CodeGen/CGDecl.cpp   |  4 +++-
 clang/test/KeyInstructions/init-static.cpp | 12 
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/KeyInstructions/init-static.cpp

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 9860ab0b033bb..3c5597a00f2ea 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -428,8 +428,10 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
   bool isCudaSharedVar = getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
  D.hasAttr();
   // If this value has an initializer, emit it.
-  if (D.getInit() && !isCudaSharedVar)
+  if (D.getInit() && !isCudaSharedVar) {
+ApplyAtomGroup Grp(getDebugInfo());
 var = AddInitializerToStaticVarDecl(D, var);
+  }
 
   var->setAlignment(alignment.getAsAlign());
 
diff --git a/clang/test/KeyInstructions/init-static.cpp 
b/clang/test/KeyInstructions/init-static.cpp
new file mode 100644
index 0..82e14b59df5e5
--- /dev/null
+++ b/clang/test/KeyInstructions/init-static.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o -\
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+void g(int *a) {
+// CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]]
+static int &b = *a;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134643

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

>From 08d6d9e02e9be9f87465526d8bed39013e9b Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 18:43:56 +0100
Subject: [PATCH] [KeyInstr][Clang] Switch stmt atom

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/lib/CodeGen/CGStmt.cpp|  2 ++
 clang/test/KeyInstructions/switch.c | 51 +
 2 files changed, 53 insertions(+)
 create mode 100644 clang/test/KeyInstructions/switch.c

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 3562b4ea22a24..7dd82d73d6b6a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2276,6 +2276,8 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) 
{
   // failure.
   llvm::BasicBlock *DefaultBlock = createBasicBlock("sw.default");
   SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock);
+  addInstToNewSourceAtom(SwitchInsn, CondV);
+
   if (HLSLControlFlowAttr != HLSLControlFlowHintAttr::SpellingNotCalculated) {
 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
 llvm::ConstantInt *BranchHintConstant =
diff --git a/clang/test/KeyInstructions/switch.c 
b/clang/test/KeyInstructions/switch.c
new file mode 100644
index 0..cff6b834106e9
--- /dev/null
+++ b/clang/test/KeyInstructions/switch.c
@@ -0,0 +1,51 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A, int B) {
+// CHECK: entry:
+// The load gets associated with the branch rather than the store.
+// FIXME: Is that the best thing to do?
+// CHECK: %0 = load i32, ptr %A.addr{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: switch i32 %0, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb
+// CHECK:   i32 1, label %sw.bb1
+// CHECK: ], !dbg [[G2R1:!.*]]
+switch ((g = A)) {
+case 0: break;
+case 1: {
+// CHECK: sw.bb1:
+// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: switch i32 %1, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb2
+// CHECK: ], !dbg [[G3R1:!.*]]
+switch ((B)) {
+case 0: {
+// Test that assignments in constant-folded switches don't go missing.
+// CHECK-CXX: sw.bb2:
+// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G4R1:!.*]]
+#ifdef __cplusplus
+switch (const int C = 1; C) {
+case 0: break;
+case 1: break;
+default: break;
+}
+#endif
+} break;
+default: break;
+}
+} break;
+default: break;
+}
+}
+
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] If stmt atom (PR #134642)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134642

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

>From 98ea64f7a1cd17daccd8605e8b71e56367ff65db Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 18:05:07 +0100
Subject: [PATCH] [KeyInstr][Clang] If stmt atom

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/lib/CodeGen/CodeGenFunction.cpp |  2 ++
 clang/lib/CodeGen/CodeGenFunction.h   | 10 ++
 clang/test/KeyInstructions/if.c   | 46 +++
 3 files changed, 58 insertions(+)
 create mode 100644 clang/test/KeyInstructions/if.c

diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index dcf523f56bf1e..b176227657f24 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2099,6 +2099,8 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
 
   llvm::Instruction *BrInst = Builder.CreateCondBr(CondV, TrueBlock, 
FalseBlock,
Weights, Unpredictable);
+  addInstToNewSourceAtom(BrInst, CondV);
+
   switch (HLSLControlFlowAttr) {
   case HLSLControlFlowHintAttr::Microsoft_branch:
   case HLSLControlFlowHintAttr::Microsoft_flatten: {
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 0a72784f311e5..3c3984c57d540 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1768,6 +1768,16 @@ class CodeGenFunction : public CodeGenTypeCache {
   DI->addInstToCurrentSourceAtom(KeyInstruction, Backup);
   }
 
+  /// Add \p KeyInstruction and an optional \p Backup instruction to a new atom
+  /// group (See ApplyAtomGroup for more info).
+  void addInstToNewSourceAtom(llvm::Instruction *KeyInstruction,
+  llvm::Value *Backup) {
+if (CGDebugInfo *DI = getDebugInfo()) {
+  ApplyAtomGroup Grp(getDebugInfo());
+  DI->addInstToCurrentSourceAtom(KeyInstruction, Backup);
+}
+  }
+
   /// See CGDebugInfo::addRetToOverrideOrNewSourceAtom.
   void addRetToOverrideOrNewSourceAtom(llvm::ReturnInst *Ret,
llvm::Value *Backup) {
diff --git a/clang/test/KeyInstructions/if.c b/clang/test/KeyInstructions/if.c
new file mode 100644
index 0..ccc7eb9253198
--- /dev/null
+++ b/clang/test/KeyInstructions/if.c
@@ -0,0 +1,46 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A) {
+// The branch is a key instruction, with the condition being its backup.
+// CHECK: entry:
+// CHECK: %tobool = icmp ne i32 %0, 0{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: br i1 %tobool, label %if.then, label %if.end{{.*}}, !dbg [[G1R1:!.*]]
+if (A)
+;
+
+// The assignment in the if gets a distinct source atom group.
+// CHECK: if.end:
+// CHECK: %1 = load i32, ptr %A.addr{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %1, ptr @g{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: %tobool1 = icmp ne i32 %1, 0{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: br i1 %tobool1, label %if.then2, label %if.end3{{.*}}, !dbg 
[[G3R1:!.*]]
+if ((g = A))
+;
+
+#ifdef __cplusplus
+// The assignment in the if gets a distinct source atom group.
+// CHECK-CXX: if.end3:
+// CHECK-CXX: %2 = load i32, ptr %A.addr{{.*}}, !dbg [[G4R2:!.*]]
+// CHECK-CXX: store i32 %2, ptr %B{{.*}}, !dbg [[G4R1:!.*]]
+// CHECK-CXX: %tobool4 = icmp ne i32 %3, 0{{.*}}, !dbg [[G5R2:!.*]]
+// CHECK-CXX: br i1 %tobool4, label %if.then5, label %if.end6{{.*}}, !dbg 
[[G5R1:!.*]]
+if (int B = A; B)
+;
+#endif 
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRan

[llvm-branch-commits] [clang] [KeyInstr][Clang] Do stmt atom (PR #134644)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134644

See test comment for possible future improvement.

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

>From 2ee4d451f70e4412beeb2501ee3d9113d103db7c Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 18:53:31 +0100
Subject: [PATCH] [KeyInstr][Clang] Do stmt atom

See test comment for possible future improvement.

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/lib/CodeGen/CGStmt.cpp| 10 +-
 clang/test/KeyInstructions/do.c | 33 +
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/KeyInstructions/do.c

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 7dd82d73d6b6a..e46cfb433ab89 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1242,9 +1242,17 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
   // As long as the condition is true, iterate the loop.
   if (EmitBoolCondBranch) {
 uint64_t BackedgeCount = getProfileCount(S.getBody()) - ParentCount;
-Builder.CreateCondBr(
+auto *I = Builder.CreateCondBr(
 BoolCondVal, LoopBody, LoopExit.getBlock(),
 createProfileWeightsForLoop(S.getCond(), BackedgeCount));
+
+// Key Instructions: Emit the condition and branch as separate atoms to
+// match existing loop stepping behaviour. FIXME: We could have the branch
+// as the backup location for the condition, which would probably be a
+// better experience (no jumping to the brace).
+if (auto *I = dyn_cast(BoolCondVal))
+  addInstToNewSourceAtom(I, nullptr);
+addInstToNewSourceAtom(I, nullptr);
   }
 
   LoopStack.pop();
diff --git a/clang/test/KeyInstructions/do.c b/clang/test/KeyInstructions/do.c
new file mode 100644
index 0..4b7a38cb35985
--- /dev/null
+++ b/clang/test/KeyInstructions/do.c
@@ -0,0 +1,33 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Perennial quesiton: should the `dec` be in its own source atom or not
+// (currently it is).
+
+// Another question - we've made the cmp and br separate source atoms for
+// now, to match existing behaviour in this case:
+// 1. do {
+// 2.   something();
+// 3. }
+// 4. while (--A);
+// Non key instruction behaviour is: 2, 4[, 3, 2, 4]+
+// The cond br is associated with the brace on line 3 and the cmp is line 4;
+// if they were in the same atom group we'd step just: 2, 3[, 2, 3]+
+// FIXME: We could arguably improve the behaviour by making them the same
+// group but having the cmp higher precedence, resulting in: 2, 4[, 2, 4]+.
+
+void a(int A) {
+// CHECK: %dec = add nsw i32 %0, -1, !dbg [[G1R2:!.*]]
+// CHECK: store i32 %dec, ptr %A.addr{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: %tobool = icmp ne i32 %dec, 0, !dbg [[G2R1:!.*]]
+// CHECK: br i1 %tobool, label %do.body, label %do.end, !dbg [[G3R1:!.*]], 
!llvm.loop
+do { } while (--A);
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Bitfield atom (PR #134648)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134648

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

>From 1c670c04c0397e4bafa063621006aa7e31d81aeb Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 19:57:39 +0100
Subject: [PATCH] [KeyInstr][Clang] Bitfield atom

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/lib/CodeGen/CGExpr.cpp|  3 ++-
 clang/test/KeyInstructions/bitfield.cpp | 13 +
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/KeyInstructions/bitfield.cpp

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 7408c498b3a1a..a5e113a1a4397 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2614,7 +2614,8 @@ void 
CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
   }
 
   // Write the new value back out.
-  Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, SrcVal);
 
   // Return the new value of the bit-field, if requested.
   if (Result) {
diff --git a/clang/test/KeyInstructions/bitfield.cpp 
b/clang/test/KeyInstructions/bitfield.cpp
new file mode 100644
index 0..0586050ba8397
--- /dev/null
+++ b/clang/test/KeyInstructions/bitfield.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+struct S { int a:3; };
+
+void foo(int x, S s) {
+// CHECK: %bf.set = or i8 %bf.clear, %bf.value, !dbg [[G1R2:!.*]]
+// CHECK: store i8 %bf.set, ptr %s, align 4, !dbg [[G1R1:!.*]]
+  s.a = x;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Catch variable init atom (PR #134641)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134641

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

>From 638b319d13527540a84dc7553ce8a1727a06392e Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 17:31:32 +0100
Subject: [PATCH] [KeyInstr][Clang] Catch variable init atom

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/lib/CodeGen/ItaniumCXXABI.cpp  |  1 +
 clang/test/KeyInstructions/try-catch.cpp | 20 
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/KeyInstructions/try-catch.cpp

diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 77e995b4c933a..b3f1e208fa318 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -5051,6 +5051,7 @@ void ItaniumCXXABI::emitBeginCatch(CodeGenFunction &CGF,
 
   // Emit the local.
   CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam);
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF), 
S->getBeginLoc());
   CGF.EmitAutoVarCleanups(var);
 }
diff --git a/clang/test/KeyInstructions/try-catch.cpp 
b/clang/test/KeyInstructions/try-catch.cpp
new file mode 100644
index 0..3d1080aca2f07
--- /dev/null
+++ b/clang/test/KeyInstructions/try-catch.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - -fexceptions \
+// RUN: | FileCheck %s
+
+void except() {
+  // FIXME(OCH): Should `store i32 32, ptr %exception` be key?
+  throw 32;
+}
+
+void attempt() {
+  try { except(); }
+// CHECK: catch:
+// CHECK: %4 = call ptr @__cxa_begin_catch(ptr %exn)
+// CHECK: %5 = load i32{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store i32 %5, ptr %e{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: call void @__cxa_end_catch()
+  catch (int e) { }
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Ret atom (PR #134652)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134652

[KeyInstr][Clang] Ret atom

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

[KeyInstr][Clang] Update tests with ret atoms

>From 10f161b96302da4ce8f9517d5f0a94a1d9705b35 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Fri, 4 Apr 2025 16:28:39 +0100
Subject: [PATCH 1/2] [KeyInstr][Clang] Ret atom

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/lib/CodeGen/CGCall.cpp   |  6 +-
 clang/lib/CodeGen/CGCleanup.cpp|  2 +
 clang/lib/CodeGen/CGStmt.cpp   | 13 +++-
 clang/lib/CodeGen/CodeGenFunction.cpp  | 16 
 clang/test/KeyInstructions/return-va-arg.c | 25 ++
 clang/test/KeyInstructions/return.c| 90 ++
 6 files changed, 147 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/KeyInstructions/return-va-arg.c
 create mode 100644 clang/test/KeyInstructions/return.c

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7aa77e55dbfcc..dba3fadba4f60 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3883,7 +3883,8 @@ void CodeGenFunction::EmitFunctionEpilog(const 
CGFunctionInfo &FI,
 
   // Functions with no result always return void.
   if (!ReturnValue.isValid()) {
-Builder.CreateRetVoid();
+auto *I = Builder.CreateRetVoid();
+addRetToOverrideOrNewSourceAtom(I, nullptr);
 return;
   }
 
@@ -4065,6 +4066,9 @@ void CodeGenFunction::EmitFunctionEpilog(const 
CGFunctionInfo &FI,
 
   if (RetDbgLoc)
 Ret->setDebugLoc(std::move(RetDbgLoc));
+
+  llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr;
+  addRetToOverrideOrNewSourceAtom(cast(Ret), Backup);
 }
 
 void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 7e1c5b7da9552..7292dcd47172c 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -1118,6 +1118,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest 
Dest) {
 
   // Create the branch.
   llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
+  // This is the primary instruction for this atom, acting in place of a ret.
+  addInstToCurrentSourceAtom(BI, nullptr);
 
   // Calculate the innermost active normal cleanup.
   EHScopeStack::stable_iterator
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 9292be24fc12e..21c2dd14799dd 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1594,6 +1594,7 @@ static bool isSwiftAsyncCallee(const CallExpr *CE) {
 /// if the function returns void, or may be missing one if the function returns
 /// non-void.  Fun stuff :).
 void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
+  ApplyAtomGroup Grp(getDebugInfo());
   if (requiresReturnValueCheck()) {
 llvm::Constant *SLoc = EmitCheckSourceLocation(S.getBeginLoc());
 auto *SLocPtr =
@@ -1603,6 +1604,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr);
 assert(ReturnLocation.isValid() && "No valid return location");
 Builder.CreateStore(SLocPtr, ReturnLocation);
+//*OCH?*//
   }
 
   // Returning from an outlined SEH helper is UB, and we already warn on it.
@@ -1669,16 +1671,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt 
&S) {
 // If this function returns a reference, take the address of the expression
 // rather than the value.
 RValue Result = EmitReferenceBindingToExpr(RV);
-Builder.CreateStore(Result.getScalarVal(), ReturnValue);
+auto *I = Builder.CreateStore(Result.getScalarVal(), ReturnValue);
+addInstToCurrentSourceAtom(I, I->getValueOperand());
   } else {
 switch (getEvaluationKind(RV->getType())) {
 case TEK_Scalar: {
   llvm::Value *Ret = EmitScalarExpr(RV);
-  if (CurFnInfo->getReturnInfo

[llvm-branch-commits] [clang] [KeyInstr][Clang] For stmt atom (PR #134646)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134646

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

>From 375ca9f7b756d01da82772f9316ab20b56214d91 Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Thu, 3 Apr 2025 19:12:47 +0100
Subject: [PATCH] [KeyInstr][Clang] For stmt atom

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/lib/CodeGen/CGStmt.cpp | 18 ++--
 clang/test/KeyInstructions/for.c | 37 
 2 files changed, 53 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/KeyInstructions/for.c

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index d9fd406ad64ee..65b71c39d86c4 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1324,6 +1324,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
 Continue = getJumpDestInCurrentScope("for.inc");
   BreakContinueStack.push_back(BreakContinue(LoopExit, Continue));
 
+  llvm::BasicBlock *ForBody = nullptr;
   if (S.getCond()) {
 // If the for statement has a condition scope, emit the local variable
 // declaration.
@@ -1348,7 +1349,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
   ExitBlock = createBasicBlock("for.cond.cleanup");
 
 // As long as the condition is true, iterate the loop.
-llvm::BasicBlock *ForBody = createBasicBlock("for.body");
+ForBody = createBasicBlock("for.body");
 
 // C99 6.8.5p2/p4: The first substatement is executed if the expression
 // compares unequal to 0.  The condition must be a scalar type.
@@ -1362,7 +1363,14 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
   BoolCondVal = emitCondLikelihoodViaExpectIntrinsic(
   BoolCondVal, Stmt::getLikelihood(S.getBody()));
 
-Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
+auto *I = Builder.CreateCondBr(BoolCondVal, ForBody, ExitBlock, Weights);
+// Key Instructions: Emit the condition and branch as separate atoms to
+// match existing loop stepping behaviour. FIXME: We could have the branch
+// as the backup location for the condition, which would probably be a
+// better experience (no jumping to the brace).
+if (auto *I = dyn_cast(BoolCondVal))
+  addInstToNewSourceAtom(I, nullptr);
+addInstToNewSourceAtom(I, nullptr);
 
 if (ExitBlock != LoopExit.getBlock()) {
   EmitBlock(ExitBlock);
@@ -1416,6 +1424,12 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
 
   if (CGM.shouldEmitConvergenceTokens())
 ConvergenceTokenStack.pop_back();
+
+  if (ForBody) {
+// Key Instructions: We want the for closing brace to be step-able on to
+// match existing behaviour.
+addInstToNewSourceAtom(ForBody->getTerminator(), nullptr);
+  }
 }
 
 void
diff --git a/clang/test/KeyInstructions/for.c b/clang/test/KeyInstructions/for.c
new file mode 100644
index 0..3221ece69a717
--- /dev/null
+++ b/clang/test/KeyInstructions/for.c
@@ -0,0 +1,37 @@
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Perennial quesiton: should the inc be its own source atom or not
+// (currently it is).
+
+// FIXME: See do.c and while.c regarding cmp and cond br groups.
+
+void a(int A) {
+// CHECK: entry:
+// CHECK: store i32 0, ptr %i{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: for.cond:
+// CHECK: %cmp = icmp slt i32 %0, %1, !dbg [[G2R1:!.*]]
+// CHECK: br i1 %cmp, label %for.body, label %for.end, !dbg [[G3R1:!.*]]
+
+// FIXME: Added uncond br group here which is useful for O0, which we're
+// no longer targeting. With optimisations loop rotate puts the condition
+// into for.inc and simplifycfg smooshes that and for.body together, so
+// it's 

[llvm-branch-commits] [clang] [Clang][NFC] Move some static functions into CodeGenFunction (PR #134634)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

The next patch in the stack needs to access CGF in these functions. 2
CGF fields are passed to these functions already; at this point it
felt natural to promote them to CGF methods.

---
Full diff: https://github.com/llvm/llvm-project/pull/134634.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDecl.cpp (+24-28) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+11) 


``diff
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 96d217b0a13cc..6aa9f3fa27c87 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -928,10 +928,9 @@ static bool 
canEmitInitWithFewStoresAfterBZero(llvm::Constant *Init,
 
 /// For inits that canEmitInitWithFewStoresAfterBZero returned true for, emit
 /// the scalar stores that would be required.
-static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
-llvm::Constant *Init, Address Loc,
-bool isVolatile, CGBuilderTy &Builder,
-bool IsAutoInit) {
+void CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
+  Address Loc, bool isVolatile,
+  bool IsAutoInit) {
   assert(!Init->isNullValue() && !isa(Init) &&
  "called emitStoresForInitAfterBZero for zero or undef value.");
 
@@ -952,8 +951,8 @@ static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
   // If necessary, get a pointer to the element and emit it.
   if (!Elt->isNullValue() && !isa(Elt))
 emitStoresForInitAfterBZero(
-CGM, Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), 
isVolatile,
-Builder, IsAutoInit);
+Elt, Builder.CreateConstInBoundsGEP2_32(Loc, 0, i), isVolatile,
+IsAutoInit);
 }
 return;
   }
@@ -966,9 +965,9 @@ static void emitStoresForInitAfterBZero(CodeGenModule &CGM,
 
 // If necessary, get a pointer to the element and emit it.
 if (!Elt->isNullValue() && !isa(Elt))
-  emitStoresForInitAfterBZero(CGM, Elt,
+  emitStoresForInitAfterBZero(Elt,
   Builder.CreateConstInBoundsGEP2_32(Loc, 0, 
i),
-  isVolatile, Builder, IsAutoInit);
+  isVolatile, IsAutoInit);
   }
 }
 
@@ -1169,10 +1168,10 @@ static Address 
createUnnamedGlobalForMemcpyFrom(CodeGenModule &CGM,
   return SrcPtr.withElementType(CGM.Int8Ty);
 }
 
-static void emitStoresForConstant(CodeGenModule &CGM, const VarDecl &D,
-  Address Loc, bool isVolatile,
-  CGBuilderTy &Builder,
-  llvm::Constant *constant, bool IsAutoInit) {
+void CodeGenFunction::emitStoresForConstant(const VarDecl &D, Address Loc,
+bool isVolatile,
+llvm::Constant *constant,
+bool IsAutoInit) {
   auto *Ty = constant->getType();
   uint64_t ConstantSize = CGM.getDataLayout().getTypeAllocSize(Ty);
   if (!ConstantSize)
@@ -1201,8 +1200,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
 constant->isNullValue() || isa(constant);
 if (!valueAlreadyCorrect) {
   Loc = Loc.withElementType(Ty);
-  emitStoresForInitAfterBZero(CGM, constant, Loc, isVolatile, Builder,
-  IsAutoInit);
+  emitStoresForInitAfterBZero(constant, Loc, isVolatile, IsAutoInit);
 }
 return;
   }
@@ -1240,7 +1238,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
   CharUnits::fromQuantity(Layout->getElementOffset(i));
   Address EltPtr = Builder.CreateConstInBoundsByteGEP(
   Loc.withElementType(CGM.Int8Ty), CurOff);
-  emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
+  emitStoresForConstant(D, EltPtr, isVolatile,
 constant->getAggregateElement(i), IsAutoInit);
 }
 return;
@@ -1251,7 +1249,7 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
 for (unsigned i = 0; i != ATy->getNumElements(); i++) {
   Address EltPtr = Builder.CreateConstGEP(
   Loc.withElementType(ATy->getElementType()), i);
-  emitStoresForConstant(CGM, D, EltPtr, isVolatile, Builder,
+  emitStoresForConstant(D, EltPtr, isVolatile,
 constant->getAggregateElement(i), IsAutoInit);
 }
 return;
@@ -1269,24 +1267,22 @@ static void emitStoresForConstant(CodeGenModule &CGM, 
const VarDecl &D,
 I->addAnnotationMetadata("auto-init");
 }
 
-static void emitStoresForZeroInit(CodeGenModule &CGM, const VarDecl 

[llvm-branch-commits] [clang] [KeyInstr][Clang] Agg init atom (PR #134635)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Agg init atom

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

shouldUseBZeroPlusStoresToInitialize

[KeyInstr] init-agg pattern

[KeyInstr][Clang] Init pattern atom

---
Full diff: https://github.com/llvm/llvm-project/pull/134635.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDecl.cpp (+7) 
- (added) clang/test/KeyInstructions/init-agg.cpp (+39) 


``diff
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 6aa9f3fa27c87..9860ab0b033bb 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -938,6 +938,7 @@ void 
CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
   isa(Init) || isa(Init) ||
   isa(Init)) {
 auto *I = Builder.CreateStore(Init, Loc, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1181,6 +1182,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
   Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
   if (canDoSingleStore) {
 auto *I = Builder.CreateStore(constant, Loc, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1193,6 +1195,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
   if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
 auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
SizeVal, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
+
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 
@@ -1217,6 +1221,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
 }
 auto *I = Builder.CreateMemSet(
 Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1263,6 +1268,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
createUnnamedGlobalForMemcpyFrom(
CGM, D, Builder, constant, Loc.getAlignment()),
SizeVal, isVolatile);
+  addInstToCurrentSourceAtom(I, nullptr);
+
   if (IsAutoInit)
 I->addAnnotationMetadata("auto-init");
 }
diff --git a/clang/test/KeyInstructions/init-agg.cpp 
b/clang/test/KeyInstructions/init-agg.cpp
new file mode 100644
index 0..f0cc67e659d95
--- /dev/null
+++ b/clang/test/KeyInstructions/init-agg.cpp
@@ -0,0 +1,39 @@
+
+// RUN: %clang -gkey-instructions %s -gmlt -gno-column-info -S -emit-llvm -o - 
-ftrivial-auto-var-init=pattern \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// The implicit-check-not is important; we don't want the GEPs created for the
+// store locations to be included in the atom group.
+
+int g;
+void a() {
+// CHECK: _Z1av()
+// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
+int A[] = { 1, 2, 3 };
+
+// CHECK: store i32 1, ptr %{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: store i32 2, ptr %{{.*}}, !dbg [[G2R1]]
+// CHECK: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr %{{.*}}, !dbg [[G2R1]]
+int B[] = { 1, 2, g };
+
+// CHECK: call void @llvm.memset{{.*}}, !dbg [[G3R1:!.*]]
+// CHECK: store i8 97{{.*}}, !dbg [[G3R1]]
+// CHECK: store i8 98{{.*}}, !dbg [[G3R1]]
+// CHECK: store i8 99{{.*}}, !dbg [[G3R1]]
+// CHECK: store i8 100{{.*}}, !dbg [[G3R1]]
+char big[65536] = { 'a', 'b', 'c', 'd' };
+
+// CHECK: call void @llvm.memset{{.*}}, !dbg [[G4R1:!.*]]
+char arr[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 
42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, };
+
+// CHECK: store i8 -86, ptr %uninit{{.*}}, !dbg [[G5R1:!.*]], !annotation
+char uninit; // -ftrivial-auto-var-init=pattern
+}
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 

[llvm-branch-commits] [clang] [KeyInstr][Clang] For stmt atom (PR #134646)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Bitfield atom (PR #134648)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyIntsr][Clang] Builtins alloca auto-init atom (PR #134651)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Assignment atom group (PR #134637)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** https://app.graphite.dev/github/pr/llvm/llvm-project/133487?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133486** https://app.graphite.dev/github/pr/llvm/llvm-project/133486?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133485** http

[llvm-branch-commits] [clang] [NFC][KeyInstr][Clang] Add some additional tests (PR #134654)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

https://github.com/OCHyams created 
https://github.com/llvm/llvm-project/pull/134654

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

new.cpp: Check store of addr and value are both added to same atom
cast.c: Check we look through casts
multi-func.c Check the atom group number is reset between functions

>From c7f302e62c367ed16c334da29e1ac1e9fb46bb7a Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Mon, 7 Apr 2025 12:18:48 +0100
Subject: [PATCH] [NFC][KeyInstr][Clang] Add some additional tests

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

new.cpp: Check store of addr and value are both added to same atom
cast.c: Check we look through casts
multi-func.c Check the atom group number is reset between functions
---
 clang/test/KeyInstructions/cast.c   | 19 +
 clang/test/KeyInstructions/multi-func.c | 18 
 clang/test/KeyInstructions/new.cpp  | 37 +
 3 files changed, 74 insertions(+)
 create mode 100644 clang/test/KeyInstructions/cast.c
 create mode 100644 clang/test/KeyInstructions/multi-func.c
 create mode 100644 clang/test/KeyInstructions/new.cpp

diff --git a/clang/test/KeyInstructions/cast.c 
b/clang/test/KeyInstructions/cast.c
new file mode 100644
index 0..b89edcc3089fb
--- /dev/null
+++ b/clang/test/KeyInstructions/cast.c
@@ -0,0 +1,19 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+float g;
+void a() {
+// CHECK: %0 = load float, ptr @g{{.*}}, !dbg [[G1R3:!.*]]
+// CHECK: %conv = fptosi float %0 to i32{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store i32 %conv, ptr %a{{.*}}, !dbg [[G1R1:!.*]]
+int a = g;
+// CHECK: ret{{.*}}, !dbg [[G2R1:!.*]]
+}
+
+// CHECK: [[G1R3]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 3)
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
diff --git a/clang/test/KeyInstructions/multi-func.c 
b/clang/test/KeyInstructions/multi-func.c
new file mode 100644
index 0..7d441e43444b2
--- /dev/null
+++ b/clang/test/KeyInstructions/multi-func.c
@@ -0,0 +1,18 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Check atomGroup is reset to start at 1 in each function.
+
+// CHECK: ret{{.*}}, !dbg [[AG:!.*]]
+void a() {}
+
+// CHECK: ret{{.*}}, !dbg [[BG:!.*]]
+void b() {}
+
+// CHECK: [[A:!.*]] = distinct !DISubprogram(name: "a",
+// CHECK: [[AG]] = !DILocation({{.*}}, scope: [[A]], atomGroup: 1, atomRank: 1)
+// CHECK: [[B:!.*]] = distinct !DISubprogram(name: "b",
+// CHECK: [[BG]] = !DILocation({{.*}}, scope: [[B]], atomGroup: 1, atomRank: 1)
diff --git a/clang/test/KeyInstructions/new.cpp 
b/clang/test/KeyInstructions/new.cpp
new file mode 100644
index 0..9476e311e746f
--- /dev/null
+++ b/clang/test/KeyInstructions/new.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - 
-Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Check both the addr-store and value-store are part of the same atom.
+
+void f(int x) {
+// CHECK: %call = call noalias noundef nonnull ptr @_Znwm{{.*}}, !dbg 
[[G1R2_C12:!.*]]
+// CHECK: %0 = load i32, ptr %x.addr{{.*}}, !dbg [[G1R2_C20:!.*]]
+// CHECK: store i32 %0, ptr %call{{.*

[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign vector element atom (PR #134649)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Assign matrix element atom (PR #134650)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyInstr] Complex assignment atoms (PR #134638)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134638.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+8-2) 
- (added) clang/test/KeyInstructions/complex.c (+40) 


``diff
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index a7c8b96da6853..ff960e76e8693 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -456,8 +456,12 @@ void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy 
Val, LValue lvalue,
   Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
   Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
 
-  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
-  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
+  auto *R =
+  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
+  CGF.addInstToCurrentSourceAtom(R, Val.first);
+  auto *I =
+  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
+  CGF.addInstToCurrentSourceAtom(I, Val.second);
 }
 
 
@@ -1204,6 +1208,7 @@ LValue ComplexExprEmitter::
 EmitCompoundAssignLValue(const CompoundAssignOperator *E,
   ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
  RValue &Val) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   TestAndClearIgnoreReal();
   TestAndClearIgnoreImag();
   QualType LHSTy = E->getLHS()->getType();
@@ -1351,6 +1356,7 @@ LValue ComplexExprEmitter::EmitBinAssignLValue(const 
BinaryOperator *E,
 }
 
 ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   ComplexPairTy Val;
   LValue LV = EmitBinAssignLValue(E, Val);
 
diff --git a/clang/test/KeyInstructions/complex.c 
b/clang/test/KeyInstructions/complex.c
new file mode 100644
index 0..b97314e815bdc
--- /dev/null
+++ b/clang/test/KeyInstructions/complex.c
@@ -0,0 +1,40 @@
+
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm 
-o - -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o 
- -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+_Complex float ci;
+void test() {
+// CHECK: %ci.real = load float, ptr @ci{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: %ci.imag = load float, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G1R2]]
+// CHECK: store float %ci.real, ptr %lc.realp{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: store float %ci.imag, ptr %lc.imagp{{.*}}, !dbg [[G1R1]]
+  _Complex float lc = ci;
+
+// CHECK: %ci.real1 = load float, ptr @ci{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: %ci.imag2 = load float, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R2]]
+// CHECK: store float %ci.real1, ptr @ci{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: store float %ci.imag2, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R1]]
+  ci = ci;
+
+// CHECK: %add.r = fadd float %ci.real5, %ci.real3, !dbg [[G3R2:!.*]]
+// CHECK: %add.i = fadd float %ci.imag6, %ci.imag4, !dbg [[G3R2]]
+// CHECK: store float %add.r, ptr @ci{{.*}}, !dbg [[G3R1:!.*]]
+// CHECK: store float %add.i, ptr getelementptr inbounds nuw ({ float, float 
}, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G3R1]]
+  ci += ci;
+
+// CHECK: %add = fadd float %0, %1, !dbg [[G4R2:!.*]]
+// CHECK: store float %add, ptr getelementptr inbounds nuw ({ float, float }, 
ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G4R1:!.*]]
+  __imag ci = __imag ci + __imag ci;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

``

[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Static variable init atom (PR #134636)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134636.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDecl.cpp (+3-1) 
- (added) clang/test/KeyInstructions/init-static.cpp (+12) 


``diff
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 9860ab0b033bb..3c5597a00f2ea 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -428,8 +428,10 @@ void CodeGenFunction::EmitStaticVarDecl(const VarDecl &D,
   bool isCudaSharedVar = getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
  D.hasAttr();
   // If this value has an initializer, emit it.
-  if (D.getInit() && !isCudaSharedVar)
+  if (D.getInit() && !isCudaSharedVar) {
+ApplyAtomGroup Grp(getDebugInfo());
 var = AddInitializerToStaticVarDecl(D, var);
+  }
 
   var->setAlignment(alignment.getAsAlign());
 
diff --git a/clang/test/KeyInstructions/init-static.cpp 
b/clang/test/KeyInstructions/init-static.cpp
new file mode 100644
index 0..82e14b59df5e5
--- /dev/null
+++ b/clang/test/KeyInstructions/init-static.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o -\
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+void g(int *a) {
+// CHECK: %2 = load ptr, ptr %a.addr{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store ptr %2, ptr @_ZZ1gPiE1b{{.*}}, !dbg [[G1R1:!.*]]
+static int &b = *a;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+

``




https://github.com/llvm/llvm-project/pull/134636
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Aggregate init + copy (PR #134639)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Aggregate init + copy

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

[KeyInstr][Clang] Agg copy atom

---
Full diff: https://github.com/llvm/llvm-project/pull/134639.diff


4 Files Affected:

- (modified) clang/lib/CodeGen/CGExprAgg.cpp (+3-1) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+1) 
- (added) clang/test/KeyInstructions/agg.c (+17) 
- (modified) clang/test/KeyInstructions/init-agg.c (+2) 


``diff
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index c8bdda375d1b1..26bc2666d9759 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1332,6 +1332,7 @@ static bool isBlockVarRef(const Expr *E) {
 }
 
 void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   // For an assignment to work, the value on the right has
   // to be compatible with the value on the left.
   assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
@@ -2394,7 +2395,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, 
LValue Src, QualType Ty,
 }
   }
 
-  auto Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
+  auto *Inst = Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, isVolatile);
+  addInstToCurrentSourceAtom(Inst, nullptr);
 
   // Determine the metadata to describe the position of any padding in this
   // memcpy, as well as the TBAA tags for the members of the struct, in case
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index d8b1c4e4efb77..0a72784f311e5 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -3042,6 +3042,7 @@ class CodeGenFunction : public CodeGenTypeCache {
 
   /// Emit an aggregate assignment.
   void EmitAggregateAssign(LValue Dest, LValue Src, QualType EltTy) {
+ApplyAtomGroup Grp(getDebugInfo());
 bool IsVolatile = hasVolatileMember(EltTy);
 EmitAggregateCopy(Dest, Src, EltTy, AggValueSlot::MayOverlap, IsVolatile);
   }
diff --git a/clang/test/KeyInstructions/agg.c b/clang/test/KeyInstructions/agg.c
new file mode 100644
index 0..177e1ea8b9fc1
--- /dev/null
+++ b/clang/test/KeyInstructions/agg.c
@@ -0,0 +1,17 @@
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+typedef struct { int a, b, c; } Struct;
+void fun(Struct a) {
+// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
+  Struct b = a;
+
+// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G2R1:!.*]]
+  b = a;
+}
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
diff --git a/clang/test/KeyInstructions/init-agg.c 
b/clang/test/KeyInstructions/init-agg.c
index ad298715286cd..dc3ccaedc57b5 100644
--- a/clang/test/KeyInstructions/init-agg.c
+++ b/clang/test/KeyInstructions/init-agg.c
@@ -9,6 +9,8 @@
 // store locations to be included in the atom group.
 
 int g;
+typedef struct { int a, b, c; } Struct;
+Struct g2;
 void a() {
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
 int A[] = { 1, 2, 3 };

``




https://github.com/llvm/llvm-project/pull/134639
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr] Complex assignment atoms (PR #134638)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134638.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExprComplex.cpp (+8-2) 
- (added) clang/test/KeyInstructions/complex.c (+40) 


``diff
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index a7c8b96da6853..ff960e76e8693 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -456,8 +456,12 @@ void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy 
Val, LValue lvalue,
   Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
   Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
 
-  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
-  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
+  auto *R =
+  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
+  CGF.addInstToCurrentSourceAtom(R, Val.first);
+  auto *I =
+  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
+  CGF.addInstToCurrentSourceAtom(I, Val.second);
 }
 
 
@@ -1204,6 +1208,7 @@ LValue ComplexExprEmitter::
 EmitCompoundAssignLValue(const CompoundAssignOperator *E,
   ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
  RValue &Val) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   TestAndClearIgnoreReal();
   TestAndClearIgnoreImag();
   QualType LHSTy = E->getLHS()->getType();
@@ -1351,6 +1356,7 @@ LValue ComplexExprEmitter::EmitBinAssignLValue(const 
BinaryOperator *E,
 }
 
 ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   ComplexPairTy Val;
   LValue LV = EmitBinAssignLValue(E, Val);
 
diff --git a/clang/test/KeyInstructions/complex.c 
b/clang/test/KeyInstructions/complex.c
new file mode 100644
index 0..b97314e815bdc
--- /dev/null
+++ b/clang/test/KeyInstructions/complex.c
@@ -0,0 +1,40 @@
+
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm 
-o - -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o 
- -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+_Complex float ci;
+void test() {
+// CHECK: %ci.real = load float, ptr @ci{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: %ci.imag = load float, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G1R2]]
+// CHECK: store float %ci.real, ptr %lc.realp{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: store float %ci.imag, ptr %lc.imagp{{.*}}, !dbg [[G1R1]]
+  _Complex float lc = ci;
+
+// CHECK: %ci.real1 = load float, ptr @ci{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: %ci.imag2 = load float, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R2]]
+// CHECK: store float %ci.real1, ptr @ci{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: store float %ci.imag2, ptr getelementptr inbounds nuw ({ float, 
float }, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G2R1]]
+  ci = ci;
+
+// CHECK: %add.r = fadd float %ci.real5, %ci.real3, !dbg [[G3R2:!.*]]
+// CHECK: %add.i = fadd float %ci.imag6, %ci.imag4, !dbg [[G3R2]]
+// CHECK: store float %add.r, ptr @ci{{.*}}, !dbg [[G3R1:!.*]]
+// CHECK: store float %add.i, ptr getelementptr inbounds nuw ({ float, float 
}, ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G3R1]]
+  ci += ci;
+
+// CHECK: %add = fadd float %0, %1, !dbg [[G4R2:!.*]]
+// CHECK: store float %add, ptr getelementptr inbounds nuw ({ float, float }, 
ptr @ci, i32 0, i32 1){{.*}}, !dbg [[G4R1:!.*]]
+  __imag ci = __imag ci + __imag ci;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

``




http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Catch variable init atom (PR #134641)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Coerced store atoms (PR #134653)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Do stmt atom (PR #134644)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** http

[llvm-branch-commits] [clang] [NFC][KeyInstr][Clang] Add some additional tests (PR #134654)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Ret atom (PR #134652)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134654** https://app.graphite.dev/github/pr/llvm/llvm-project/134654?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134653** https://app.graphite.dev/github/pr/llvm/llvm-project/134653?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134652** https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134652?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134651** https://app.graphite.dev/github/pr/llvm/llvm-project/134651?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134650** https://app.graphite.dev/github/pr/llvm/llvm-project/134650?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134649** https://app.graphite.dev/github/pr/llvm/llvm-project/134649?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134648** https://app.graphite.dev/github/pr/llvm/llvm-project/134648?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134647** https://app.graphite.dev/github/pr/llvm/llvm-project/134647?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134646** https://app.graphite.dev/github/pr/llvm/llvm-project/134646?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134645** https://app.graphite.dev/github/pr/llvm/llvm-project/134645?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134644** https://app.graphite.dev/github/pr/llvm/llvm-project/134644?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134643** https://app.graphite.dev/github/pr/llvm/llvm-project/134643?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134642** https://app.graphite.dev/github/pr/llvm/llvm-project/134642?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134641** https://app.graphite.dev/github/pr/llvm/llvm-project/134641?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** http

[llvm-branch-commits] [clang] [KeyInstr][Clang] Bitfield atom (PR #134648)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134648.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+2-1) 
- (added) clang/test/KeyInstructions/bitfield.cpp (+13) 


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 7408c498b3a1a..a5e113a1a4397 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2614,7 +2614,8 @@ void 
CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
   }
 
   // Write the new value back out.
-  Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  auto *I = Builder.CreateStore(SrcVal, Ptr, Dst.isVolatileQualified());
+  addInstToCurrentSourceAtom(I, SrcVal);
 
   // Return the new value of the bit-field, if requested.
   if (Result) {
diff --git a/clang/test/KeyInstructions/bitfield.cpp 
b/clang/test/KeyInstructions/bitfield.cpp
new file mode 100644
index 0..0586050ba8397
--- /dev/null
+++ b/clang/test/KeyInstructions/bitfield.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+struct S { int a:3; };
+
+void foo(int x, S s) {
+// CHECK: %bf.set = or i8 %bf.clear, %bf.value, !dbg [[G1R2:!.*]]
+// CHECK: store i8 %bf.set, ptr %s, align 4, !dbg [[G1R1:!.*]]
+  s.a = x;
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134648
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Member initalization atom (PR #134640)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134640.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGClass.cpp (+1) 
- (added) clang/test/KeyInstructions/init-member.cpp (+22) 


``diff
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 98c93b5bb4883..8ef795bfee410 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -1338,6 +1338,7 @@ void CodeGenFunction::EmitCtorPrologue(const 
CXXConstructorDecl *CD,
 assert(!Member->isBaseInitializer());
 assert(Member->isAnyMemberInitializer() &&
"Delegating initializer on non-delegating constructor");
+ApplyAtomGroup Grp(getDebugInfo());
 CM.addMemberInitializer(Member);
   }
   CM.finish();
diff --git a/clang/test/KeyInstructions/init-member.cpp 
b/clang/test/KeyInstructions/init-member.cpp
new file mode 100644
index 0..60949bd8a604a
--- /dev/null
+++ b/clang/test/KeyInstructions/init-member.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s
+
+struct B {
+  float y;
+};
+
+class Cls {
+  public:
+int x = 1;
+B b = {5.f};
+};
+
+void fun() {
+  Cls c;
+}
+
+// CHECK: store i32 1, ptr %x{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: store float 5.00e+00, ptr %y{{.*}}, !dbg [[G2R1:!.*]]
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134640
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] For range stmt atoms (PR #134647)

2025-04-07 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 375ca9f7b756d01da82772f9316ab20b56214d91 
2484a49c8f259891882a18636b769bf4c06cb8ce --extensions cpp -- 
clang/test/KeyInstructions/for-range.cpp clang/lib/CodeGen/CGStmt.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 9292be24fc..2696bc9cc3 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1535,7 +1535,7 @@ CodeGenFunction::EmitCXXForRangeStmt(const 
CXXForRangeStmt &S,
 ConvergenceTokenStack.pop_back();
 
   // We want the for closing brace to be step-able on to match existing
-  // behaviour. 
+  // behaviour.
   addInstToNewSourceAtom(ForBody->getTerminator(), nullptr);
 }
 

``




https://github.com/llvm/llvm-project/pull/134647
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Ret atom (PR #134652)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Ret atom

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

[KeyInstr][Clang] Update tests with ret atoms

---

Patch is 21.44 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/134652.diff


21 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+5-1) 
- (modified) clang/lib/CodeGen/CGCleanup.cpp (+2) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+9-4) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+16) 
- (modified) clang/test/KeyInstructions/agg.c (+3) 
- (modified) clang/test/KeyInstructions/assign-scalar.c (+3) 
- (modified) clang/test/KeyInstructions/bitfield.cpp (+3) 
- (modified) clang/test/KeyInstructions/builtin.c (+3) 
- (modified) clang/test/KeyInstructions/complex.c (+3) 
- (modified) clang/test/KeyInstructions/do.c (+3) 
- (modified) clang/test/KeyInstructions/for.c (+3) 
- (modified) clang/test/KeyInstructions/if.c (+4-1) 
- (modified) clang/test/KeyInstructions/init-agg.c (+3) 
- (modified) clang/test/KeyInstructions/init-member.cpp (+2) 
- (modified) clang/test/KeyInstructions/init-scalar.c (+2-2) 
- (modified) clang/test/KeyInstructions/init-static.cpp (+2-1) 
- (added) clang/test/KeyInstructions/return-va-arg.c (+25) 
- (added) clang/test/KeyInstructions/return.c (+90) 
- (modified) clang/test/KeyInstructions/switch.c (+3) 
- (modified) clang/test/KeyInstructions/try-catch.cpp (+3) 
- (modified) clang/test/KeyInstructions/while.c (+3) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7aa77e55dbfcc..dba3fadba4f60 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3883,7 +3883,8 @@ void CodeGenFunction::EmitFunctionEpilog(const 
CGFunctionInfo &FI,
 
   // Functions with no result always return void.
   if (!ReturnValue.isValid()) {
-Builder.CreateRetVoid();
+auto *I = Builder.CreateRetVoid();
+addRetToOverrideOrNewSourceAtom(I, nullptr);
 return;
   }
 
@@ -4065,6 +4066,9 @@ void CodeGenFunction::EmitFunctionEpilog(const 
CGFunctionInfo &FI,
 
   if (RetDbgLoc)
 Ret->setDebugLoc(std::move(RetDbgLoc));
+
+  llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr;
+  addRetToOverrideOrNewSourceAtom(cast(Ret), Backup);
 }
 
 void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 7e1c5b7da9552..7292dcd47172c 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -1118,6 +1118,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest 
Dest) {
 
   // Create the branch.
   llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
+  // This is the primary instruction for this atom, acting in place of a ret.
+  addInstToCurrentSourceAtom(BI, nullptr);
 
   // Calculate the innermost active normal cleanup.
   EHScopeStack::stable_iterator
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 9292be24fc12e..21c2dd14799dd 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1594,6 +1594,7 @@ static bool isSwiftAsyncCallee(const CallExpr *CE) {
 /// if the function returns void, or may be missing one if the function returns
 /// non-void.  Fun stuff :).
 void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
+  ApplyAtomGroup Grp(getDebugInfo());
   if (requiresReturnValueCheck()) {
 llvm::Constant *SLoc = EmitCheckSourceLocation(S.getBeginLoc());
 auto *SLocPtr =
@@ -1603,6 +1604,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr);
 assert(ReturnLocation.isValid() && "No valid return location");
 Builder.CreateStore(SLocPtr, ReturnLocation);
+//*OCH?*//
   }
 
   // Returning from an outlined SEH helper is UB, and we already warn on it.
@@ -1669,16 +1671,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt 
&S) {
 // If this function returns a reference, take the address of the expression
 // rather than the value.
 RValue Result = EmitReferenceBindingToExpr(RV);
-Builder.CreateStore(Result.getScalarVal(), ReturnValue);
+auto *I = Builder.CreateStore(Result.getScalarVal(), ReturnValue);
+addInstToCurrentSourceAtom(I, I->getValueOperand());
   } else {
 switch (getEvaluationKind(RV->getType())) {
 case TE

[llvm-branch-commits] [clang] [KeyInstr][Clang] Ret atom (PR #134652)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Ret atom

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

[KeyInstr][Clang] Update tests with ret atoms

---

Patch is 21.44 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/134652.diff


21 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+5-1) 
- (modified) clang/lib/CodeGen/CGCleanup.cpp (+2) 
- (modified) clang/lib/CodeGen/CGStmt.cpp (+9-4) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+16) 
- (modified) clang/test/KeyInstructions/agg.c (+3) 
- (modified) clang/test/KeyInstructions/assign-scalar.c (+3) 
- (modified) clang/test/KeyInstructions/bitfield.cpp (+3) 
- (modified) clang/test/KeyInstructions/builtin.c (+3) 
- (modified) clang/test/KeyInstructions/complex.c (+3) 
- (modified) clang/test/KeyInstructions/do.c (+3) 
- (modified) clang/test/KeyInstructions/for.c (+3) 
- (modified) clang/test/KeyInstructions/if.c (+4-1) 
- (modified) clang/test/KeyInstructions/init-agg.c (+3) 
- (modified) clang/test/KeyInstructions/init-member.cpp (+2) 
- (modified) clang/test/KeyInstructions/init-scalar.c (+2-2) 
- (modified) clang/test/KeyInstructions/init-static.cpp (+2-1) 
- (added) clang/test/KeyInstructions/return-va-arg.c (+25) 
- (added) clang/test/KeyInstructions/return.c (+90) 
- (modified) clang/test/KeyInstructions/switch.c (+3) 
- (modified) clang/test/KeyInstructions/try-catch.cpp (+3) 
- (modified) clang/test/KeyInstructions/while.c (+3) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7aa77e55dbfcc..dba3fadba4f60 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3883,7 +3883,8 @@ void CodeGenFunction::EmitFunctionEpilog(const 
CGFunctionInfo &FI,
 
   // Functions with no result always return void.
   if (!ReturnValue.isValid()) {
-Builder.CreateRetVoid();
+auto *I = Builder.CreateRetVoid();
+addRetToOverrideOrNewSourceAtom(I, nullptr);
 return;
   }
 
@@ -4065,6 +4066,9 @@ void CodeGenFunction::EmitFunctionEpilog(const 
CGFunctionInfo &FI,
 
   if (RetDbgLoc)
 Ret->setDebugLoc(std::move(RetDbgLoc));
+
+  llvm::Value *Backup = RV ? Ret->getOperand(0) : nullptr;
+  addRetToOverrideOrNewSourceAtom(cast(Ret), Backup);
 }
 
 void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 7e1c5b7da9552..7292dcd47172c 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -1118,6 +1118,8 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest 
Dest) {
 
   // Create the branch.
   llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
+  // This is the primary instruction for this atom, acting in place of a ret.
+  addInstToCurrentSourceAtom(BI, nullptr);
 
   // Calculate the innermost active normal cleanup.
   EHScopeStack::stable_iterator
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 9292be24fc12e..21c2dd14799dd 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1594,6 +1594,7 @@ static bool isSwiftAsyncCallee(const CallExpr *CE) {
 /// if the function returns void, or may be missing one if the function returns
 /// non-void.  Fun stuff :).
 void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
+  ApplyAtomGroup Grp(getDebugInfo());
   if (requiresReturnValueCheck()) {
 llvm::Constant *SLoc = EmitCheckSourceLocation(S.getBeginLoc());
 auto *SLocPtr =
@@ -1603,6 +1604,7 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 CGM.getSanitizerMetadata()->disableSanitizerForGlobal(SLocPtr);
 assert(ReturnLocation.isValid() && "No valid return location");
 Builder.CreateStore(SLocPtr, ReturnLocation);
+//*OCH?*//
   }
 
   // Returning from an outlined SEH helper is UB, and we already warn on it.
@@ -1669,16 +1671,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt 
&S) {
 // If this function returns a reference, take the address of the expression
 // rather than the value.
 RValue Result = EmitReferenceBindingToExpr(RV);
-Builder.CreateStore(Result.getScalarVal(), ReturnValue);
+auto *I = Builder.CreateStore(Result.getScalarVal(), ReturnValue);
+addInstToCurrentSourceAtom(I, I->getValueOperand());
   } else {
 switch (getEvaluationKind(RV->getType())) {
 case TEK_Scalar

[llvm-branch-commits] [clang] [KeyIntsr][Clang] Builtins alloca auto-init atom (PR #134651)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyIntsr][Clang] Builtins alloca auto-init atom

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

[KeyInstr][Clang] matrix store atom

[KeyInstr][Clang] Store-like builtin atoms

---
Full diff: https://github.com/llvm/llvm-project/pull/134651.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+23-10) 
- (added) clang/test/KeyInstructions/builtin.c (+77) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 91ac7c5847b02..a735d5fa151ac 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -29,6 +29,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/IntrinsicsX86.h"
@@ -138,6 +139,7 @@ static void initializeAlloca(CodeGenFunction &CGF, 
AllocaInst *AI, Value *Size,
   if (CGF.CGM.stopAutoInit())
 return;
   auto *I = CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
+  CGF.addInstToCurrentSourceAtom(I, nullptr);
   I->addAnnotationMetadata("auto-init");
 }
 
@@ -3937,6 +3939,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Matrix, Dst.emitRawPointer(*this),
 Align(Dst.getAlignment().getQuantity()), Stride, IsVolatile,
 MatrixTy->getNumRows(), MatrixTy->getNumColumns());
+addInstToNewSourceAtom(cast(Result), nullptr);
 return RValue::get(Result);
   }
 
@@ -4097,7 +4100,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Value *SizeVal = EmitScalarExpr(E->getArg(1));
 EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
 E->getArg(0)->getExprLoc(), FD, 0);
-Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
+auto *I = Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(nullptr);
   }
 
@@ -4112,7 +4116,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
 E->getArg(1)->getType(), E->getArg(1)->getExprLoc(), 
FD,
 0);
-Builder.CreateMemMove(Dest, Src, SizeVal, false);
+auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(nullptr);
   }
 
@@ -4125,7 +4130,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Value *SizeVal = EmitScalarExpr(E->getArg(2));
 EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
 EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
-Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 if (BuiltinID == Builtin::BImempcpy ||
 BuiltinID == Builtin::BI__builtin_mempcpy)
   return RValue::get(Builder.CreateInBoundsGEP(
@@ -4141,7 +4147,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
 EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
 EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
-Builder.CreateMemCpyInline(Dest, Src, Size);
+auto *I = Builder.CreateMemCpyInline(Dest, Src, Size);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(nullptr);
   }
 
@@ -4162,7 +4169,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Address Dest = EmitPointerWithAlignment(E->getArg(0));
 Address Src = EmitPointerWithAlignment(E->getArg(1));
 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
-Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(Dest, *this);
   }
 
@@ -4188,7 +4196,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Address Dest = EmitPointerWithAlignment(E->getArg(0));
 Address Src = EmitPointerWithAlignment(E->getArg(1));
 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
- 

[llvm-branch-commits] [clang] [KeyIntsr][Clang] Builtins alloca auto-init atom (PR #134651)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyIntsr][Clang] Builtins alloca auto-init atom

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

[KeyInstr][Clang] matrix store atom

[KeyInstr][Clang] Store-like builtin atoms

---
Full diff: https://github.com/llvm/llvm-project/pull/134651.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+23-10) 
- (added) clang/test/KeyInstructions/builtin.c (+77) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 91ac7c5847b02..a735d5fa151ac 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -29,6 +29,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/IntrinsicsX86.h"
@@ -138,6 +139,7 @@ static void initializeAlloca(CodeGenFunction &CGF, 
AllocaInst *AI, Value *Size,
   if (CGF.CGM.stopAutoInit())
 return;
   auto *I = CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
+  CGF.addInstToCurrentSourceAtom(I, nullptr);
   I->addAnnotationMetadata("auto-init");
 }
 
@@ -3937,6 +3939,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Matrix, Dst.emitRawPointer(*this),
 Align(Dst.getAlignment().getQuantity()), Stride, IsVolatile,
 MatrixTy->getNumRows(), MatrixTy->getNumColumns());
+addInstToNewSourceAtom(cast(Result), nullptr);
 return RValue::get(Result);
   }
 
@@ -4097,7 +4100,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Value *SizeVal = EmitScalarExpr(E->getArg(1));
 EmitNonNullArgCheck(Dest, E->getArg(0)->getType(),
 E->getArg(0)->getExprLoc(), FD, 0);
-Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
+auto *I = Builder.CreateMemSet(Dest, Builder.getInt8(0), SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(nullptr);
   }
 
@@ -4112,7 +4116,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 EmitNonNullArgCheck(RValue::get(Dest.emitRawPointer(*this)),
 E->getArg(1)->getType(), E->getArg(1)->getExprLoc(), 
FD,
 0);
-Builder.CreateMemMove(Dest, Src, SizeVal, false);
+auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(nullptr);
   }
 
@@ -4125,7 +4130,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Value *SizeVal = EmitScalarExpr(E->getArg(2));
 EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
 EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
-Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 if (BuiltinID == Builtin::BImempcpy ||
 BuiltinID == Builtin::BI__builtin_mempcpy)
   return RValue::get(Builder.CreateInBoundsGEP(
@@ -4141,7 +4147,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 E->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
 EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
 EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
-Builder.CreateMemCpyInline(Dest, Src, Size);
+auto *I = Builder.CreateMemCpyInline(Dest, Src, Size);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(nullptr);
   }
 
@@ -4162,7 +4169,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Address Dest = EmitPointerWithAlignment(E->getArg(0));
 Address Src = EmitPointerWithAlignment(E->getArg(1));
 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), Size);
-Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+auto *I = Builder.CreateMemCpy(Dest, Src, SizeVal, false);
+addInstToNewSourceAtom(I, nullptr);
 return RValue::get(Dest, *this);
   }
 
@@ -4188,7 +4196,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Address Dest = EmitPointerWithAlignment(E->getArg(0));
 Address Src = EmitPointerWithAlignment(E->getArg(1));
 Value *SizeVal = llvm::ConstantInt::get(Builder.getContext(), S

[llvm-branch-commits] [clang] [KeyInstr][Clang] Coerced store atoms (PR #134653)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Coerced store atoms

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

[KeyInstr][Clang] Coerced to int atom

[KeyInstr][Clang] Coerced ptr to int atom

[KeyInstr][Clang] Coerce packed struct atom

[KeyInstr][Clang] Coerce through memory atom

---
Full diff: https://github.com/llvm/llvm-project/pull/134653.diff


5 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+13-8) 
- (added) clang/test/KeyInstructions/coerced-packed.c (+22) 
- (added) clang/test/KeyInstructions/coerced-ptr.c (+21) 
- (added) clang/test/KeyInstructions/coerced-through-memory.c (+26) 
- (added) clang/test/KeyInstructions/coerced.c (+40) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index dba3fadba4f60..a794b884a6feb 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1400,7 +1400,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
 SrcSize == CGM.getDataLayout().getTypeAllocSize(Dst.getElementType())) 
{
   // If the value is supposed to be a pointer, convert it before storing 
it.
   Src = CoerceIntOrPtrToIntOrPtr(Src, Dst.getElementType(), *this);
-  Builder.CreateStore(Src, Dst, DstIsVolatile);
+  auto *I = Builder.CreateStore(Src, Dst, DstIsVolatile);
+  addInstToCurrentSourceAtom(I, Src);
 } else if (llvm::StructType *STy =
dyn_cast(Src->getType())) {
   // Prefer scalar stores to first-class aggregate stores.
@@ -1408,16 +1409,19 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
   for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
 Address EltPtr = Builder.CreateStructGEP(Dst, i);
 llvm::Value *Elt = Builder.CreateExtractValue(Src, i);
-Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
+auto *I = Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
+addInstToCurrentSourceAtom(I, Elt);
   }
 } else {
-  Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
+  auto * I = Builder.CreateStore(Src, Dst.withElementType(SrcTy), 
DstIsVolatile);
+  addInstToCurrentSourceAtom(I, Src);
 }
   } else if (SrcTy->isIntegerTy()) {
 // If the source is a simple integer, coerce it directly.
 llvm::Type *DstIntTy = Builder.getIntNTy(DstSize.getFixedValue() * 8);
 Src = CoerceIntOrPtrToIntOrPtr(Src, DstIntTy, *this);
-Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile);
+auto *I = Builder.CreateStore(Src, Dst.withElementType(DstIntTy), 
DstIsVolatile);
+addInstToCurrentSourceAtom(I, Src);
   } else {
 // Otherwise do coercion through memory. This is stupid, but
 // simple.
@@ -1431,10 +1435,11 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
 RawAddress Tmp =
 CreateTempAllocaForCoercion(*this, SrcTy, Dst.getAlignment());
 Builder.CreateStore(Src, Tmp);
-Builder.CreateMemCpy(Dst.emitRawPointer(*this),
- Dst.getAlignment().getAsAlign(), Tmp.getPointer(),
- Tmp.getAlignment().getAsAlign(),
- Builder.CreateTypeSize(IntPtrTy, DstSize));
+auto *I = Builder.CreateMemCpy(
+Dst.emitRawPointer(*this), Dst.getAlignment().getAsAlign(),
+Tmp.getPointer(), Tmp.getAlignment().getAsAlign(),
+Builder.CreateTypeSize(IntPtrTy, DstSize));
+addInstToCurrentSourceAtom(I, Src);
   }
 }
 
diff --git a/clang/test/KeyInstructions/coerced-packed.c 
b/clang/test/KeyInstructions/coerced-packed.c
new file mode 100644
index 0..476d3f742cec2
--- /dev/null
+++ b/clang/test/KeyInstructions/coerced-packed.c
@@ -0,0 +1,22 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o - -target arm64-apple-ios11 \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o - -target arm64-apple-ios11 \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+typedef struct {
+  char a;
+  int x;
+} __attribute((packed)) S;
+
+S getS();
+void f() {
+// CHECK: [[call:%.*]] = call i40{{.*}}getS{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store i40 [[call]], ptr %s, align 1, !dbg [[G1R1:!.*]]
+S s = getS();

[llvm-branch-commits] [clang] [KeyInstr][Clang] Coerced store atoms (PR #134653)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Coerced store atoms

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

[KeyInstr][Clang] Coerced to int atom

[KeyInstr][Clang] Coerced ptr to int atom

[KeyInstr][Clang] Coerce packed struct atom

[KeyInstr][Clang] Coerce through memory atom

---
Full diff: https://github.com/llvm/llvm-project/pull/134653.diff


5 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+13-8) 
- (added) clang/test/KeyInstructions/coerced-packed.c (+22) 
- (added) clang/test/KeyInstructions/coerced-ptr.c (+21) 
- (added) clang/test/KeyInstructions/coerced-through-memory.c (+26) 
- (added) clang/test/KeyInstructions/coerced.c (+40) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index dba3fadba4f60..a794b884a6feb 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1400,7 +1400,8 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
 SrcSize == CGM.getDataLayout().getTypeAllocSize(Dst.getElementType())) 
{
   // If the value is supposed to be a pointer, convert it before storing 
it.
   Src = CoerceIntOrPtrToIntOrPtr(Src, Dst.getElementType(), *this);
-  Builder.CreateStore(Src, Dst, DstIsVolatile);
+  auto *I = Builder.CreateStore(Src, Dst, DstIsVolatile);
+  addInstToCurrentSourceAtom(I, Src);
 } else if (llvm::StructType *STy =
dyn_cast(Src->getType())) {
   // Prefer scalar stores to first-class aggregate stores.
@@ -1408,16 +1409,19 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
   for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
 Address EltPtr = Builder.CreateStructGEP(Dst, i);
 llvm::Value *Elt = Builder.CreateExtractValue(Src, i);
-Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
+auto *I = Builder.CreateStore(Elt, EltPtr, DstIsVolatile);
+addInstToCurrentSourceAtom(I, Elt);
   }
 } else {
-  Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
+  auto * I = Builder.CreateStore(Src, Dst.withElementType(SrcTy), 
DstIsVolatile);
+  addInstToCurrentSourceAtom(I, Src);
 }
   } else if (SrcTy->isIntegerTy()) {
 // If the source is a simple integer, coerce it directly.
 llvm::Type *DstIntTy = Builder.getIntNTy(DstSize.getFixedValue() * 8);
 Src = CoerceIntOrPtrToIntOrPtr(Src, DstIntTy, *this);
-Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile);
+auto *I = Builder.CreateStore(Src, Dst.withElementType(DstIntTy), 
DstIsVolatile);
+addInstToCurrentSourceAtom(I, Src);
   } else {
 // Otherwise do coercion through memory. This is stupid, but
 // simple.
@@ -1431,10 +1435,11 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
 RawAddress Tmp =
 CreateTempAllocaForCoercion(*this, SrcTy, Dst.getAlignment());
 Builder.CreateStore(Src, Tmp);
-Builder.CreateMemCpy(Dst.emitRawPointer(*this),
- Dst.getAlignment().getAsAlign(), Tmp.getPointer(),
- Tmp.getAlignment().getAsAlign(),
- Builder.CreateTypeSize(IntPtrTy, DstSize));
+auto *I = Builder.CreateMemCpy(
+Dst.emitRawPointer(*this), Dst.getAlignment().getAsAlign(),
+Tmp.getPointer(), Tmp.getAlignment().getAsAlign(),
+Builder.CreateTypeSize(IntPtrTy, DstSize));
+addInstToCurrentSourceAtom(I, Src);
   }
 }
 
diff --git a/clang/test/KeyInstructions/coerced-packed.c 
b/clang/test/KeyInstructions/coerced-packed.c
new file mode 100644
index 0..476d3f742cec2
--- /dev/null
+++ b/clang/test/KeyInstructions/coerced-packed.c
@@ -0,0 +1,22 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o - -target arm64-apple-ios11 \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o - -target arm64-apple-ios11 \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+typedef struct {
+  char a;
+  int x;
+} __attribute((packed)) S;
+
+S getS();
+void f() {
+// CHECK: [[call:%.*]] = call i40{{.*}}getS{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store i40 [[call]], ptr %s, align 1, !dbg [[G1R1:!.*]]
+S s = getS();
+// CHEC

[llvm-branch-commits] [llvm] [LV] Reduce register usage for scaled reductions (PR #133090)

2025-04-07 Thread Sam Tebbs via llvm-branch-commits

https://github.com/SamTebbs33 edited 
https://github.com/llvm/llvm-project/pull/133090
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [NFC][KeyInstr][Clang] Add some additional tests (PR #134654)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

new.cpp: Check store of addr and value are both added to same atom
cast.c: Check we look through casts
multi-func.c Check the atom group number is reset between functions

---
Full diff: https://github.com/llvm/llvm-project/pull/134654.diff


3 Files Affected:

- (added) clang/test/KeyInstructions/cast.c (+19) 
- (added) clang/test/KeyInstructions/multi-func.c (+18) 
- (added) clang/test/KeyInstructions/new.cpp (+37) 


``diff
diff --git a/clang/test/KeyInstructions/cast.c 
b/clang/test/KeyInstructions/cast.c
new file mode 100644
index 0..b89edcc3089fb
--- /dev/null
+++ b/clang/test/KeyInstructions/cast.c
@@ -0,0 +1,19 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+float g;
+void a() {
+// CHECK: %0 = load float, ptr @g{{.*}}, !dbg [[G1R3:!.*]]
+// CHECK: %conv = fptosi float %0 to i32{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: store i32 %conv, ptr %a{{.*}}, !dbg [[G1R1:!.*]]
+int a = g;
+// CHECK: ret{{.*}}, !dbg [[G2R1:!.*]]
+}
+
+// CHECK: [[G1R3]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 3)
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
diff --git a/clang/test/KeyInstructions/multi-func.c 
b/clang/test/KeyInstructions/multi-func.c
new file mode 100644
index 0..7d441e43444b2
--- /dev/null
+++ b/clang/test/KeyInstructions/multi-func.c
@@ -0,0 +1,18 @@
+// RUN: %clang -gkey-instructions -gno-column-info -x c++ %s -gmlt -S 
-emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -gno-column-info -x c %s -gmlt -S -emit-llvm 
-o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Check atomGroup is reset to start at 1 in each function.
+
+// CHECK: ret{{.*}}, !dbg [[AG:!.*]]
+void a() {}
+
+// CHECK: ret{{.*}}, !dbg [[BG:!.*]]
+void b() {}
+
+// CHECK: [[A:!.*]] = distinct !DISubprogram(name: "a",
+// CHECK: [[AG]] = !DILocation({{.*}}, scope: [[A]], atomGroup: 1, atomRank: 1)
+// CHECK: [[B:!.*]] = distinct !DISubprogram(name: "b",
+// CHECK: [[BG]] = !DILocation({{.*}}, scope: [[B]], atomGroup: 1, atomRank: 1)
diff --git a/clang/test/KeyInstructions/new.cpp 
b/clang/test/KeyInstructions/new.cpp
new file mode 100644
index 0..9476e311e746f
--- /dev/null
+++ b/clang/test/KeyInstructions/new.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang -gkey-instructions %s -gmlt -gcolumn-info -S -emit-llvm -o - 
-Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// Check both the addr-store and value-store are part of the same atom.
+
+void f(int x) {
+// CHECK: %call = call noalias noundef nonnull ptr @_Znwm{{.*}}, !dbg 
[[G1R2_C12:!.*]]
+// CHECK: %0 = load i32, ptr %x.addr{{.*}}, !dbg [[G1R2_C20:!.*]]
+// CHECK: store i32 %0, ptr %call{{.*}}, !dbg [[G1R1_C12:!.*]]
+// CHECK: store ptr %call, ptr %{{.*}}, !dbg [[G1R1_C8:!.*]]
+  int *n = new int(x);
+// CHECK: %call1 = call noalias noundef nonnull ptr @_Znwm{{.*}}, !dbg 
[[G2R2_C7:!.*]]
+// CHECK: %1 = load i32, ptr %x.addr{{.*}}, !dbg [[G2R2_C15:!.*]]
+// CHECK: store i32 %1, ptr %call{{.*}}, !dbg [[G2R1_C7:!.*]]
+// CHECK: store ptr %call1, ptr %{{.*}}, !dbg [[G2R1_C5:!.*]]
+  n = new int(x);
+// CHECK: %2 = load i32, ptr %x.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: %3 = load ptr, ptr %n
+// CHECK: store i32 %2, ptr %3{{.*}}, !dbg [[G3R1:!.*]]
+  *n = x;
+// CHECK: ret void, !dbg [[G4R1:!.*]]
+}
+
+// CHECK: [[G1R2_C12]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R2_C20]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1_C12]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G1R1_C8]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+
+// CHECK: [[G2R2_C7]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G2R2_C15]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// 

[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-07 Thread Anatoly Trosinenko via llvm-branch-commits


@@ -191,16 +201,27 @@ define void @test_tailcall_omit_mov_x16_x16(ptr %objptr) 
#0 {
 define i32 @test_call_omit_extra_moves(ptr %objptr) #0 {
 ; CHECK-LABEL: test_call_omit_extra_moves:
 ; DARWIN-NEXT:   stp x29, x30, [sp, #-16]!
-; ELF-NEXT:  str x30, [sp, #-16]!
-; CHECK-NEXT:ldr x16, [x0]
-; CHECK-NEXT:mov x17, x0
-; CHECK-NEXT:movkx17, #6503, lsl #48
-; CHECK-NEXT:autda   x16, x17
-; CHECK-NEXT:ldr x8, [x16]
-; CHECK-NEXT:movkx16, #34646, lsl #48
-; CHECK-NEXT:blraa   x8, x16
-; CHECK-NEXT:mov w0, #42
+; DARWIN-NEXT:   ldr x16, [x0]
+; DARWIN-NEXT:   mov x17, x0
+; DARWIN-NEXT:   movkx17, #6503, lsl #48
+; DARWIN-NEXT:   autda   x16, x17
+; DARWIN-NEXT:   ldr x8, [x16]
+; DARWIN-NEXT:   movkx16, #34646, lsl #48
+; DARWIN-NEXT:   blraa   x8, x16
+; DARWIN-NEXT:   mov w0, #42
 ; DARWIN-NEXT:   ldp x29, x30, [sp], #16
+; ELF-NEXT:  str x30, [sp, #-16]!
+; ELF-NEXT:  ldr x8, [x0]
+; ELF-NEXT:  mov x9, x0
+; ELF-NEXT:  movkx9, #6503, lsl #48
+; ELF-NEXT:  autda   x8, x9
+; ELF-NEXT:  ldr x9, [x8]
+; FIXME: Get rid of the x16/x17 constraint on non-Darwin so we can eliminate
+; this mov.
+; ELF-NEXT:  mov x17, x8
+; ELF-NEXT:  movkx17, #34646, lsl #48
+; ELF-NEXT:  blraa   x9, x17
+; ELF-NEXT:  mov w0, #42
 ; ELF-NEXT:  ldr x30, [sp], #16
 ; CHECK-NEXT:ret

atrosinenko wrote:

Looks like `x0` could be updated in-place, as its value doesn't seem to be used 
after the blend operation.

https://github.com/llvm/llvm-project/pull/132857
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Assignment atom group (PR #134637)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

[KeyInstr][Clang] Assignment atom group

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

[KeyInstr][Clang] Multiple assignment  (x = y = z)

Compound assign

Pre/Post Inc/Dec

Rename test & run C & C++

---
Full diff: https://github.com/llvm/llvm-project/pull/134637.diff


4 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+9) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+4) 
- (added) clang/test/KeyInstructions/assign-scalar.c (+48) 
- (renamed) clang/test/KeyInstructions/init-agg.c (+4-2) 


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index a00a8ba2cd5cb..7408c498b3a1a 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -5814,6 +5814,15 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const 
BinaryOperator *E) {
 
   assert(E->getOpcode() == BO_Assign && "unexpected binary l-value");
 
+  // This covers both LHS and RHS expressions, though nested RHS
+  // expressions may get subsequently separately grouped.
+  // FIXME(OCH): Not clear yet if we've got fine enough control
+  // to pick and choose when we need to. Currently looks ok:
+  // a = b = c  -> Two atoms.
+  // x = new(1) -> One atom (for both addr store and value store).
+  // Complex and agg assignment -> One atom.
+  ApplyAtomGroup Grp(getDebugInfo());
+
   // Note that in all of these cases, __block variables need the RHS
   // evaluated first just in case the variable gets moved by the RHS.
 
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 140a12d384502..a4afafd3f536b 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -897,6 +897,7 @@ class ScalarExprEmitter
 return result; 
\
   }
\
   Value *VisitBin##OP##Assign(const CompoundAssignOperator *E) {   
\
+ApplyAtomGroup Grp(CGF.getDebugInfo());
\
 return EmitCompoundAssign(E, &ScalarExprEmitter::Emit##OP);
\
   }
   HANDLEBINOP(Mul)
@@ -2940,6 +2941,7 @@ class OMPLastprivateConditionalUpdateRAII {
 llvm::Value *
 ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV,
bool isInc, bool isPre) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   OMPLastprivateConditionalUpdateRAII OMPRegion(CGF, E);
   QualType type = E->getSubExpr()->getType();
   llvm::PHINode *atomicPHI = nullptr;
@@ -4973,6 +4975,7 @@ llvm::Value 
*CodeGenFunction::EmitWithOriginalRHSBitfieldAssignment(
 }
 
 Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) {
+  ApplyAtomGroup Grp(CGF.getDebugInfo());
   bool Ignore = TestAndClearIgnoreResultAssign();
 
   Value *RHS;
@@ -5740,6 +5743,7 @@ LValue CodeGenFunction::EmitObjCIsaExpr(const ObjCIsaExpr 
*E) {
 
 LValue CodeGenFunction::EmitCompoundAssignmentLValue(
 const CompoundAssignOperator *E) {
+  ApplyAtomGroup Grp(getDebugInfo());
   ScalarExprEmitter Scalar(*this);
   Value *Result = nullptr;
   switch (E->getOpcode()) {
diff --git a/clang/test/KeyInstructions/assign-scalar.c 
b/clang/test/KeyInstructions/assign-scalar.c
new file mode 100644
index 0..1f1fe8fda39e6
--- /dev/null
+++ b/clang/test/KeyInstructions/assign-scalar.c
@@ -0,0 +1,48 @@
+// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gcolumn-info -S -emit-llvm 
-o - -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -gcolumn-info -S -emit-llvm -o 
- -Wno-unused-variable \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+unsigned long long g;
+void fun() {
+// CHECK: store i64 0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+g = 0;
+
+// Treat the two assignments as two atoms.
+//
+// FIXME: Because of the atomGroup implementation the load can only be
+// associated with one of the two stores, despite being a good backup
+// loction for both.
+// CHECK-NEXT: %0 = load i64, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G3R1:!.*]]
+// CHECK-NEXT: store i64 %0, ptr @g{{.*}}, !dbg [[G2R1:!.*]]
+g = g = g;
+
+// Compound a

[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-07 Thread Anatoly Trosinenko via llvm-branch-commits


@@ -146,10 +152,10 @@ define i64 @test_resign_blend_and_const(i64 %arg, i64 
%arg1) {
 ; CHECKED-NEXT:mov x17, x16
 ; CHECKED-NEXT:xpacd x17
 ; CHECKED-NEXT:cmp x16, x17
-; CHECKED-NEXT:b.eq [[L]]auth_success_1
+; CHECKED-NEXT:b.eq [[L]]auth_success_[[N2:[0-9]]]

atrosinenko wrote:

[nit]
```suggestion
; CHECKED-NEXT:b.eq [[L]]auth_success_[[N2:[0-9]+]]
```

https://github.com/llvm/llvm-project/pull/132857
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] If stmt atom (PR #134642)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134642.diff


3 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+2) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+10) 
- (added) clang/test/KeyInstructions/if.c (+46) 


``diff
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index dcf523f56bf1e..b176227657f24 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2099,6 +2099,8 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
 
   llvm::Instruction *BrInst = Builder.CreateCondBr(CondV, TrueBlock, 
FalseBlock,
Weights, Unpredictable);
+  addInstToNewSourceAtom(BrInst, CondV);
+
   switch (HLSLControlFlowAttr) {
   case HLSLControlFlowHintAttr::Microsoft_branch:
   case HLSLControlFlowHintAttr::Microsoft_flatten: {
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 0a72784f311e5..3c3984c57d540 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -1768,6 +1768,16 @@ class CodeGenFunction : public CodeGenTypeCache {
   DI->addInstToCurrentSourceAtom(KeyInstruction, Backup);
   }
 
+  /// Add \p KeyInstruction and an optional \p Backup instruction to a new atom
+  /// group (See ApplyAtomGroup for more info).
+  void addInstToNewSourceAtom(llvm::Instruction *KeyInstruction,
+  llvm::Value *Backup) {
+if (CGDebugInfo *DI = getDebugInfo()) {
+  ApplyAtomGroup Grp(getDebugInfo());
+  DI->addInstToCurrentSourceAtom(KeyInstruction, Backup);
+}
+  }
+
   /// See CGDebugInfo::addRetToOverrideOrNewSourceAtom.
   void addRetToOverrideOrNewSourceAtom(llvm::ReturnInst *Ret,
llvm::Value *Backup) {
diff --git a/clang/test/KeyInstructions/if.c b/clang/test/KeyInstructions/if.c
new file mode 100644
index 0..ccc7eb9253198
--- /dev/null
+++ b/clang/test/KeyInstructions/if.c
@@ -0,0 +1,46 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A) {
+// The branch is a key instruction, with the condition being its backup.
+// CHECK: entry:
+// CHECK: %tobool = icmp ne i32 %0, 0{{.*}}, !dbg [[G1R2:!.*]]
+// CHECK: br i1 %tobool, label %if.then, label %if.end{{.*}}, !dbg [[G1R1:!.*]]
+if (A)
+;
+
+// The assignment in the if gets a distinct source atom group.
+// CHECK: if.end:
+// CHECK: %1 = load i32, ptr %A.addr{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %1, ptr @g{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: %tobool1 = icmp ne i32 %1, 0{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: br i1 %tobool1, label %if.then2, label %if.end3{{.*}}, !dbg 
[[G3R1:!.*]]
+if ((g = A))
+;
+
+#ifdef __cplusplus
+// The assignment in the if gets a distinct source atom group.
+// CHECK-CXX: if.end3:
+// CHECK-CXX: %2 = load i32, ptr %A.addr{{.*}}, !dbg [[G4R2:!.*]]
+// CHECK-CXX: store i32 %2, ptr %B{{.*}}, !dbg [[G4R1:!.*]]
+// CHECK-CXX: %tobool4 = icmp ne i32 %3, 0{{.*}}, !dbg [[G5R2:!.*]]
+// CHECK-CXX: br i1 %tobool4, label %if.then5, label %if.end6{{.*}}, !dbg 
[[G5R1:!.*]]
+if (int B = A; B)
+;
+#endif 
+}
+
+// CHECK: [[G1R2]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK-CXX: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
+// CHECK-CXX: [[G5R2]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 2)
+// CHECK-CXX: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134642
_

[llvm-branch-commits] [clang] [KeyInstr] Complex assignment atoms (PR #134638)

2025-04-07 Thread Orlando Cazalet-Hyams via llvm-branch-commits

OCHyams wrote:

> [!WARNING]
> This pull request is not mergeable via GitHub because a downstack PR is 
> open. Once all requirements are satisfied, merge this PR as a stack  href="https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-downstack-mergeability-warning";
>  >on Graphite.
> https://graphite.dev/docs/merge-pull-requests";>Learn more

* **#134640** https://app.graphite.dev/github/pr/llvm/llvm-project/134640?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134639** https://app.graphite.dev/github/pr/llvm/llvm-project/134639?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134638** https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/134638?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* **#134637** https://app.graphite.dev/github/pr/llvm/llvm-project/134637?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134636** https://app.graphite.dev/github/pr/llvm/llvm-project/134636?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134635** https://app.graphite.dev/github/pr/llvm/llvm-project/134635?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134634** https://app.graphite.dev/github/pr/llvm/llvm-project/134634?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134633** https://app.graphite.dev/github/pr/llvm/llvm-project/134633?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134632** https://app.graphite.dev/github/pr/llvm/llvm-project/134632?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#134627** https://app.graphite.dev/github/pr/llvm/llvm-project/134627?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133495** https://app.graphite.dev/github/pr/llvm/llvm-project/133495?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133494** https://app.graphite.dev/github/pr/llvm/llvm-project/133494?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133493** https://app.graphite.dev/github/pr/llvm/llvm-project/133493?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133492** https://app.graphite.dev/github/pr/llvm/llvm-project/133492?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133491** https://app.graphite.dev/github/pr/llvm/llvm-project/133491?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133490** https://app.graphite.dev/github/pr/llvm/llvm-project/133490?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133489** https://app.graphite.dev/github/pr/llvm/llvm-project/133489?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133488** https://app.graphite.dev/github/pr/llvm/llvm-project/133488?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133487** https://app.graphite.dev/github/pr/llvm/llvm-project/133487?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133486** https://app.graphite.dev/github/pr/llvm/llvm-project/133486?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/>
* **#133485** http

[llvm-branch-commits] AArch64: Relax x16/x17 constraint on AUT in certain cases. (PR #132857)

2025-04-07 Thread Anatoly Trosinenko via llvm-branch-commits


@@ -621,10 +641,10 @@ define i64 @test_resign_da_constdisc(i64 %arg, i64 %arg1) 
{
 ; CHECKED-NEXT:mov x17, x16
 ; CHECKED-NEXT:xpacd x17
 ; CHECKED-NEXT:cmp x16, x17
-; CHECKED-NEXT:b.eq [[L]]auth_success_7
+; CHECKED-NEXT:b.eq [[L]]auth_success_[[N1:[0-9]]]

atrosinenko wrote:

[nit]
```suggestion
; CHECKED-NEXT:b.eq [[L]]auth_success_[[N1:[0-9]+]]
```

https://github.com/llvm/llvm-project/pull/132857
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134643.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGStmt.cpp (+2) 
- (added) clang/test/KeyInstructions/switch.c (+51) 


``diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 3562b4ea22a24..7dd82d73d6b6a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2276,6 +2276,8 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) 
{
   // failure.
   llvm::BasicBlock *DefaultBlock = createBasicBlock("sw.default");
   SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock);
+  addInstToNewSourceAtom(SwitchInsn, CondV);
+
   if (HLSLControlFlowAttr != HLSLControlFlowHintAttr::SpellingNotCalculated) {
 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
 llvm::ConstantInt *BranchHintConstant =
diff --git a/clang/test/KeyInstructions/switch.c 
b/clang/test/KeyInstructions/switch.c
new file mode 100644
index 0..cff6b834106e9
--- /dev/null
+++ b/clang/test/KeyInstructions/switch.c
@@ -0,0 +1,51 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A, int B) {
+// CHECK: entry:
+// The load gets associated with the branch rather than the store.
+// FIXME: Is that the best thing to do?
+// CHECK: %0 = load i32, ptr %A.addr{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: switch i32 %0, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb
+// CHECK:   i32 1, label %sw.bb1
+// CHECK: ], !dbg [[G2R1:!.*]]
+switch ((g = A)) {
+case 0: break;
+case 1: {
+// CHECK: sw.bb1:
+// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: switch i32 %1, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb2
+// CHECK: ], !dbg [[G3R1:!.*]]
+switch ((B)) {
+case 0: {
+// Test that assignments in constant-folded switches don't go missing.
+// CHECK-CXX: sw.bb2:
+// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G4R1:!.*]]
+#ifdef __cplusplus
+switch (const int C = 1; C) {
+case 0: break;
+case 1: break;
+default: break;
+}
+#endif
+} break;
+default: break;
+}
+} break;
+default: break;
+}
+}
+
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134643
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Switch stmt atom (PR #134643)

2025-04-07 Thread via llvm-branch-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Orlando Cazalet-Hyams (OCHyams)


Changes

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

---
Full diff: https://github.com/llvm/llvm-project/pull/134643.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGStmt.cpp (+2) 
- (added) clang/test/KeyInstructions/switch.c (+51) 


``diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 3562b4ea22a24..7dd82d73d6b6a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -2276,6 +2276,8 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) 
{
   // failure.
   llvm::BasicBlock *DefaultBlock = createBasicBlock("sw.default");
   SwitchInsn = Builder.CreateSwitch(CondV, DefaultBlock);
+  addInstToNewSourceAtom(SwitchInsn, CondV);
+
   if (HLSLControlFlowAttr != HLSLControlFlowHintAttr::SpellingNotCalculated) {
 llvm::MDBuilder MDHelper(CGM.getLLVMContext());
 llvm::ConstantInt *BranchHintConstant =
diff --git a/clang/test/KeyInstructions/switch.c 
b/clang/test/KeyInstructions/switch.c
new file mode 100644
index 0..cff6b834106e9
--- /dev/null
+++ b/clang/test/KeyInstructions/switch.c
@@ -0,0 +1,51 @@
+// RUN: %clang -gkey-instructions -x c++ -std=c++17 %s -gmlt -S -emit-llvm -o 
- \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank --check-prefixes=CHECK,CHECK-CXX
+
+// RUN: %clang -gkey-instructions -x c %s -gmlt -S -emit-llvm -o -  \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+int g;
+void a(int A, int B) {
+// CHECK: entry:
+// The load gets associated with the branch rather than the store.
+// FIXME: Is that the best thing to do?
+// CHECK: %0 = load i32, ptr %A.addr{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr @g{{.*}}, !dbg [[G1R1:!.*]]
+// CHECK: switch i32 %0, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb
+// CHECK:   i32 1, label %sw.bb1
+// CHECK: ], !dbg [[G2R1:!.*]]
+switch ((g = A)) {
+case 0: break;
+case 1: {
+// CHECK: sw.bb1:
+// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: switch i32 %1, label %{{.*}} [
+// CHECK:   i32 0, label %sw.bb2
+// CHECK: ], !dbg [[G3R1:!.*]]
+switch ((B)) {
+case 0: {
+// Test that assignments in constant-folded switches don't go missing.
+// CHECK-CXX: sw.bb2:
+// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G4R1:!.*]]
+#ifdef __cplusplus
+switch (const int C = 1; C) {
+case 0: break;
+case 1: break;
+default: break;
+}
+#endif
+} break;
+default: break;
+}
+} break;
+default: break;
+}
+}
+
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G3R2]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 2)
+// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
+// CHECK-CXX: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)

``




https://github.com/llvm/llvm-project/pull/134643
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [KeyInstr][Clang] Coerced store atoms (PR #134653)

2025-04-07 Thread via llvm-branch-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff e5b6141602a80a402afca6c88c275ea71edff6f5 
e5779b993f4f2d5e2c1b84562f5f80adfa73f4df --extensions cpp,c -- 
clang/test/KeyInstructions/coerced-packed.c 
clang/test/KeyInstructions/coerced-ptr.c 
clang/test/KeyInstructions/coerced-through-memory.c 
clang/test/KeyInstructions/coerced.c clang/lib/CodeGen/CGCall.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a794b884a6..2263ef7a0e 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1413,14 +1413,16 @@ void CodeGenFunction::CreateCoercedStore(llvm::Value 
*Src, Address Dst,
 addInstToCurrentSourceAtom(I, Elt);
   }
 } else {
-  auto * I = Builder.CreateStore(Src, Dst.withElementType(SrcTy), 
DstIsVolatile);
+  auto *I =
+  Builder.CreateStore(Src, Dst.withElementType(SrcTy), DstIsVolatile);
   addInstToCurrentSourceAtom(I, Src);
 }
   } else if (SrcTy->isIntegerTy()) {
 // If the source is a simple integer, coerce it directly.
 llvm::Type *DstIntTy = Builder.getIntNTy(DstSize.getFixedValue() * 8);
 Src = CoerceIntOrPtrToIntOrPtr(Src, DstIntTy, *this);
-auto *I = Builder.CreateStore(Src, Dst.withElementType(DstIntTy), 
DstIsVolatile);
+auto *I =
+Builder.CreateStore(Src, Dst.withElementType(DstIntTy), DstIsVolatile);
 addInstToCurrentSourceAtom(I, Src);
   } else {
 // Otherwise do coercion through memory. This is stupid, but

``




https://github.com/llvm/llvm-project/pull/134653
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


  1   2   >