diff options
Diffstat (limited to 'llvm/lib/Target/X86/X86IndirectBranchTracking.cpp')
-rw-r--r-- | llvm/lib/Target/X86/X86IndirectBranchTracking.cpp | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp b/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp index 1570e7a0b2d..f280d3db6fe 100644 --- a/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp +++ b/llvm/lib/Target/X86/X86IndirectBranchTracking.cpp @@ -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::createX86IndirectBranchTrackingPass() { 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::runOnMachineFunction(MachineFunction &MF) { 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; } |