Skip to content

Commit

Permalink
Rename DEBUG macro to LLVM_DEBUG.
Browse files Browse the repository at this point in the history
    
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM
- Manual change to APInt
- Manually chage DOCS as regex doesn't match it.

In the transition period the DEBUG() macro is still present and aliased
to the LLVM_DEBUG() one.

Differential Revision: https://reviews.llvm.org/D43624

llvm-svn: 332240
  • Loading branch information
nzaghen committed May 14, 2018
1 parent affbc99 commit d34e60c
Show file tree
Hide file tree
Showing 502 changed files with 9,320 additions and 8,807 deletions.
16 changes: 8 additions & 8 deletions llvm/docs/Bugpoint.rst
Expand Up @@ -198,14 +198,14 @@ desired ranges. For example:

static int calledCount = 0;
calledCount++;
DEBUG(if (calledCount < 212) return false);
DEBUG(if (calledCount > 217) return false);
DEBUG(if (calledCount == 213) return false);
DEBUG(if (calledCount == 214) return false);
DEBUG(if (calledCount == 215) return false);
DEBUG(if (calledCount == 216) return false);
DEBUG(dbgs() << "visitXOR calledCount: " << calledCount << "\n");
DEBUG(dbgs() << "I: "; I->dump());
LLVM_DEBUG(if (calledCount < 212) return false);
LLVM_DEBUG(if (calledCount > 217) return false);
LLVM_DEBUG(if (calledCount == 213) return false);
LLVM_DEBUG(if (calledCount == 214) return false);
LLVM_DEBUG(if (calledCount == 215) return false);
LLVM_DEBUG(if (calledCount == 216) return false);
LLVM_DEBUG(dbgs() << "visitXOR calledCount: " << calledCount << "\n");
LLVM_DEBUG(dbgs() << "I: "; I->dump());

could be added to ``visitXOR`` to limit ``visitXor`` to being applied only to
calls 212 and 217. This is from an actual test case and raises an important
Expand Down
2 changes: 1 addition & 1 deletion llvm/docs/CommandGuide/opt.rst
Expand Up @@ -96,7 +96,7 @@ OPTIONS
.. option:: -debug

If this is a debug build, this option will enable debug printouts from passes
which use the ``DEBUG()`` macro. See the `LLVM Programmer's Manual
which use the ``LLVM_DEBUG()`` macro. See the `LLVM Programmer's Manual
<../ProgrammersManual.html>`_, section ``#DEBUG`` for more information.

.. option:: -load=<plugin>
Expand Down
6 changes: 3 additions & 3 deletions llvm/docs/CommandLine.rst
Expand Up @@ -886,12 +886,12 @@ To do this, set up your .h file with your option, like this for example:
// debug build, then the code specified as the option to the macro will be
// executed. Otherwise it will not be.
#ifdef NDEBUG
#define DEBUG(X)
#define LLVM_DEBUG(X)
#else
#define DEBUG(X) do { if (DebugFlag) { X; } } while (0)
#define LLVM_DEBUG(X) do { if (DebugFlag) { X; } } while (0)
#endif

This allows clients to blissfully use the ``DEBUG()`` macro, or the
This allows clients to blissfully use the ``LLVM_DEBUG()`` macro, or the
``DebugFlag`` explicitly if they want to. Now we just need to be able to set
the ``DebugFlag`` boolean when the option is set. To do this, we pass an
additional argument to our command line argument processor, and we specify where
Expand Down
18 changes: 9 additions & 9 deletions llvm/docs/ProgrammersManual.rst
Expand Up @@ -1020,7 +1020,7 @@ be passed by value.

.. _DEBUG:

The ``DEBUG()`` macro and ``-debug`` option
The ``LLVM_DEBUG()`` macro and ``-debug`` option
-------------------------------------------

Often when working on your pass you will put a bunch of debugging printouts and
Expand All @@ -1033,14 +1033,14 @@ them out, allowing you to enable them if you need them in the future.

The ``llvm/Support/Debug.h`` (`doxygen
<http://llvm.org/doxygen/Debug_8h_source.html>`__) file provides a macro named
``DEBUG()`` that is a much nicer solution to this problem. Basically, you can
put arbitrary code into the argument of the ``DEBUG`` macro, and it is only
``LLVM_DEBUG()`` that is a much nicer solution to this problem. Basically, you can
put arbitrary code into the argument of the ``LLVM_DEBUG`` macro, and it is only
executed if '``opt``' (or any other tool) is run with the '``-debug``' command
line argument:

