-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Coroutines] Improve dump of BB label to avoid str copies #112374
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
Merged
TylerNowicki
merged 1 commit into
llvm:main
from
TylerNowicki:users/tylernowicki/coro-improve-dump
Oct 16, 2024
Merged
[Coroutines] Improve dump of BB label to avoid str copies #112374
TylerNowicki
merged 1 commit into
llvm:main
from
TylerNowicki:users/tylernowicki/coro-improve-dump
Oct 16, 2024
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
TylerNowicki
commented
Oct 15, 2024
- This avoids the need to call printAsOperand that requires use of an ostream and thus avoids a str copy.
- ModuleSlotTracker is used to get a BB # for BB's without names when dumping SuspendCrossingInfo and materialization info.
- getBasicBlockLabel() is changed to dumpBasicBlockLabel() that directly prints the label to dbgs()
- The label corresponds with the print-before BB #s.
- This change does not require any additional arguments to be added to dump() methods, at least those that currently do not require any args.
* This avoids the need to call printAsOperand that requires use of an ostream and thus avoids a str copy. * ModuleSlotTracker is used to get a BB # for BB's without names when dumping SuspendCrossingInfo and materialization info. * getBasicBlockLabel() is changed to dumpBasicBlockLabel() that directly prints the label to dbgs() * The label corresponds with the print-before BB #s. * This change does not require any additional arguments to be added to dump() methods, at least those that currently do not require any args.
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-coroutines Author: Tyler Nowicki (TylerNowicki) Changes
Full diff: https://github.com/llvm/llvm-project/pull/112374.diff 3 Files Affected:
diff --git a/llvm/include/llvm/Transforms/Coroutines/SuspendCrossingInfo.h b/llvm/include/llvm/Transforms/Coroutines/SuspendCrossingInfo.h
index 49cae6dde47e54..88cbf88acc4cd0 100644
--- a/llvm/include/llvm/Transforms/Coroutines/SuspendCrossingInfo.h
+++ b/llvm/include/llvm/Transforms/Coroutines/SuspendCrossingInfo.h
@@ -25,6 +25,8 @@
namespace llvm {
+class ModuleSlotTracker;
+
// Provides two way mapping between the blocks and numbers.
class BlockToIndexMapping {
SmallVector<BasicBlock *, 32> V;
@@ -96,7 +98,8 @@ class SuspendCrossingInfo {
// Print order is in RPO
void dump() const;
void dump(StringRef Label, BitVector const &BV,
- const ReversePostOrderTraversal<Function *> &RPOT) const;
+ const ReversePostOrderTraversal<Function *> &RPOT,
+ ModuleSlotTracker &MST) const;
#endif
SuspendCrossingInfo(Function &F,
diff --git a/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp b/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp
index c3ea0977d42117..6327cea64c0de6 100644
--- a/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp
+++ b/llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp
@@ -15,6 +15,7 @@
#include "llvm/IR/Dominators.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instruction.h"
+#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/Transforms/Coroutines/SpillUtils.h"
#include <deque>
@@ -104,19 +105,25 @@ struct RematGraph {
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
- static std::string getBasicBlockLabel(const BasicBlock *BB) {
- if (BB->hasName())
- return BB->getName().str();
-
- std::string S;
- raw_string_ostream OS(S);
- BB->printAsOperand(OS, false);
- return OS.str().substr(1);
+ static void dumpBasicBlockLabel(const BasicBlock *BB,
+ ModuleSlotTracker &MST) {
+ if (BB->hasName()) {
+ dbgs() << BB->getName();
+ return;
+ }
+
+ dbgs() << MST.getLocalSlot(BB);
}
void dump() const {
+ BasicBlock *BB = EntryNode->Node->getParent();
+ Function *F = BB->getParent();
+
+ ModuleSlotTracker MST(F->getParent());
+ MST.incorporateFunction(*F);
+
dbgs() << "Entry (";
- dbgs() << getBasicBlockLabel(EntryNode->Node->getParent());
+ dumpBasicBlockLabel(BB, MST);
dbgs() << ") : " << *EntryNode->Node << "\n";
for (auto &E : Remats) {
dbgs() << *(E.first) << "\n";
diff --git a/llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp b/llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp
index f18f23306befb4..c9bb3395a99491 100644
--- a/llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp
+++ b/llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/Coroutines/SuspendCrossingInfo.h"
+#include "llvm/IR/ModuleSlotTracker.h"
// The "coro-suspend-crossing" flag is very noisy. There is another debug type,
// "coro-frame", which results in leaner debug spew.
@@ -20,24 +21,26 @@
namespace llvm {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
-static std::string getBasicBlockLabel(const BasicBlock *BB) {
- if (BB->hasName())
- return BB->getName().str();
-
- std::string S;
- raw_string_ostream OS(S);
- BB->printAsOperand(OS, false);
- return OS.str().substr(1);
+static void dumpBasicBlockLabel(const BasicBlock *BB, ModuleSlotTracker &MST) {
+ if (BB->hasName()) {
+ dbgs() << BB->getName();
+ return;
+ }
+
+ dbgs() << MST.getLocalSlot(BB);
}
-LLVM_DUMP_METHOD void SuspendCrossingInfo::dump(
- StringRef Label, BitVector const &BV,
- const ReversePostOrderTraversal<Function *> &RPOT) const {
+LLVM_DUMP_METHOD void
+SuspendCrossingInfo::dump(StringRef Label, BitVector const &BV,
+ const ReversePostOrderTraversal<Function *> &RPOT,
+ ModuleSlotTracker &MST) const {
dbgs() << Label << ":";
for (const BasicBlock *BB : RPOT) {
auto BBNo = Mapping.blockToIndex(BB);
- if (BV[BBNo])
- dbgs() << " " << getBasicBlockLabel(BB);
+ if (BV[BBNo]) {
+ dbgs() << " ";
+ dumpBasicBlockLabel(BB, MST);
+ }
}
dbgs() << "\n";
}
@@ -49,12 +52,16 @@ LLVM_DUMP_METHOD void SuspendCrossingInfo::dump() const {
BasicBlock *const B = Mapping.indexToBlock(0);
Function *F = B->getParent();
+ ModuleSlotTracker MST(F->getParent());
+ MST.incorporateFunction(*F);
+
ReversePostOrderTraversal<Function *> RPOT(F);
for (const BasicBlock *BB : RPOT) {
auto BBNo = Mapping.blockToIndex(BB);
- dbgs() << getBasicBlockLabel(BB) << ":\n";
- dump(" Consumes", Block[BBNo].Consumes, RPOT);
- dump(" Kills", Block[BBNo].Kills, RPOT);
+ dumpBasicBlockLabel(BB, MST);
+ dbgs() << ":\n";
+ dump(" Consumes", Block[BBNo].Consumes, RPOT, MST);
+ dump(" Kills", Block[BBNo].Kills, RPOT, MST);
}
dbgs() << "\n";
}
|
2b8f1d1
to
000b969
Compare
ChuanqiXu9
approved these changes
Oct 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.