[llvm] r280056 - Replace incorrect "#ifdef DEBUG" with "#ifndef NDEBUG".

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 29 20:16:16 PDT 2016


Author: jyknight
Date: Mon Aug 29 22:16:16 2016
New Revision: 280056

URL: http://llvm.org/viewvc/llvm-project?rev=280056&view=rev
Log:
Replace incorrect "#ifdef DEBUG" with "#ifndef NDEBUG".

The former is simply wrong -- the code will either never be used or will
always be used, rather than being dependent upon whether it's built with
debug assertions enabled.

The macro DEBUG isn't ever set by the llvm build system. But, the macro
DEBUG(X) is defined (unconditionally) if you happen to include
llvm/Support/Debug.h.

The code in Value.h which was erroneously protected by the #ifdef DEBUG
didn't even compile -- you can't cast<> from an LLVMOpaqueValue
directly. Fortunately, it was never invoked, as Core.cpp included
Value.h before Debug.h.

The conditionalized code in AArch64CollectLOH.cpp was previously always
used, as it includes Debug.h.

Modified:
    llvm/trunk/include/llvm/IR/Value.h
    llvm/trunk/lib/Target/AArch64/AArch64CollectLOH.cpp

Modified: llvm/trunk/include/llvm/IR/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=280056&r1=280055&r2=280056&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Value.h (original)
+++ llvm/trunk/include/llvm/IR/Value.h Mon Aug 29 22:16:16 2016
@@ -805,9 +805,9 @@ inline Value **unwrap(LLVMValueRef *Vals
 
 template<typename T>
 inline T **unwrap(LLVMValueRef *Vals, unsigned Length) {
-#ifdef DEBUG
+#ifndef NDEBUG
   for (LLVMValueRef *I = Vals, *E = Vals + Length; I != E; ++I)
-    cast<T>(*I);
+    unwrap<T>(*I); // For side effect of calling assert on invalid usage.
 #endif
   (void)Length;
   return reinterpret_cast<T**>(Vals);

Modified: llvm/trunk/lib/Target/AArch64/AArch64CollectLOH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64CollectLOH.cpp?rev=280056&r1=280055&r2=280056&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64CollectLOH.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64CollectLOH.cpp Mon Aug 29 22:16:16 2016
@@ -138,6 +138,7 @@ BasicBlockScopeOnly("aarch64-collect-loh
 
 STATISTIC(NumADRPSimpleCandidate,
           "Number of simplifiable ADRP dominate by another");
+#ifndef NDEBUG
 STATISTIC(NumADRPComplexCandidate2,
           "Number of simplifiable ADRP reachable by 2 defs");
 STATISTIC(NumADRPComplexCandidate3,
@@ -156,11 +157,14 @@ STATISTIC(NumLDRToLDRWithImm,
           "Number of simplifiable LDR with imm reachable by LDR");
 STATISTIC(NumADDToLDR, "Number of simplifiable LDR reachable by ADD");
 STATISTIC(NumLDRToLDR, "Number of simplifiable LDR reachable by LDR");
+#endif // NDEBUG
 STATISTIC(NumADRPToLDR, "Number of simplifiable LDR reachable by ADRP");
+#ifndef NDEBUG
 STATISTIC(NumCplxLvl1, "Number of complex case of level 1");
 STATISTIC(NumTooCplxLvl1, "Number of too complex case of level 1");
 STATISTIC(NumCplxLvl2, "Number of complex case of level 2");
 STATISTIC(NumTooCplxLvl2, "Number of too complex case of level 2");
+#endif // NDEBUG
 STATISTIC(NumADRSimpleCandidate, "Number of simplifiable ADRP + ADD");
 STATISTIC(NumADRComplexCandidate, "Number of too complex ADRP + ADD");
 
@@ -627,7 +631,7 @@ static void computeADRP(const InstrToIns
       AArch64FI.addLOHDirective(MCLOH_AdrpAdrp, {L2, L1});
       ++NumADRPSimpleCandidate;
     }
-#ifdef DEBUG
+#ifndef NDEBUG
     else if (Size == 2)
       ++NumADRPComplexCandidate2;
     else if (Size == 3)
@@ -771,10 +775,10 @@ static void computeOthers(const InstrToI
                           AArch64FunctionInfo &AArch64FI, const MapRegToId &RegToId,
                           const MachineDominatorTree *MDT) {
   SetOfMachineInstr *InvolvedInLOHs = nullptr;
-#ifdef DEBUG
+#ifndef NDEBUG
   SetOfMachineInstr InvolvedInLOHsStorage;
   InvolvedInLOHs = &InvolvedInLOHsStorage;
-#endif // DEBUG
+#endif // NDEBUG
   DEBUG(dbgs() << "*** Compute LOH for Others\n");
   // ADRP -> ADD/LDR -> LDR/STR pattern.
   // Fall back to ADRP -> ADD pattern if we fail to catch the bigger pattern.
@@ -815,7 +819,7 @@ static void computeOthers(const InstrToI
   // PotentialCandidates are result of a chain ADRP -> ADD/LDR ->
   // A potential candidate becomes a candidate, if its current immediate
   // operand is zero and all nodes of the chain have respectively only one user
-#ifdef DEBUG
+#ifndef NDEBUG
   SetOfMachineInstr DefsOfPotentialCandidates;
 #endif
   for (const MachineInstr *Candidate : PotentialCandidates) {
@@ -831,7 +835,7 @@ static void computeOthers(const InstrToI
           getUses(DefsPerColorToUses,
                   RegToId.find(Def->getOperand(0).getReg())->second, *Def);
       if (Users->size() > 1) {
-#ifdef DEBUG
+#ifndef NDEBUG
         // if all the uses of this def are in potential candidate, this is
         // a complex candidate of level 2.
         bool IsLevel2 = true;
@@ -844,7 +848,7 @@ static void computeOthers(const InstrToI
         }
         if (IsLevel2)
           ++NumCplxLvl2;
-#endif // DEBUG
+#endif // NDEBUG
         PotentialADROpportunities.insert(Def);
         continue;
       }
@@ -859,7 +863,7 @@ static void computeOthers(const InstrToI
         getUses(DefsPerColorToUses,
                 RegToId.find(Def->getOperand(0).getReg())->second, *Def);
     if (Users->size() > 1) {
-#ifdef DEBUG
+#ifndef NDEBUG
       // if all the uses of this def are in the defs of the potential candidate,
       // this is a complex candidate of level 1
       if (DefsOfPotentialCandidates.empty()) {
@@ -881,7 +885,7 @@ static void computeOthers(const InstrToI
       }
       if (!Found)
         ++NumCplxLvl1;
-#endif // DEBUG
+#endif // NDEBUG
       continue;
     }
 
@@ -928,7 +932,7 @@ static void computeOthers(const InstrToI
                "L2 already involved in LOH.");
         assert((!InvolvedInLOHs || InvolvedInLOHs->insert(Candidate)) &&
                "Candidate already involved in LOH.");
-#ifdef DEBUG
+#ifndef NDEBUG
         // get the immediate of the load
         if (Candidate->getOperand(2).getImm() == 0)
           if (ImmediateDefOpc == AArch64::ADDXri)
@@ -939,7 +943,7 @@ static void computeOthers(const InstrToI
           ++NumADDToLDRWithImm;
         else
           ++NumLDRToLDRWithImm;
-#endif // DEBUG
+#endif // NDEBUG
       }
     } else {
       if (ImmediateDefOpc == AArch64::ADRP)
@@ -962,7 +966,7 @@ static void computeOthers(const InstrToI
                "L2 already involved in LOH.");
         assert((!InvolvedInLOHs || InvolvedInLOHs->insert(Candidate)) &&
                "Candidate already involved in LOH.");
-#ifdef DEBUG
+#ifndef NDEBUG
         // get the immediate of the store
         if (Candidate->getOperand(2).getImm() == 0)
           if (ImmediateDefOpc == AArch64::ADDXri)




More information about the llvm-commits mailing list