From f01af29f01f17c15b95136f5608748b098d1faa3 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Sat, 9 May 2015 00:56:07 +0000 Subject: [PATCH] MachineCSE: Add a target query for the LookAheadLimit heurisitic This is used to determine whether or not to CSE physical register defs. Differential Revision: http://reviews.llvm.org/D9472 llvm-svn: 236923 --- llvm/include/llvm/Target/TargetInstrInfo.h | 8 ++++++++ llvm/lib/CodeGen/MachineCSE.cpp | 5 +++-- llvm/lib/Target/R600/SIInstrInfo.h | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Target/TargetInstrInfo.h b/llvm/include/llvm/Target/TargetInstrInfo.h index f9c1e523e5a8..2b0a888fa77d 100644 --- a/llvm/include/llvm/Target/TargetInstrInfo.h +++ b/llvm/include/llvm/Target/TargetInstrInfo.h @@ -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; }; diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp index f72d72a2e87b..87aaaa0834cf 100644 --- a/llvm/lib/CodeGen/MachineCSE.cpp +++ b/llvm/lib/CodeGen/MachineCSE.cpp @@ -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 > AllocatorTy; typedef ScopedHashTable(); DT = &getAnalysis(); + LookAheadLimit = TII->getMachineCSELookAheadLimit(); return PerformCSE(DT->getRootNode()); } diff --git a/llvm/lib/Target/R600/SIInstrInfo.h b/llvm/lib/Target/R600/SIInstrInfo.h index 7e049dca7b14..f952c0f08534 100644 --- a/llvm/lib/Target/R600/SIInstrInfo.h +++ b/llvm/lib/Target/R600/SIInstrInfo.h @@ -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; }