[llvm] r325967 - Sink the verification code around the assert where it's handled and wrap in NDEBUG.

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 14:32:05 PST 2018


Author: echristo
Date: Fri Feb 23 14:32:05 2018
New Revision: 325967

URL: http://llvm.org/viewvc/llvm-project?rev=325967&view=rev
Log:
Sink the verification code around the assert where it's handled and wrap in NDEBUG.

This has the advantage of making release only builds more warning
free and there's no need to make this routine a class function if
it isn't using class members anyhow.

Modified:
    llvm/trunk/lib/Target/X86/X86IndirectBranchTracking.cpp

Modified: llvm/trunk/lib/Target/X86/X86IndirectBranchTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86IndirectBranchTracking.cpp?rev=325967&r1=325966&r2=325967&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86IndirectBranchTracking.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86IndirectBranchTracking.cpp Fri Feb 23 14:32:05 2018
@@ -55,17 +55,6 @@ private:
   /// Endbr opcode for the current machine function.
   unsigned int EndbrOpcode;
 
-  /// The function looks for an indirect jump terminator in MBB predecessors.
-  ///
-  /// Jump tables are generated when lowering switch-case statements or
-  /// setjmp/longjump functions.
-  /// As a result only indirect jumps use jump tables.
-  /// The function verifies this assumption.
-  ///
-  /// \return true if the input \p MBB has a predecessor MBB with indirect
-  /// branch terminator or false otherwise.
-  bool verifyIndirectJump(const MachineBasicBlock *MBB) const;
-
   /// Adds a new ENDBR instruction to the begining of the MBB.
   /// The function will not add it if already exists.
   /// It will add ENDBR32 or ENDBR64 opcode, depending on the target.
@@ -80,16 +69,6 @@ FunctionPass *llvm::createX86IndirectBra
   return new X86IndirectBranchTrackingPass();
 }
 
-bool X86IndirectBranchTrackingPass::verifyIndirectJump(
-    const MachineBasicBlock *MBB) const {
-  for (auto &PredMBB : MBB->predecessors())
-    for (auto &TermI : PredMBB->terminators())
-      if (TermI.isIndirectBranch())
-        return true;
-
-  return false;
-}
-
 void X86IndirectBranchTrackingPass::addENDBR(MachineBasicBlock &MBB) const {
   assert(TII && "Target instruction info was not initialized");
   assert((X86::ENDBR64 == EndbrOpcode || X86::ENDBR32 == EndbrOpcode) &&
@@ -148,11 +127,21 @@ bool X86IndirectBranchTrackingPass::runO
   if (MachineJumpTableInfo *JTI = MF.getJumpTableInfo()) {
     for (const auto &JT : JTI->getJumpTables()) {
       for (auto *MBB : JT.MBBs) {
-        // This assert verifies the assumption that this MBB has an indirect
-        // jump terminator in one of its predecessor.
-        assert(verifyIndirectJump(MBB) &&
+	// This assert verifies the assumption that this MBB has an indirect
+	// jump terminator in one of its predecessor.
+	// Jump tables are generated when lowering switch-case statements or
+	// setjmp/longjump functions. As a result only indirect jumps use jump
+	// tables.
+        #ifndef NDEBUG
+        bool hasIndirectJumpTerm = false;
+        for (auto &PredMBB : MBB->predecessors())
+          for (auto &TermI : PredMBB->terminators())
+            if (TermI.isIndirectBranch())
+              hasIndirectJumpTerm = true;
+        assert(hasIndirectJumpTerm &&
                "The MBB is not the destination of an indirect jump");
-
+	(void)hasIndirectJumpTerm;
+	#endif
         addENDBR(*MBB);
         Changed = true;
       }




More information about the llvm-commits mailing list