Skip to content

[KeyInstr][Clang] Assignment atom group #134637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: users/OCHyams/ki-clang-init-static
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[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:
#130943
  • Loading branch information
OCHyams committed Apr 7, 2025
commit cdf3eef4a2c3d46687b6b2e49d02b7e7152f2d5e
9 changes: 9 additions & 0 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 9 additions & 0 deletions clang/test/KeyInstructions/assign.cpp
Original file line number Diff line number Diff line change
@@ -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)