Skip to content

[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
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

namespace llvm {

class ModuleSlotTracker;

// Provides two way mapping between the blocks and numbers.
class BlockToIndexMapping {
SmallVector<BasicBlock *, 32> V;
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 16 additions & 9 deletions llvm/lib/Transforms/Coroutines/MaterializationUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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";
Expand Down
39 changes: 23 additions & 16 deletions llvm/lib/Transforms/Coroutines/SuspendCrossingInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,34 @@
//===----------------------------------------------------------------------===//

#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.
#define DEBUG_TYPE "coro-suspend-crossing"

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";
}
Expand All @@ -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";
}
Expand Down
Loading