.. code-block:: c++

DEBUG(dbgs() << "I am here!\n");
LLVM_DEBUG(dbgs() << "I am here!\n");

Then you can run your pass like this:

Expand All @@ -1051,13 +1051,13 @@ Then you can run your pass like this:
$ opt < a.bc > /dev/null -mypass -debug
I am here!
Using the ``DEBUG()`` macro instead of a home-brewed solution allows you to not
Using the ``LLVM_DEBUG()`` macro instead of a home-brewed solution allows you to not
have to create "yet another" command line option for the debug output for your
pass. Note that ``DEBUG()`` macros are disabled for non-asserts builds, so they
pass. Note that ``LLVM_DEBUG()`` macros are disabled for non-asserts builds, so they
do not cause a performance impact at all (for the same reason, they should also
not contain side-effects!).

One additional nice thing about the ``DEBUG()`` macro is that you can enable or
One additional nice thing about the ``LLVM_DEBUG()`` macro is that you can enable or
disable it directly in gdb. Just use "``set DebugFlag=0``" or "``set
DebugFlag=1``" from the gdb if the program is running. If the program hasn't
been started yet, you can always just run it with ``-debug``.
Expand All @@ -1076,10 +1076,10 @@ follows:
.. code-block:: c++

#define DEBUG_TYPE "foo"
DEBUG(dbgs() << "'foo' debug type\n");
LLVM_DEBUG(dbgs() << "'foo' debug type\n");
#undef DEBUG_TYPE
#define DEBUG_TYPE "bar"
DEBUG(dbgs() << "'bar' debug type\n");
LLVM_DEBUG(dbgs() << "'bar' debug type\n");
#undef DEBUG_TYPE

