https://github.com/OCHyams updated https://github.com/llvm/llvm-project/pull/134639
>From 46ccd7a165bde6ad72f785551bf57cc7fb590378 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Thu, 3 Apr 2025 15:15:39 +0100 Subject: [PATCH 1/4] [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/DebugInfo/KeyInstructions/agg.c | 12 ++++++++++++ clang/test/DebugInfo/KeyInstructions/init-agg.c | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 clang/test/DebugInfo/KeyInstructions/agg.c diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index e6f18505a7d4d..c683b2a38225d 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -2393,7 +2393,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/DebugInfo/KeyInstructions/agg.c b/clang/test/DebugInfo/KeyInstructions/agg.c new file mode 100644 index 0000000000000..5990859a5b548 --- /dev/null +++ b/clang/test/DebugInfo/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/DebugInfo/KeyInstructions/init-agg.c b/clang/test/DebugInfo/KeyInstructions/init-agg.c index ad298715286cd..dc3ccaedc57b5 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-agg.c +++ b/clang/test/DebugInfo/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 738d294f757ffeeb4a2ec26cd1f1214b5669c656 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Thu, 3 Apr 2025 16:00:26 +0100 Subject: [PATCH 2/4] [KeyInstr][Clang] Agg copy atom --- clang/lib/CodeGen/CGExprAgg.cpp | 1 + clang/lib/CodeGen/CodeGenFunction.h | 1 + clang/test/DebugInfo/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 c683b2a38225d..cad6731173700 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 1743f558b37e9..47ed4e051ca47 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -3035,6 +3035,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/DebugInfo/KeyInstructions/agg.c b/clang/test/DebugInfo/KeyInstructions/agg.c index 5990859a5b548..177e1ea8b9fc1 100644 --- a/clang/test/DebugInfo/KeyInstructions/agg.c +++ b/clang/test/DebugInfo/KeyInstructions/agg.c @@ -1,12 +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 %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 typedef struct { int a, b, c; } Struct; void fun(Struct a) { -// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]] +// 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) >From 35092c0b650a6e782549d813483d738f5788283f Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 15:16:33 +0100 Subject: [PATCH 3/4] move ApplyAtomGroup into CodeGenFunction.h (CGDebugInfo.h no longer included) --- clang/lib/CodeGen/CGDebugInfo.h | 14 -------------- clang/lib/CodeGen/CodeGenFunction.h | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 10739194fd70f..79d031acbf19e 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -892,20 +892,6 @@ class CGDebugInfo { } }; -/// A scoped helper to set the current source atom group for -/// CGDebugInfo::addInstToCurrentSourceAtom. 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. -class ApplyAtomGroup { - uint64_t OriginalAtom = 0; - CGDebugInfo *DI = nullptr; - -public: - ApplyAtomGroup(CGDebugInfo *DI); - ~ApplyAtomGroup(); -}; - /// A scoped helper to set the current debug location to the specified /// location or preferred location of the specified Expr. class ApplyDebugLocation { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 47ed4e051ca47..78d71fc822bcb 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -258,6 +258,20 @@ template <> struct DominatingValue<RValue> { } }; +/// A scoped helper to set the current source atom group for +/// CGDebugInfo::addInstToCurrentSourceAtom. 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. +class ApplyAtomGroup { + uint64_t OriginalAtom = 0; + CGDebugInfo *DI = nullptr; + +public: + ApplyAtomGroup(CGDebugInfo *DI); + ~ApplyAtomGroup(); +}; + /// CodeGenFunction - This class organizes the per-function state that is used /// while generating LLVM code. class CodeGenFunction : public CodeGenTypeCache { >From a9c75894442b8a6c5ffe8d9330958153f33c2502 Mon Sep 17 00:00:00 2001 From: Orlando Cazalet-Hyams <orlando.hy...@sony.com> Date: Wed, 21 May 2025 15:19:13 +0100 Subject: [PATCH 4/4] cc1 --- clang/test/DebugInfo/KeyInstructions/agg.c | 4 ++-- clang/test/DebugInfo/KeyInstructions/init-agg.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/DebugInfo/KeyInstructions/agg.c b/clang/test/DebugInfo/KeyInstructions/agg.c index 177e1ea8b9fc1..06c9ebbb63369 100644 --- a/clang/test/DebugInfo/KeyInstructions/agg.c +++ b/clang/test/DebugInfo/KeyInstructions/agg.c @@ -1,7 +1,7 @@ -// RUN: %clang -gkey-instructions -x c++ %s -gmlt -S -emit-llvm -o - \ +// RUN: %clang_cc1 -gkey-instructions -x c++ %s -debug-info-kind=line-tables-only -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_cc1 -gkey-instructions -x c %s -debug-info-kind=line-tables-only -emit-llvm -o - \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank typedef struct { int a, b, c; } Struct; diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.c b/clang/test/DebugInfo/KeyInstructions/init-agg.c index dc3ccaedc57b5..de1f247bb2722 100644 --- a/clang/test/DebugInfo/KeyInstructions/init-agg.c +++ b/clang/test/DebugInfo/KeyInstructions/init-agg.c @@ -1,8 +1,8 @@ -// RUN: %clang -gkey-instructions -x c++ %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=pattern \ +// RUN: %clang_cc1 -gkey-instructions -x c++ %s -debug-info-kind=line-tables-only -gno-column-info -emit-llvm -o - -ftrivial-auto-var-init=pattern \ // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not atomRank -// RUN: %clang -gkey-instructions -x c %s -gmlt -gno-column-info -S -emit-llvm -o - -ftrivial-auto-var-init=pattern \ +// RUN: %clang_cc1 -gkey-instructions -x c %s -debug-info-kind=line-tables-only -gno-column-info -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 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits