[PATCH] MachineCSE: Add a target query for the LookAheadLimit heurisitic

Phabricator reviews at reviews.llvm.org
Fri May 8 17:59:45 PDT 2015


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9472

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

Index: llvm/trunk/include/llvm/Target/TargetInstrInfo.h
===================================================================
--- llvm/trunk/include/llvm/Target/TargetInstrInfo.h
+++ llvm/trunk/include/llvm/Target/TargetInstrInfo.h
@@ -1235,6 +1235,14 @@
     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: llvm/trunk/lib/Target/R600/SIInstrInfo.h
===================================================================
--- llvm/trunk/lib/Target/R600/SIInstrInfo.h
+++ llvm/trunk/lib/Target/R600/SIInstrInfo.h
@@ -142,6 +142,8 @@
   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;
   }
Index: llvm/trunk/lib/CodeGen/MachineCSE.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/MachineCSE.cpp
+++ llvm/trunk/lib/CodeGen/MachineCSE.cpp
@@ -48,7 +48,7 @@
     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 @@
     }
 
   private:
-    const unsigned LookAheadLimit;
+    unsigned LookAheadLimit;
     typedef RecyclingAllocator<BumpPtrAllocator,
         ScopedHashTableVal<MachineInstr*, unsigned> > AllocatorTy;
     typedef ScopedHashTable<MachineInstr*, unsigned,
@@ -716,5 +716,6 @@
   MRI = &MF.getRegInfo();
   AA = &getAnalysis<AliasAnalysis>();
   DT = &getAnalysis<MachineDominatorTree>();
+  LookAheadLimit = TII->getMachineCSELookAheadLimit();
   return PerformCSE(DT->getRootNode());
 }

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9472.25394.patch
Type: text/x-patch
Size: 2232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150509/a9a34f72/attachment.bin>


More information about the llvm-commits mailing list