Skip to content

Commit

Permalink
Cleanup dump() functions.
Browse files Browse the repository at this point in the history
We had various variants of defining dump() functions in LLVM. Normalize
them (this should just consistently implement the things discussed in
http://lists.llvm.org/pipermail/cfe-dev/2014-January/034323.html

For reference:
- Public headers should just declare the dump() method but not use
  LLVM_DUMP_METHOD or #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
- The definition of a dump method should look like this:
  #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  LLVM_DUMP_METHOD void MyClass::dump() {
    // print stuff to dbgs()...
  }
  #endif

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293359 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
MatzeB committed Jan 28, 2017
1 parent 92cf58e commit 88d2075
Show file tree
Hide file tree
Showing 94 changed files with 376 additions and 195 deletions.
2 changes: 1 addition & 1 deletion include/llvm/CodeGen/MachineOperand.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class MachineOperand {
void print(raw_ostream &os, ModuleSlotTracker &MST,
const TargetRegisterInfo *TRI = nullptr,
const TargetIntrinsicInfo *IntrinsicInfo = nullptr) const;
LLVM_DUMP_METHOD void dump() const;
void dump() const;

//===--------------------------------------------------------------------===//
// Accessors that tell you what kind of MachineOperand you're looking at.
Expand Down
2 changes: 1 addition & 1 deletion include/llvm/CodeGen/RegisterPressure.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class PressureDiff {
void addPressureChange(unsigned RegUnit, bool IsDec,
const MachineRegisterInfo *MRI);

LLVM_DUMP_METHOD void dump(const TargetRegisterInfo &TRI) const;
void dump(const TargetRegisterInfo &TRI) const;
};

/// List of registers defined and used by a machine instruction.
Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Support/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);

