浏览代码

TailDuplication: Save MF and reduce number of parameters. NFC

Save the function in the class, and then don't pass it around. This reduces the
number of parameters and makes calls to member functions simpler.
No Functional Change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279700 91177308-0d34-0410-b5e6-96231b3b80d8
Kyle Butt 9 年之前
父节点
当前提交
227103b8b3
共有 3 个文件被更改,包括 28 次插入32 次删除
  1. 6 8
      include/llvm/CodeGen/TailDuplicator.h
  2. 1 2
      lib/CodeGen/TailDuplication.cpp
  3. 21 22
      lib/CodeGen/TailDuplicator.cpp

+ 6 - 8
include/llvm/CodeGen/TailDuplicator.h

@@ -33,6 +33,7 @@ class TailDuplicator {
   const MachineBranchProbabilityInfo *MBPI;
   const MachineBranchProbabilityInfo *MBPI;
   const MachineModuleInfo *MMI;
   const MachineModuleInfo *MMI;
   MachineRegisterInfo *MRI;
   MachineRegisterInfo *MRI;
+  MachineFunction *MF;
   bool PreRegAlloc;
   bool PreRegAlloc;
   unsigned TailDupSize;
   unsigned TailDupSize;
 
 
@@ -51,14 +52,12 @@ public:
   void initMF(MachineFunction &MF, const MachineModuleInfo *MMI,
   void initMF(MachineFunction &MF, const MachineModuleInfo *MMI,
               const MachineBranchProbabilityInfo *MBPI,
               const MachineBranchProbabilityInfo *MBPI,
               unsigned TailDupSize = 0);
               unsigned TailDupSize = 0);
-  bool tailDuplicateBlocks(MachineFunction &MF);
+  bool tailDuplicateBlocks();
   static bool isSimpleBB(MachineBasicBlock *TailBB);
   static bool isSimpleBB(MachineBasicBlock *TailBB);
-  bool shouldTailDuplicate(const MachineFunction &MF, bool IsSimple,
-                           MachineBasicBlock &TailBB);
+  bool shouldTailDuplicate(bool IsSimple, MachineBasicBlock &TailBB);
   /// Returns true if TailBB can successfully be duplicated into PredBB
   /// Returns true if TailBB can successfully be duplicated into PredBB
   bool canTailDuplicate(MachineBasicBlock *TailBB, MachineBasicBlock *PredBB);
   bool canTailDuplicate(MachineBasicBlock *TailBB, MachineBasicBlock *PredBB);
-  bool tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple,
-                              MachineBasicBlock *MBB);
+  bool tailDuplicateAndUpdate(bool IsSimple, MachineBasicBlock *MBB);
 
 
 private:
 private:
   typedef TargetInstrInfo::RegSubRegPair RegSubRegPair;
   typedef TargetInstrInfo::RegSubRegPair RegSubRegPair;
@@ -71,7 +70,7 @@ private:
                   SmallVectorImpl<std::pair<unsigned, RegSubRegPair>> &Copies,
                   SmallVectorImpl<std::pair<unsigned, RegSubRegPair>> &Copies,
                   const DenseSet<unsigned> &UsedByPhi, bool Remove);
                   const DenseSet<unsigned> &UsedByPhi, bool Remove);
   void duplicateInstruction(MachineInstr *MI, MachineBasicBlock *TailBB,
   void duplicateInstruction(MachineInstr *MI, MachineBasicBlock *TailBB,
-                            MachineBasicBlock *PredBB, MachineFunction &MF,
+                            MachineBasicBlock *PredBB,
                             DenseMap<unsigned, RegSubRegPair> &LocalVRMap,
                             DenseMap<unsigned, RegSubRegPair> &LocalVRMap,
                             const DenseSet<unsigned> &UsedByPhi);
                             const DenseSet<unsigned> &UsedByPhi);
   void updateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead,
   void updateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead,
@@ -82,8 +81,7 @@ private:
                          SmallVectorImpl<MachineBasicBlock *> &TDBBs,
                          SmallVectorImpl<MachineBasicBlock *> &TDBBs,
                          const DenseSet<unsigned> &RegsUsedByPhi,
                          const DenseSet<unsigned> &RegsUsedByPhi,
                          SmallVectorImpl<MachineInstr *> &Copies);
                          SmallVectorImpl<MachineInstr *> &Copies);
