MachineCSE: Add a target query for the LookAheadLimit heurisitic
authorTom Stellard <thomas.stellard@amd.com>
Sat, 9 May 2015 00:56:07 +0000 (00:56 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Sat, 9 May 2015 00:56:07 +0000 (00:56 +0000)
This is used to determine whether or not to CSE physical register
defs.

Differential Revision: http://reviews.llvm.org/D9472

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236923 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetInstrInfo.h
lib/CodeGen/MachineCSE.cpp
lib/Target/R600/SIInstrInfo.h

index f9c1e523e5a843d56d965e1556c3f658d226ef2b..2b0a888fa77d5495b98363c703e379096db3355e 100644 (file)
@@ -1235,6 +1235,14 @@ public:
     return false;
   }
 
+  /// \brief Return the value to use for the MachineCSE's LookAheadLimit,
+  /// which is a heuristic used for CSE'ing phys reg defs.
+  virtual unsigned getMachineCSELookAheadLimit () const {
+    // The default lookahead is small to prevent unprofitable quadratic
+    // behavior.
+    return 5;
+  }
+
 private:
   int CallFrameSetupOpcode, CallFrameDestroyOpcode;
 };
index f72d72a2e87b050ca56cc055899e4b356b7c4367..87aaaa0834cf5186306b1fe1e70330c7dda6884d 100644 (file)
@@ -48,7 +48,7 @@ namespace {
     MachineRegisterInfo *MRI;
   public:
     static char ID; // Pass identification
-    MachineCSE() : MachineFunctionPass(ID), LookAheadLimit(5), CurrVN(0) {
+    MachineCSE() : MachineFunctionPass(ID), LookAheadLimit(0), CurrVN(0) {
       initializeMachineCSEPass(*PassRegistry::getPassRegistry());
     }
 
@@ -69,7 +69,7 @@ namespace {
     }
 
   private:
-    const unsigned LookAheadLimit;
+    unsigned LookAheadLimit;
     typedef RecyclingAllocator<BumpPtrAllocator,
         ScopedHashTableVal<MachineInstr*, unsigned> > AllocatorTy;
     typedef ScopedHashTable<MachineInstr*, unsigned,
@@ -716,5 +716,6 @@ bool MachineCSE::runOnMachineFunction(MachineFunction &MF) {
   MRI = &MF.getRegInfo();
   AA = &getAnalysis<AliasAnalysis>();
   DT = &getAnalysis<MachineDominatorTree>();
+  LookAheadLimit = TII->getMachineCSELookAheadLimit();
   return PerformCSE(DT->getRootNode());
 }
index 7e049dca7b142732f9a7827b5c008cb28d943f73..f952c0f085344164625f4b73a57307d6a036342e 100644 (file)
@@ -142,6 +142,8 @@ public:
   bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
                      unsigned Reg, MachineRegisterInfo *MRI) const final;
 
+  unsigned getMachineCSELookAheadLimit() const override { return 500; }
+
   bool isSALU(uint16_t Opcode) const {
     return get(Opcode).TSFlags & SIInstrFlags::SALU;
   }