Skip to content

Commit 4db57ab

Browse files
TylerNowickitnowicki
andauthored
[Coroutines] Improve dump of BB label to avoid str copies (llvm#112374)
* 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. Co-authored-by: tnowicki <[email protected]>
1 parent cfc10be commit 4db57ab

File tree

3 files changed

+43
-26
lines changed

3 files changed

+43
-26
lines changed

llvm/include/llvm/Transforms/Coroutines/SuspendCrossingInfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace llvm {
2727

28+
class ModuleSlotTracker;
29+
2830
// Provides two way mapping between the blocks and numbers.
2931
class BlockToIndexMapping {
3032
SmallVector<BasicBlock *, 32> V;
@@ -96,7 +98,8 @@ class SuspendCrossingInfo {
9698
// Print order is in RPO
9799
void dump() const;
98100
void dump(StringRef Label, BitVector const &BV,
99-
const ReversePostOrderTraversal<Function *> &RPOT) const;
101+
const ReversePostOrderTraversal<Function *> &RPOT,
102+
ModuleSlotTracker &MST) const;
100103
#endif
101104

102105
SuspendCrossingInfo(Function &F,

llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/IR/Dominators.h"
1616
#include "llvm/IR/InstIterator.h"
1717
#include "llvm/IR/Instruction.h"
18+
#include "llvm/IR/ModuleSlotTracker.h"
1819
#include "llvm/Transforms/Coroutines/SpillUtils.h"
1920
#include <deque>
2021

@@ -104,19 +105,25 @@ struct RematGraph {
104105
}
105106

106107
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
107-
static std::string getBasicBlockLabel(const BasicBlock *BB) {
108-
if (BB->hasName())
109-
return BB->getName().str();
110-
111-
std::string S;
112-
raw_string_ostream OS(S);
113-
BB->printAsOperand(OS, false);
114-
return OS.str().substr(1);
108+
static void dumpBasicBlockLabel(const BasicBlock *BB,
109+
ModuleSlotTracker &MST) {
110+
if (BB->hasName()) {
111+
dbgs() << BB->getName();
112+
return;
113+
}
114+
115+
dbgs() << MST.getLocalSlot(BB);
115116
}
116117

117118
void dump() const {
119+
BasicBlock *BB = EntryNode->Node->getParent();
120+
Function *F = BB->getParent();
121+
122+
ModuleSlotTracker MST(F->getParent());
123+
MST.incorporateFunction(*F);
124+
118125
dbgs() << "Entry (";
119-
dbgs() << getBasicBlockLabel(EntryNode->Node->getParent());
126+
dumpBasicBlockLabel(BB, MST);
120127
dbgs() << ") : " << *EntryNode->Node << "\n";
121128
for (auto &E : Remats) {
122129
dbgs() << *(E.first) << "\n";

llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,34 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "llvm/Transforms/Coroutines/SuspendCrossingInfo.h"
16+
#include "llvm/IR/ModuleSlotTracker.h"
1617

1718
// The "coro-suspend-crossing" flag is very noisy. There is another debug type,
1819
// "coro-frame", which results in leaner debug spew.
1920
#define DEBUG_TYPE "coro-suspend-crossing"
2021

2122
namespace llvm {
2223
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
23-
static std::string getBasicBlockLabel(const BasicBlock *BB) {
24-
if (BB->hasName())
25-
return BB->getName().str();
26-
27-
std::string S;
28-
raw_string_ostream OS(S);
29-
BB->printAsOperand(OS, false);
30-
return OS.str().substr(1);
24+
static void dumpBasicBlockLabel(const BasicBlock *BB, ModuleSlotTracker &MST) {
25+
if (BB->hasName()) {
26+
dbgs() << BB->getName();
27+
return;
28+
}
29+
30+
dbgs() << MST.getLocalSlot(BB);
3131
}
3232

33-
LLVM_DUMP_METHOD void SuspendCrossingInfo::dump(
34-
StringRef Label, BitVector const &BV,
35-
const ReversePostOrderTraversal<Function *> &RPOT) const {
33+
LLVM_DUMP_METHOD void
34+
SuspendCrossingInfo::dump(StringRef Label, BitVector const &BV,
35+
const ReversePostOrderTraversal<Function *> &RPOT,
36+
ModuleSlotTracker &MST) const {
3637
dbgs() << Label << ":";
3738
for (const BasicBlock *BB : RPOT) {
3839
auto BBNo = Mapping.blockToIndex(BB);
39-
if (BV[BBNo])
40-
dbgs() << " " << getBasicBlockLabel(BB);
40+
if (BV[BBNo]) {
41+
dbgs() << " ";
42+
dumpBasicBlockLabel(BB, MST);
43+
}
4144
}
4245
dbgs() << "\n";
4346
}
@@ -49,12 +52,16 @@ LLVM_DUMP_METHOD void SuspendCrossingInfo::dump() const {
4952
BasicBlock *const B = Mapping.indexToBlock(0);
5053
Function *F = B->getParent();
5154

55+
ModuleSlotTracker MST(F->getParent());
56+
MST.incorporateFunction(*F);
57+
5258
ReversePostOrderTraversal<Function *> RPOT(F);
5359
for (const BasicBlock *BB : RPOT) {
5460
auto BBNo = Mapping.blockToIndex(BB);
55-
dbgs() << getBasicBlockLabel(BB) << ":\n";
56-
dump(" Consumes", Block[BBNo].Consumes, RPOT);
57-
dump(" Kills", Block[BBNo].Kills, RPOT);
61+
dumpBasicBlockLabel(BB, MST);
62+
dbgs() << ":\n";
63+
dump(" Consumes", Block[BBNo].Consumes, RPOT, MST);
64+
dump(" Kills", Block[BBNo].Kills, RPOT, MST);
5865
}
5966
dbgs() << "\n";
6067
}

0 commit comments

Comments
 (0)