Then you can run your pass like this:
Expand Down
47 changes: 25 additions & 22 deletions llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h
Expand Up @@ -1030,8 +1030,9 @@ void BlockFrequencyInfoImpl<BT>::calculate(const FunctionT &F,
Nodes.clear();

// Initialize.
DEBUG(dbgs() << "\nblock-frequency: " << F.getName() << "\n================="
<< std::string(F.getName().size(), '=') << "\n");
LLVM_DEBUG(dbgs() << "\nblock-frequency: " << F.getName()
<< "\n================="
<< std::string(F.getName().size(), '=') << "\n");
initializeRPOT();
initializeLoops();

Expand Down Expand Up @@ -1067,10 +1068,11 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeRPOT() {
assert(RPOT.size() - 1 <= BlockNode::getMaxIndex() &&
"More nodes in function than Block Frequency Info supports");

DEBUG(dbgs() << "reverse-post-order-traversal\n");
LLVM_DEBUG(dbgs() << "reverse-post-order-traversal\n");
for (rpot_iterator I = rpot_begin(), E = rpot_end(); I != E; ++I) {
BlockNode Node = getNode(I);
DEBUG(dbgs() << " - " << getIndex(I) << ": " << getBlockName(Node) << "\n");
LLVM_DEBUG(dbgs() << " - " << getIndex(I) << ": " << getBlockName(Node)
<< "\n");
Nodes[*I] = Node;
}

Expand All @@ -1081,7 +1083,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeRPOT() {
}

template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {
DEBUG(dbgs() << "loop-detection\n");
LLVM_DEBUG(dbgs() << "loop-detection\n");
if (LI->empty())
return;

Expand All @@ -1099,7 +1101,7 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {

Loops.emplace_back(Parent, Header);
Working[Header.Index].Loop = &Loops.back();
DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");
LLVM_DEBUG(dbgs() << " - loop = " << getBlockName(Header) << "\n");

for (const LoopT *L : *Loop)
Q.emplace_back(L, &Loops.back());
Expand Down Expand Up @@ -1128,8 +1130,8 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::initializeLoops() {

Working[Index].Loop = HeaderData.Loop;
HeaderData.Loop->Nodes.push_back(Index);
DEBUG(dbgs() << " - loop = " << getBlockName(Header)
<< ": member = " << getBlockName(Index) << "\n");
LLVM_DEBUG(dbgs() << " - loop = " << getBlockName(Header)
<< ": member = " << getBlockName(Index) << "\n");
}
}

Expand All @@ -1150,10 +1152,10 @@ template <class BT> void BlockFrequencyInfoImpl<BT>::computeMassInLoops() {
template <class BT>
bool BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
// Compute mass in loop.
DEBUG(dbgs() << "compute-mass-in-loop: " << getLoopName(Loop) << "\n");
LLVM_DEBUG(dbgs() << "compute-mass-in-loop: " << getLoopName(Loop) << "\n");

if (Loop.isIrreducible()) {
DEBUG(dbgs() << "isIrreducible = true\n");
LLVM_DEBUG(dbgs() << "isIrreducible = true\n");
Distribution Dist;
unsigned NumHeadersWithWeight = 0;
Optional<uint64_t> MinHeaderWeight;
Expand All @@ -1165,14 +1167,14 @@ bool BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
IsIrrLoopHeader.set(Loop.Nodes[H].Index);
Optional<uint64_t> HeaderWeight = Block->getIrrLoopHeaderWeight();
if (!HeaderWeight) {
DEBUG(dbgs() << "Missing irr loop header metadata on "
<< getBlockName(HeaderNode) << "\n");
LLVM_DEBUG(dbgs() << "Missing irr loop header metadata on "
<< getBlockName(HeaderNode) << "\n");
HeadersWithoutWeight.insert(H);
continue;
}
DEBUG(dbgs() << getBlockName(HeaderNode)
<< " has irr loop header weight " << HeaderWeight.getValue()
<< "\n");
LLVM_DEBUG(dbgs() << getBlockName(HeaderNode)
<< " has irr loop header weight "
<< HeaderWeight.getValue() << "\n");
NumHeadersWithWeight++;
uint64_t HeaderWeightValue = HeaderWeight.getValue();
if (!MinHeaderWeight || HeaderWeightValue < MinHeaderWeight)
Expand All @@ -1194,8 +1196,8 @@ bool BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
assert(!getBlock(HeaderNode)->getIrrLoopHeaderWeight() &&
"Shouldn't have a weight metadata");
uint64_t MinWeight = MinHeaderWeight.getValue();
DEBUG(dbgs() << "Giving weight " << MinWeight
<< " to " << getBlockName(HeaderNode) << "\n");
LLVM_DEBUG(dbgs() << "Giving weight " << MinWeight << " to "
<< getBlockName(HeaderNode) << "\n");
if (MinWeight)
Dist.addLocal(HeaderNode, MinWeight);
}
Expand Down Expand Up @@ -1224,7 +1226,7 @@ bool BlockFrequencyInfoImpl<BT>::computeMassInLoop(LoopData &Loop) {
template <class BT>
bool BlockFrequencyInfoImpl<BT>::tryToComputeMassInFunction() {
// Compute mass in function.
DEBUG(dbgs() << "compute-mass-in-function\n");
LLVM_DEBUG(dbgs() << "compute-mass-in-function\n");
assert(!Working.empty() && "no blocks in function");
assert(!Working[0].isLoopHeader() && "entry block is a loop header");

Expand Down Expand Up @@ -1276,9 +1278,10 @@ template <class BT> struct BlockEdgesAdder {
template <class BT>
void BlockFrequencyInfoImpl<BT>::computeIrreducibleMass(
LoopData *OuterLoop, std::list<LoopData>::iterator Insert) {
DEBUG(dbgs() << "analyze-irreducible-in-";
if (OuterLoop) dbgs() << "loop: " << getLoopName(*OuterLoop) << "\n";
else dbgs() << "function\n");
LLVM_DEBUG(dbgs() << "analyze-irreducible-in-";
if (OuterLoop) dbgs()
<< "loop: " << getLoopName(*OuterLoop) << "\n";
else dbgs() << "function\n");

using namespace bfi_detail;

Expand All @@ -1304,7 +1307,7 @@ template <class BT>
bool
BlockFrequencyInfoImpl<BT>::propagateMassToSuccessors(LoopData *OuterLoop,
const BlockNode &Node) {
DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
LLVM_DEBUG(dbgs() << " - node: " << getBlockName(Node) << "\n");
// Calculate probability for successors.
Distribution Dist;
if (auto *Loop = Working[Node.Index].getPackagedLoop()) {
Expand Down
46 changes: 26 additions & 20 deletions llvm/include/llvm/Analysis/CGSCCPassManager.h
Expand Up @@ -387,15 +387,15 @@ class ModuleToPostOrderCGSCCPassAdaptor
do {
LazyCallGraph::RefSCC *RC = RCWorklist.pop_back_val();
if (InvalidRefSCCSet.count(RC)) {
DEBUG(dbgs() << "Skipping an invalid RefSCC...\n");
LLVM_DEBUG(dbgs() << "Skipping an invalid RefSCC...\n");
continue;
}

assert(CWorklist.empty() &&
"Should always start with an empty SCC worklist");

DEBUG(dbgs() << "Running an SCC pass across the RefSCC: " << *RC
<< "\n");
LLVM_DEBUG(dbgs() << "Running an SCC pass across the RefSCC: " << *RC
<< "\n");

// Push the initial SCCs in reverse post-order as we'll pop off the
// back and so see this in post-order.
Expand All @@ -409,12 +409,13 @@ class ModuleToPostOrderCGSCCPassAdaptor
// other RefSCCs should be queued above, so we just need to skip both
// scenarios here.
if (InvalidSCCSet.count(C)) {
DEBUG(dbgs() << "Skipping an invalid SCC...\n");
LLVM_DEBUG(dbgs() << "Skipping an invalid SCC...\n");
continue;
}
if (&C->getOuterRefSCC() != RC) {
DEBUG(dbgs() << "Skipping an SCC that is now part of some other "
"RefSCC...\n");
LLVM_DEBUG(dbgs()
<< "Skipping an SCC that is now part of some other "
"RefSCC...\n");
continue;
}

Expand All @@ -436,7 +437,8 @@ class ModuleToPostOrderCGSCCPassAdaptor
// If the CGSCC pass wasn't able to provide a valid updated SCC,
// the current SCC may simply need to be skipped if invalid.
if (UR.InvalidatedSCCs.count(C)) {
DEBUG(dbgs() << "Skipping invalidated root or island SCC!\n");
LLVM_DEBUG(dbgs()
<< "Skipping invalidated root or island SCC!\n");
break;
}
// Check that we didn't miss any update scenario.
Expand Down Expand Up @@ -464,9 +466,10 @@ class ModuleToPostOrderCGSCCPassAdaptor
// FIXME: If we ever start having RefSCC passes, we'll want to
// iterate there too.
if (UR.UpdatedC)
DEBUG(dbgs() << "Re-running SCC passes after a refinement of the "
"current SCC: "
<< *UR.UpdatedC << "\n");
LLVM_DEBUG(dbgs()
<< "Re-running SCC passes after a refinement of the "
"current SCC: "
<< *UR.UpdatedC << "\n");

// Note that both `C` and `RC` may at this point refer to deleted,
// invalid SCC and RefSCCs respectively. But we will short circuit
Expand Down Expand Up @@ -601,7 +604,8 @@ class CGSCCToFunctionPassAdaptor
// a pointer we can overwrite.
LazyCallGraph::SCC *CurrentC = &C;

DEBUG(dbgs() << "Running function passes across an SCC: " << C << "\n");
LLVM_DEBUG(dbgs() << "Running function passes across an SCC: " << C
<< "\n");

PreservedAnalyses PA = PreservedAnalyses::all();
for (LazyCallGraph::Node *N : Nodes) {
Expand Down Expand Up @@ -757,9 +761,9 @@ class DevirtSCCRepeatedPass
if (!F)
return false;

DEBUG(dbgs() << "Found devirutalized call from "
<< CS.getParent()->getParent()->getName() << " to "
<< F->getName() << "\n");
LLVM_DEBUG(dbgs() << "Found devirutalized call from "
<< CS.getParent()->getParent()->getName() << " to "
<< F->getName() << "\n");

// We now have a direct call where previously we had an indirect call,
// so iterate to process this devirtualization site.
Expand Down Expand Up @@ -793,16 +797,18 @@ class DevirtSCCRepeatedPass

// Otherwise, if we've already hit our max, we're done.
if (Iteration >= MaxIterations) {
DEBUG(dbgs() << "Found another devirtualization after hitting the max "
"number of repetitions ("
<< MaxIterations << ") on SCC: " << *C << "\n");
LLVM_DEBUG(
dbgs() << "Found another devirtualization after hitting the max "
"number of repetitions ("
<< MaxIterations << ") on SCC: " << *C << "\n");
PA.intersect(std::move(PassPA));
break;
}

DEBUG(dbgs()
<< "Repeating an SCC pass after finding a devirtualization in: "
<< *C << "\n");
LLVM_DEBUG(
dbgs()
<< "Repeating an SCC pass after finding a devirtualization in: " << *C
<< "\n");

// Move over the new call counts in preparation for iterating.
CallCounts = std::move(NewCallCounts);
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/RegionInfoImpl.h
Expand Up @@ -675,7 +675,7 @@ typename Tr::RegionT *RegionInfoBase<Tr>::createRegion(BlockT *entry,
#ifdef EXPENSIVE_CHECKS
region->verifyRegion();
#else
DEBUG(region->verifyRegion());
LLVM_DEBUG(region->verifyRegion());
#endif

updateStatistics(region);
Expand Down
10 changes: 5 additions & 5 deletions llvm/include/llvm/Analysis/SparsePropagation.h
Expand Up @@ -260,7 +260,7 @@ void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::MarkBlockExecutable(
BasicBlock *BB) {
if (!BBExecutable.insert(BB).second)
return;
DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << "\n");
LLVM_DEBUG(dbgs() << "Marking Block Executable: " << BB->getName() << "\n");
BBWorkList.push_back(BB); // Add the block to the work list!
}

Expand All @@ -270,8 +270,8 @@ void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::markEdgeExecutable(
if (!KnownFeasibleEdges.insert(Edge(Source, Dest)).second)
return; // This edge is already known to be executable!

DEBUG(dbgs() << "Marking Edge Executable: " << Source->getName() << " -> "
<< Dest->getName() << "\n");
LLVM_DEBUG(dbgs() << "Marking Edge Executable: " << Source->getName()
<< " -> " << Dest->getName() << "\n");

if (BBExecutable.count(Dest)) {
// The destination is already executable, but we just made an edge
Expand Down Expand Up @@ -477,7 +477,7 @@ void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::Solve() {
Value *V = ValueWorkList.back();
ValueWorkList.pop_back();

DEBUG(dbgs() << "\nPopped off V-WL: " << *V << "\n");
LLVM_DEBUG(dbgs() << "\nPopped off V-WL: " << *V << "\n");

// "V" got into the work list because it made a transition. See if any
// users are both live and in need of updating.
Expand All @@ -492,7 +492,7 @@ void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::Solve() {
BasicBlock *BB = BBWorkList.back();
BBWorkList.pop_back();

DEBUG(dbgs() << "\nPopped off BBWL: " << *BB);
LLVM_DEBUG(dbgs() << "\nPopped off BBWL: " << *BB);

// Notify all instructions in this basic block that they are newly
// executable.
Expand Down

0 comments on commit d34e60c

Please sign in to comment.