-  bool tailDuplicate(MachineFunction &MF, bool IsSimple,
-                     MachineBasicBlock *TailBB,
+  bool tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB,
                      SmallVectorImpl<MachineBasicBlock *> &TDBBs,
                      SmallVectorImpl<MachineBasicBlock *> &TDBBs,
                      SmallVectorImpl<MachineInstr *> &Copies);
                      SmallVectorImpl<MachineInstr *> &Copies);
   void appendCopies(MachineBasicBlock *MBB,
   void appendCopies(MachineBasicBlock *MBB,

+ 1 - 2
lib/CodeGen/TailDuplication.cpp

@@ -47,13 +47,12 @@ bool TailDuplicatePass::runOnMachineFunction(MachineFunction &MF) {
   if (skipFunction(*MF.getFunction()))
   if (skipFunction(*MF.getFunction()))
     return false;
     return false;
 
 
-  auto MMI = getAnalysisIfAvailable<MachineModuleInfo>();
   auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
   auto MBPI = &getAnalysis<MachineBranchProbabilityInfo>();
 
 
   Duplicator.initMF(MF, MMI, MBPI);
   Duplicator.initMF(MF, MMI, MBPI);
 
 
   bool MadeChange = false;
   bool MadeChange = false;
-  while (Duplicator.tailDuplicateBlocks(MF))
+  while (Duplicator.tailDuplicateBlocks())
     MadeChange = true;
     MadeChange = true;
 
 
   return MadeChange;
   return MadeChange;

+ 21 - 22
lib/CodeGen/TailDuplicator.cpp

@@ -56,12 +56,14 @@ static cl::opt<unsigned> TailDupLimit("tail-dup-limit", cl::init(~0U),
 
 
 namespace llvm {
 namespace llvm {
 
 
-void TailDuplicator::initMF(MachineFunction &MF, const MachineModuleInfo *MMIin,
+void TailDuplicator::initMF(MachineFunction &MFin,
+                            const MachineModuleInfo *MMIin,
                             const MachineBranchProbabilityInfo *MBPIin,
                             const MachineBranchProbabilityInfo *MBPIin,
                             unsigned TailDupSizeIn) {
                             unsigned TailDupSizeIn) {
-  TII = MF.getSubtarget().getInstrInfo();
-  TRI = MF.getSubtarget().getRegisterInfo();
-  MRI = &MF.getRegInfo();
+  MF = &MFin;
+  TII = MF->getSubtarget().getInstrInfo();
+  TRI = MF->getSubtarget().getRegisterInfo();
+  MRI = &MF->getRegInfo();
   MMI = MMIin;
   MMI = MMIin;
   MBPI = MBPIin;
   MBPI = MBPIin;
   TailDupSize = TailDupSizeIn;
   TailDupSize = TailDupSizeIn;
@@ -118,7 +120,7 @@ static void VerifyPHIs(MachineFunction &MF, bool CheckExtra) {
 }
 }
 
 
 /// Tail duplicate the block and cleanup.
 /// Tail duplicate the block and cleanup.
-bool TailDuplicator::tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple,
+bool TailDuplicator::tailDuplicateAndUpdate(bool IsSimple,
                                             MachineBasicBlock *MBB) {
                                             MachineBasicBlock *MBB) {
   // Save the successors list.
   // Save the successors list.
   SmallSetVector<MachineBasicBlock *, 8> Succs(MBB->succ_begin(),
   SmallSetVector<MachineBasicBlock *, 8> Succs(MBB->succ_begin(),
@@ -126,13 +128,13 @@ bool TailDuplicator::tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple,
 
 
   SmallVector<MachineBasicBlock *, 8> TDBBs;
   SmallVector<MachineBasicBlock *, 8> TDBBs;
   SmallVector<MachineInstr *, 16> Copies;
   SmallVector<MachineInstr *, 16> Copies;
-  if (!tailDuplicate(MF, IsSimple, MBB, TDBBs, Copies))
+  if (!tailDuplicate(IsSimple, MBB, TDBBs, Copies))
     return false;
     return false;
 
 
   ++NumTails;
   ++NumTails;
 
 
   SmallVector<MachineInstr *, 8> NewPHIs;
   SmallVector<MachineInstr *, 8> NewPHIs;
-  MachineSSAUpdater SSAUpdate(MF, &NewPHIs);
+  MachineSSAUpdater SSAUpdate(*MF, &NewPHIs);
 
 
   // TailBB's immediate successors are now successors of those predecessors
   // TailBB's immediate successors are now successors of those predecessors
   // which duplicated TailBB. Add the predecessors as sources to the PHI
   // which duplicated TailBB. Add the predecessors as sources to the PHI
@@ -221,15 +223,15 @@ bool TailDuplicator::tailDuplicateAndUpdate(MachineFunction &MF, bool IsSimple,
 /// Look for small blocks that are unconditionally branched to and do not fall
 /// Look for small blocks that are unconditionally branched to and do not fall
 /// through. Tail-duplicate their instructions into their predecessors to
 /// through. Tail-duplicate their instructions into their predecessors to
 /// eliminate (dynamic) branches.
 /// eliminate (dynamic) branches.
-bool TailDuplicator::tailDuplicateBlocks(MachineFunction &MF) {
+bool TailDuplicator::tailDuplicateBlocks() {
   bool MadeChange = false;
   bool MadeChange = false;
 
 
   if (PreRegAlloc && TailDupVerify) {
   if (PreRegAlloc && TailDupVerify) {
     DEBUG(dbgs() << "\n*** Before tail-duplicating\n");
     DEBUG(dbgs() << "\n*** Before tail-duplicating\n");
-    VerifyPHIs(MF, true);
+    VerifyPHIs(*MF, true);
   }
   }
 
 
-  for (MachineFunction::iterator I = ++MF.begin(), E = MF.end(); I != E;) {
+  for (MachineFunction::iterator I = ++MF->begin(), E = MF->end(); I != E;) {
     MachineBasicBlock *MBB = &*I++;
     MachineBasicBlock *MBB = &*I++;
 
 
     if (NumTails == TailDupLimit)
     if (NumTails == TailDupLimit)
@@ -237,14 +239,14 @@ bool TailDuplicator::tailDuplicateBlocks(MachineFunction &MF) {
 
 
     bool IsSimple = isSimpleBB(MBB);
     bool IsSimple = isSimpleBB(MBB);
 
 
-    if (!shouldTailDuplicate(MF, IsSimple, *MBB))
+    if (!shouldTailDuplicate(IsSimple, *MBB))
       continue;
       continue;
 
 
-    MadeChange |= tailDuplicateAndUpdate(MF, IsSimple, MBB);
+    MadeChange |= tailDuplicateAndUpdate(IsSimple, MBB);
   }
   }
 
 
   if (PreRegAlloc && TailDupVerify)
   if (PreRegAlloc && TailDupVerify)
-    VerifyPHIs(MF, false);
+    VerifyPHIs(*MF, false);
 
 
   return MadeChange;
   return MadeChange;
 }
 }
@@ -333,10 +335,9 @@ void TailDuplicator::processPHI(
 /// the source operands due to earlier PHI translation.
 /// the source operands due to earlier PHI translation.
 void TailDuplicator::duplicateInstruction(
 void TailDuplicator::duplicateInstruction(
     MachineInstr *MI, MachineBasicBlock *TailBB, MachineBasicBlock *PredBB,
     MachineInstr *MI, MachineBasicBlock *TailBB, MachineBasicBlock *PredBB,
-    MachineFunction &MF,
     DenseMap<unsigned, RegSubRegPair> &LocalVRMap,
     DenseMap<unsigned, RegSubRegPair> &LocalVRMap,
     const DenseSet<unsigned> &UsedByPhi) {
     const DenseSet<unsigned> &UsedByPhi) {
-  MachineInstr *NewMI = TII->duplicate(*MI, MF);
+  MachineInstr *NewMI = TII->duplicate(*MI, *MF);
   if (PreRegAlloc) {
   if (PreRegAlloc) {
     for (unsigned i = 0, e = NewMI->getNumOperands(); i != e; ++i) {
     for (unsigned i = 0, e = NewMI->getNumOperands(); i != e; ++i) {
       MachineOperand &MO = NewMI->getOperand(i);
       MachineOperand &MO = NewMI->getOperand(i);
@@ -498,8 +499,7 @@ void TailDuplicator::updateSuccessorsPHIs(
 }
 }
 
 
 /// Determine if it is profitable to duplicate this block.
 /// Determine if it is profitable to duplicate this block.
-bool TailDuplicator::shouldTailDuplicate(const MachineFunction &MF,
-                                         bool IsSimple,
+bool TailDuplicator::shouldTailDuplicate(bool IsSimple,
                                          MachineBasicBlock &TailBB) {
                                          MachineBasicBlock &TailBB) {
   // Only duplicate blocks that end with unconditional branches.
   // Only duplicate blocks that end with unconditional branches.
   if (TailBB.canFallThrough())
   if (TailBB.canFallThrough())
@@ -515,7 +515,7 @@ bool TailDuplicator::shouldTailDuplicate(const MachineFunction &MF,
   unsigned MaxDuplicateCount;
   unsigned MaxDuplicateCount;
   if (TailDupSize == 0 &&
   if (TailDupSize == 0 &&
       TailDuplicateSize.getNumOccurrences() == 0 &&
       TailDuplicateSize.getNumOccurrences() == 0 &&
-      MF.getFunction()->optForSize())
+      MF->getFunction()->optForSize())
     MaxDuplicateCount = 1;
     MaxDuplicateCount = 1;
   else if (TailDupSize == 0)
   else if (TailDupSize == 0)
     MaxDuplicateCount = TailDuplicateSize;
     MaxDuplicateCount = TailDuplicateSize;
@@ -737,8 +737,7 @@ bool TailDuplicator::canTailDuplicate(MachineBasicBlock *TailBB,
 
 
 /// If it is profitable, duplicate TailBB's contents in each
 /// If it is profitable, duplicate TailBB's contents in each
 /// of its predecessors.
 /// of its predecessors.
-bool TailDuplicator::tailDuplicate(MachineFunction &MF, bool IsSimple,
-                                   MachineBasicBlock *TailBB,
+bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB,
                                    SmallVectorImpl<MachineBasicBlock *> &TDBBs,
                                    SmallVectorImpl<MachineBasicBlock *> &TDBBs,
                                    SmallVectorImpl<MachineInstr *> &Copies) {
                                    SmallVectorImpl<MachineInstr *> &Copies) {
   DEBUG(dbgs() << "\n*** Tail-duplicating BB#" << TailBB->getNumber() << '\n');
   DEBUG(dbgs() << "\n*** Tail-duplicating BB#" << TailBB->getNumber() << '\n');
@@ -790,7 +789,7 @@ bool TailDuplicator::tailDuplicate(MachineFunction &MF, bool IsSimple,
       } else {
       } else {
         // Replace def of virtual registers with new registers, and update
         // Replace def of virtual registers with new registers, and update
         // uses with PHI source register or the new registers.
         // uses with PHI source register or the new registers.
-        duplicateInstruction(MI, TailBB, PredBB, MF, LocalVRMap, UsedByPhi);
+        duplicateInstruction(MI, TailBB, PredBB, LocalVRMap, UsedByPhi);
       }
       }
     }
     }
     appendCopies(PredBB, CopyInfos, Copies);
     appendCopies(PredBB, CopyInfos, Copies);
@@ -847,7 +846,7 @@ bool TailDuplicator::tailDuplicate(MachineFunction &MF, bool IsSimple,
         // uses with PHI source register or the new registers.
         // uses with PHI source register or the new registers.
         MachineInstr *MI = &*I++;
         MachineInstr *MI = &*I++;
         assert(!MI->isBundle() && "Not expecting bundles before regalloc!");
         assert(!MI->isBundle() && "Not expecting bundles before regalloc!");
-        duplicateInstruction(MI, TailBB, PrevBB, MF, LocalVRMap, UsedByPhi);
+        duplicateInstruction(MI, TailBB, PrevBB, LocalVRMap, UsedByPhi);
         MI->eraseFromParent();
         MI->eraseFromParent();
       }
       }
       appendCopies(PrevBB, CopyInfos, Copies);
       appendCopies(PrevBB, CopyInfos, Copies);