/// \brief Mark debug helper function definitions like dump() that should not be
/// stripped from debug builds.
/// Note that you should also surround dump() functions with
/// `#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)` so they do always
/// get stripped in release builds.
// FIXME: Move this to a private config.h as it's not usable in public headers.
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
Expand Down
3 changes: 3 additions & 0 deletions include/llvm/Support/GCOV.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class GCOVFile {
bool readGCNO(GCOVBuffer &Buffer);
bool readGCDA(GCOVBuffer &Buffer);
uint32_t getChecksum() const { return Checksum; }
void print(raw_ostream &OS) const;
void dump() const;
void collectLineCounts(FileInfo &FI);

Expand Down Expand Up @@ -290,6 +291,7 @@ class GCOVFunction {
return make_range(block_begin(), block_end());
}

void print(raw_ostream &OS) const;
void dump() const;
void collectLineCounts(FileInfo &FI);

Expand Down Expand Up @@ -361,6 +363,7 @@ class GCOVBlock {
return make_range(dst_begin(), dst_end());
}

void print(raw_ostream &OS) const;
void dump() const;
void collectLineCounts(FileInfo &FI);

Expand Down
1 change: 1 addition & 0 deletions include/llvm/TableGen/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,7 @@ class Record {
ResolveFirst = b;
}

void print(raw_ostream &OS) const;
void dump() const;

//===--------------------------------------------------------------------===//
Expand Down
2 changes: 2 additions & 0 deletions lib/Analysis/BlockFrequencyInfoImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ ScaledNumber<uint64_t> BlockMass::toScaled() const {
return ScaledNumber<uint64_t>(getMass() + 1, -64);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void BlockMass::dump() const { print(dbgs()); }
#endif

static char getHexDigit(int N) {
assert(N < 16);
Expand Down
12 changes: 8 additions & 4 deletions lib/Analysis/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ void CallGraph::print(raw_ostream &OS) const {
CN->print(OS);
}

LLVM_DUMP_METHOD
void CallGraph::dump() const { print(dbgs()); }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void CallGraph::dump() const { print(dbgs()); }
#endif

// removeFunctionFromModule - Unlink the function from this module, returning
// it. Because this removes the function from the module, the call graph node
Expand Down Expand Up @@ -194,8 +195,9 @@ void CallGraphNode::print(raw_ostream &OS) const {
OS << '\n';
}

LLVM_DUMP_METHOD
void CallGraphNode::dump() const { print(dbgs()); }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void CallGraphNode::dump() const { print(dbgs()); }
#endif

/// removeCallEdgeFor - This method removes the edge in the node for the
/// specified call site. Note that this method takes linear time, so it
Expand Down Expand Up @@ -307,8 +309,10 @@ void CallGraphWrapperPass::print(raw_ostream &OS, const Module *) const {
G->print(OS);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD
void CallGraphWrapperPass::dump() const { print(dbgs(), nullptr); }
#endif

namespace {
struct CallGraphPrinterLegacyPass : public ModulePass {
Expand Down
5 changes: 3 additions & 2 deletions lib/Analysis/DependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ void DependenceInfo::Constraint::setAny(ScalarEvolution *NewSE) {
Kind = Any;
}


#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
// For debugging purposes. Dumps the constraint out to OS.
void DependenceInfo::Constraint::dump(raw_ostream &OS) const {
LLVM_DUMP_METHOD void DependenceInfo::Constraint::dump(raw_ostream &OS) const {
if (isEmpty())
OS << " Empty\n";
else if (isAny())
Expand All @@ -403,6 +403,7 @@ void DependenceInfo::Constraint::dump(raw_ostream &OS) const {
else
llvm_unreachable("unknown constraint type in Constraint::dump");
}
#endif


// Updates X with the intersection
Expand Down
12 changes: 9 additions & 3 deletions lib/Analysis/LazyCallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ void LazyCallGraph::Node::removeEdgeInternal(Function &Target) {
EdgeIndexMap.erase(IndexMapI);
}

void LazyCallGraph::Node::dump() const {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void LazyCallGraph::Node::dump() const {
dbgs() << *this << '\n';
}
#endif

LazyCallGraph::LazyCallGraph(Module &M) : NextDFSNumber(0) {
DEBUG(dbgs() << "Building CG for module: " << M.getModuleIdentifier()
Expand Down Expand Up @@ -167,9 +169,11 @@ LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) {
return *this;
}

void LazyCallGraph::SCC::dump() const {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void LazyCallGraph::SCC::dump() const {
dbgs() << *this << '\n';
}
#endif

#ifndef NDEBUG
void LazyCallGraph::SCC::verify() {
Expand Down Expand Up @@ -243,9 +247,11 @@ bool LazyCallGraph::SCC::isAncestorOf(const SCC &TargetC) const {

LazyCallGraph::RefSCC::RefSCC(LazyCallGraph &G) : G(&G) {}

void LazyCallGraph::RefSCC::dump() const {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void LazyCallGraph::RefSCC::dump() const {
dbgs() << *this << '\n';
}
#endif

#ifndef NDEBUG
void LazyCallGraph::RefSCC::verify() {
Expand Down
5 changes: 3 additions & 2 deletions lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ static cl::opt<unsigned> MaxConstantEvolvingDepth(
// Implementation of the SCEV class.
//

LLVM_DUMP_METHOD
void SCEV::dump() const {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void SCEV::dump() const {
print(dbgs());
dbgs() << '\n';
}
#endif

void SCEV::print(raw_ostream &OS) const {
switch (static_cast<SCEVTypes>(getSCEVType())) {
Expand Down
5 changes: 4 additions & 1 deletion lib/Bitcode/Writer/ValueEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,14 @@ unsigned ValueEnumerator::getValueID(const Value *V) const {
return I->second-1;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void ValueEnumerator::dump() const {
print(dbgs(), ValueMap, "Default");
dbgs() << '\n';
print(dbgs(), MetadataMap, "MetaData");
dbgs() << '\n';
}
#endif

void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
const char *Name) const {
Expand All @@ -452,7 +454,8 @@ void ValueEnumerator::print(raw_ostream &OS, const ValueMapType &Map,
OS << "Value: " << V->getName();
else
OS << "Value: [null]\n";
V->dump();
V->print(errs());
errs() << '\n';

OS << " Uses(" << std::distance(V->use_begin(),V->use_end()) << "):";
for (const Use &U : V->uses()) {
Expand Down
17 changes: 11 additions & 6 deletions lib/CodeGen/AsmPrinter/DIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ void DIEAbbrev::print(raw_ostream &O) {
}
}

LLVM_DUMP_METHOD
void DIEAbbrev::dump() { print(dbgs()); }
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DIEAbbrev::dump() {
print(dbgs());
}
#endif

//===----------------------------------------------------------------------===//
// DIEAbbrevSet Implementation
Expand Down Expand Up @@ -249,10 +252,11 @@ void DIE::print(raw_ostream &O, unsigned IndentCount) const {
O << "\n";
}

LLVM_DUMP_METHOD
void DIE::dump() {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DIE::dump() {
print(dbgs());
}
#endif

unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
DIEAbbrevSet &AbbrevSet,
Expand Down Expand Up @@ -340,10 +344,11 @@ void DIEValue::print(raw_ostream &O) const {
}
}

LLVM_DUMP_METHOD
void DIEValue::dump() const {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void DIEValue::dump() const {
print(dbgs());
}
#endif

//===----------------------------------------------------------------------===//
// DIEInteger Implementation
Expand Down
4 changes: 3 additions & 1 deletion lib/CodeGen/BranchRelaxation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ void BranchRelaxation::verify() {
#endif
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
/// print block size and offset information - debugging
void BranchRelaxation::dumpBBs() {
LLVM_DUMP_METHOD void BranchRelaxation::dumpBBs() {
for (auto &MBB : *MF) {
const BasicBlockInfo &BBI = BlockInfo[MBB.getNumber()];
dbgs() << format("BB#%u\toffset=%08x\t", MBB.getNumber(), BBI.Offset)
<< format("size=%#x\n", BBI.Size);
}
}
#endif

/// scanFunction - Do the initial scan of the function, building up
/// information about each block.
Expand Down
4 changes: 3 additions & 1 deletion lib/CodeGen/GlobalISel/RegBankSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,12 @@ bool RegBankSelect::MappingCost::operator==(const MappingCost &Cost) const {
LocalFreq == Cost.LocalFreq;
}

void RegBankSelect::MappingCost::dump() const {
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void RegBankSelect::MappingCost::dump() const {
print(dbgs());
dbgs() << '\n';
}
#endif

void RegBankSelect::MappingCost::print(raw_ostream &OS) const {
if (*this == ImpossibleCost()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/CodeGen/GlobalISel/RegisterBank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ bool RegisterBank::operator==(const RegisterBank &OtherRB) const {
return &OtherRB == this;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void RegisterBank::dump(const TargetRegisterInfo *TRI) const {
print(dbgs(), /* IsForDebug */ true, TRI);
}
#endif

void RegisterBank::print(raw_ostream &OS, bool IsForDebug,
const TargetRegisterInfo *TRI) const {
Expand Down
8 changes: 8 additions & 0 deletions lib/CodeGen/GlobalISel/RegisterBankInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,12 @@ unsigned RegisterBankInfo::getSizeInBits(unsigned Reg,
//------------------------------------------------------------------------------
// Helper classes implementation.
//------------------------------------------------------------------------------
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void RegisterBankInfo::PartialMapping::dump() const {
print(dbgs());
dbgs() << '\n';
}
#endif

bool RegisterBankInfo::PartialMapping::verify() const {
assert(RegBank && "Register bank not set");
Expand Down Expand Up @@ -453,10 +455,12 @@ bool RegisterBankInfo::ValueMapping::verify(unsigned MeaningfulBitWidth) const {
return true;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void RegisterBankInfo::ValueMapping::dump() const {
print(dbgs());
dbgs() << '\n';
}
#endif

void RegisterBankInfo::ValueMapping::print(raw_ostream &OS) const {
OS << "#BreakDown: " << NumBreakDowns << " ";
Expand Down Expand Up @@ -505,10 +509,12 @@ bool RegisterBankInfo::InstructionMapping::verify(
return true;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void RegisterBankInfo::InstructionMapping::dump() const {
print(dbgs());
dbgs() << '\n';
}
#endif

void RegisterBankInfo::InstructionMapping::print(raw_ostream &OS) const {
OS << "ID: " << getID() << " Cost: " << getCost() << " Mapping: ";
Expand Down Expand Up @@ -621,10 +627,12 @@ RegisterBankInfo::OperandsMapper::getVRegs(unsigned OpIdx,
return Res;
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void RegisterBankInfo::OperandsMapper::dump() const {
print(dbgs(), true);
dbgs() << '\n';
}
#endif

void RegisterBankInfo::OperandsMapper::print(raw_ostream &OS,
bool ForDebug) const {
Expand Down
7 changes: 3 additions & 4 deletions lib/CodeGen/LexicalScopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,8 @@ bool LexicalScopes::dominates(const DILocation *DL, MachineBasicBlock *MBB) {
return Result;
}

/// dump - Print data structures.
void LexicalScope::dump(unsigned Indent) const {
#ifndef NDEBUG
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void LexicalScope::dump(unsigned Indent) const {
raw_ostream &err = dbgs();
err.indent(Indent);
err << "DFSIn: " << DFSIn << " DFSOut: " << DFSOut << "\n";
Expand All @@ -316,5 +315,5 @@ void LexicalScope::dump(unsigned Indent) const {
for (unsigned i = 0, e = Children.size(); i != e; ++i)
if (Children[i] != this)
Children[i]->dump(Indent + 2);
#endif
}
#endif
2 changes: 1 addition & 1 deletion lib/CodeGen/LiveDebugVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ bool LiveDebugVariables::doInitialization(Module &M) {
return Pass::doInitialization(M);
}

#ifndef NDEBUG
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD void LiveDebugVariables::dump() {
if (pImpl)
static_cast<LDVImpl*>(pImpl)->print(dbgs());
Expand Down
2 changes: 2 additions & 0 deletions lib/CodeGen/LiveInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ void LiveInterval::verify(const MachineRegisterInfo *MRI) const {
// When they exist, Spills.back().start <= LastStart,
// and WriteI[-1].start <= LastStart.

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void LiveRangeUpdater::print(raw_ostream &OS) const {
if (!isDirty()) {
if (LR)
Expand All @@ -1058,6 +1059,7 @@ void LiveRangeUpdater::print(raw_ostream &OS) const {
LLVM_DUMP_METHOD void LiveRangeUpdater::dump() const {
print(errs());
}
#endif

// Determine if A and B should be coalesced.
static inline bool coalescable(const LiveRange::Segment &A,
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/LiveIntervalAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void LiveIntervals::printInstrs(raw_ostream &OS) const {
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void LiveIntervals::dumpInstrs() const {
LLVM_DUMP_METHOD void LiveIntervals::dumpInstrs() const {
printInstrs(dbgs());
}
#endif
Expand Down
Loading

0 comments on commit 88d2075

Please sign in to comment.