diff options
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
| -rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 36 | 
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 03ceac10beec..530954976292 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -1,4 +1,4 @@ -//===-- BranchFolding.cpp - Fold machine code branch instructions ---------===// +//===- BranchFolding.cpp - Fold machine code branch instructions ----------===//  //  //                     The LLVM Compiler Infrastructure  // @@ -18,30 +18,46 @@  //===----------------------------------------------------------------------===//  #include "BranchFolding.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/BitVector.h" +#include "llvm/ADT/SmallPtrSet.h"  #include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/Statistic.h" +#include "llvm/ADT/STLExtras.h"  #include "llvm/CodeGen/Analysis.h" +#include "llvm/CodeGen/MachineBasicBlock.h"  #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"  #include "llvm/CodeGen/MachineBranchProbabilityInfo.h" +#include "llvm/CodeGen/MachineFunction.h"  #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstr.h"  #include "llvm/CodeGen/MachineJumpTableInfo.h" -#include "llvm/CodeGen/MachineMemOperand.h"  #include "llvm/CodeGen/MachineLoopInfo.h"  #include "llvm/CodeGen/MachineModuleInfo.h" +#include "llvm/CodeGen/MachineOperand.h"  #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/CodeGen/Passes.h"  #include "llvm/CodeGen/TargetPassConfig.h"  #include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h"  #include "llvm/IR/Function.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Pass.h" +#include "llvm/Support/BlockFrequency.h" +#include "llvm/Support/BranchProbability.h"  #include "llvm/Support/CommandLine.h"  #include "llvm/Support/Debug.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/raw_ostream.h"  #include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetMachine.h"  #include "llvm/Target/TargetRegisterInfo.h"  #include "llvm/Target/TargetSubtargetInfo.h" -#include <algorithm> +#include <cassert> +#include <cstddef> +#include <iterator> +#include <numeric> +#include <vector> +  using namespace llvm;  #define DEBUG_TYPE "branch-folder" @@ -69,10 +85,12 @@ TailMergeSize("tail-merge-size",                                cl::init(3), cl::Hidden);  namespace { +    /// BranchFolderPass - Wrap branch folder in a machine function pass.    class BranchFolderPass : public MachineFunctionPass {    public:      static char ID; +      explicit BranchFolderPass(): MachineFunctionPass(ID) {}      bool runOnMachineFunction(MachineFunction &MF) override; @@ -84,7 +102,8 @@ namespace {        MachineFunctionPass::getAnalysisUsage(AU);      }    }; -} + +} // end anonymous namespace  char BranchFolderPass::ID = 0;  char &llvm::BranchFolderPassID = BranchFolderPass::ID; @@ -368,7 +387,7 @@ MachineBasicBlock *BranchFolder::SplitMBBAt(MachineBasicBlock &CurMBB,    // Create the fall-through block.    MachineFunction::iterator MBBI = CurMBB.getIterator(); -  MachineBasicBlock *NewMBB =MF.CreateMachineBasicBlock(BB); +  MachineBasicBlock *NewMBB = MF.CreateMachineBasicBlock(BB);    CurMBB.getParent()->insert(++MBBI, NewMBB);    // Move all the successors of this block to the specified block. @@ -506,7 +525,7 @@ static unsigned CountTerminators(MachineBasicBlock *MBB,                                   MachineBasicBlock::iterator &I) {    I = MBB->end();    unsigned NumTerms = 0; -  for (;;) { +  while (true) {      if (I == MBB->begin()) {        I = MBB->end();        break; @@ -1601,7 +1620,6 @@ ReoptimizeBlock:    // block doesn't fall through into some other block, see if we can find a    // place to move this block where a fall-through will happen.    if (!PrevBB.canFallThrough()) { -      // Now we know that there was no fall-through into this block, check to      // see if it has a fall-through into its successor.      bool CurFallsThru = MBB->canFallThrough();  | 
