-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[KeyInstr][Clang] Break and Continue stmt atoms #141618
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
[KeyInstr][Clang] Break and Continue stmt atoms #141618
Conversation
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Orlando Cazalet-Hyams (OCHyams) ChangesBased on top of #134646 This patch is part of a stack that teaches Clang to generate Key Instructions RFC: The feature is only functional in LLVM if LLVM is built with CMake flag Full diff: https://github.com/llvm/llvm-project/pull/141618.diff 4 Files Affected:
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 7e1c5b7da9552..4ed2c5183c47e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -1118,6 +1118,7 @@ void CodeGenFunction::EmitBranchThroughCleanup(JumpDest Dest) {
// Create the branch.
llvm::BranchInst *BI = Builder.CreateBr(Dest.getBlock());
+ 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 cd2f05d419216..fe7b97d226a55 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1715,6 +1715,7 @@ void CodeGenFunction::EmitBreakStmt(const BreakStmt &S) {
if (HaveInsertPoint())
EmitStopPoint(&S);
+ ApplyAtomGroup Grp(getDebugInfo());
EmitBranchThroughCleanup(BreakContinueStack.back().BreakBlock);
}
@@ -1727,6 +1728,7 @@ void CodeGenFunction::EmitContinueStmt(const ContinueStmt &S) {
if (HaveInsertPoint())
EmitStopPoint(&S);
+ ApplyAtomGroup Grp(getDebugInfo());
EmitBranchThroughCleanup(BreakContinueStack.back().ContinueBlock);
}
diff --git a/clang/test/DebugInfo/KeyInstructions/for.c b/clang/test/DebugInfo/KeyInstructions/for.c
index d1fc79292266b..876079924de26 100644
--- a/clang/test/DebugInfo/KeyInstructions/for.c
+++ b/clang/test/DebugInfo/KeyInstructions/for.c
@@ -93,6 +93,32 @@ void d() {
}
}
+void e() {
+// - Check the `continue` keyword gets an atom group.
+// CHECK: entry:
+// CHECK-NEXT: br label %for.cond
+
+// CHECK: for.cond:
+// CHECK: br label %for.cond, !dbg [[eG1R1:!.*]], !llvm.loop
+ for ( ; ; )
+ {
+ continue;
+ }
+}
+
+void f() {
+// - Check the `break` keyword gets an atom group.
+// CHECK: entry:
+// CHECK-NEXT: br label %for.cond
+
+// CHECK: for.cond:
+// CHECK: br label %for.end, !dbg [[fG1R1:!.*]]
+ for ( ; ; )
+ {
+ break;
+ }
+}
+
// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
// CHECK: [[G3R1]] = !DILocation({{.*}}, atomGroup: 3, atomRank: 1)
@@ -116,3 +142,7 @@ void d() {
// CHECK: [[cG2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
// CHECK: [[dG1R1]] = !DILocation(line: 91, column: 3, scope: ![[#]], atomGroup: 1, atomRank: 1)
+
+// CHECK: [[eG1R1]] = !DILocation(line: 105, column: 5, scope: ![[#]], atomGroup: 1, atomRank: 1)
+
+// CHECK: [[fG1R1]] = !DILocation(line: 118, column: 5, scope: ![[#]], atomGroup: 1, atomRank: 1)
diff --git a/clang/test/DebugInfo/KeyInstructions/switch.c b/clang/test/DebugInfo/KeyInstructions/switch.c
index 5142f204ff587..96b18592621d5 100644
--- a/clang/test/DebugInfo/KeyInstructions/switch.c
+++ b/clang/test/DebugInfo/KeyInstructions/switch.c
@@ -16,18 +16,19 @@ void a(int A, int B) {
// CHECK: i32 1, label %sw.bb1
// CHECK: ], !dbg [[G2R1:!.*]]
switch ((g = A)) {
+// CHECK: br label %sw.epilog[[#]], !dbg [[G3R1:!.*]]
case 0: break;
case 1: {
// CHECK: sw.bb1:
-// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G3R2:!.*]]
+// CHECK: %1 = load i32, ptr %B.addr{{.*}}, !dbg [[G4R2:!.*]]
// CHECK: switch i32 %1, label %{{.*}} [
// CHECK: i32 0, label %sw.bb2
-// CHECK: ], !dbg [[G3R1:!.*]]
+// CHECK: ], !dbg [[G4R1:!.*]]
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:!.*]]
+// CHECK-CXX: store i32 1, ptr %C{{.*}}, !dbg [[G5R1:!.*]]
#ifdef __cplusplus
switch (const int C = 1; C) {
case 0: break;
@@ -35,17 +36,16 @@ void a(int A, int B) {
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)
+// CHECK: [[G4R2]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 2)
+// CHECK: [[G4R1]] = !DILocation({{.*}}, atomGroup: 4, atomRank: 1)
+// CHECK-CXX: [[G5R1]] = !DILocation({{.*}}, atomGroup: 5, atomRank: 1)
|
784005e
to
0af9ceb
Compare
9f9c3e1
to
9ae3232
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this all makes sense (to make break/continue their own key instructions). This involves cleanup scopes getting their own group: will destructors that run when "break"ing out of a loop get the key-ness of the "break" statement? (This might not be a bad thing at all).
I didn't close this, GitHub did (because I merged the base branch? for others that resulted in rebasing dependant branches on main... I don't understand why this one was different). I don't seem to be able to reopen it or convert it to a draft since the base branch no longer exists. I'll try rebasing... |
Nope that didn't seem to work. I'll land it manually...
Similar answer to elsewhere - calls aren't annotated by the front end, instead picked up in DWARF emission. If that changes, yes there's a risk, but imo it's a low risk. |
Landed in 8e50e88 |
Based on top of #134646
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.
RFC:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668
The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.