[RegAllocGreedy] Provide a subtarget hook to disable the local reassignment

heuristic.
By default, no functionality change.
This is a follow-up of r212099.

This hook provides a finer grain to control the optimization.

<rdar://problem/17444599>

llvm-svn: 212204
This commit is contained in:
Quentin Colombet 2014-07-02 18:32:04 +00:00
parent d47fb5b339
commit 5caa6a2da1
3 changed files with 25 additions and 4 deletions

View File

@ -100,6 +100,12 @@ public:
AntiDepBreakMode& Mode, AntiDepBreakMode& Mode,
RegClassVector& CriticalPathRCs) const; RegClassVector& CriticalPathRCs) const;
/// \brief True if the subtarget should run the local reassignment
/// heuristic of the register allocator.
/// This heuristic may be compile time intensive, \p OptLevel provides
/// a finer grain to tune the register allocator.
virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const;
/// \brief Enable use of alias analysis during code generation (during MI /// \brief Enable use of alias analysis during code generation (during MI
/// scheduling, DAGCombine, etc.). /// scheduling, DAGCombine, etc.).
virtual bool useAA() const; virtual bool useAA() const;

View File

@ -44,6 +44,7 @@
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Timer.h" #include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <queue> #include <queue>
using namespace llvm; using namespace llvm;
@ -83,7 +84,7 @@ static cl::opt<bool> EnableLocalReassignment(
"enable-local-reassign", cl::Hidden, "enable-local-reassign", cl::Hidden,
cl::desc("Local reassignment can yield better allocation decisions, but " cl::desc("Local reassignment can yield better allocation decisions, but "
"may be compile time intensive"), "may be compile time intensive"),
cl::init(true)); cl::init(false));
// FIXME: Find a good default for this flag and remove the flag. // FIXME: Find a good default for this flag and remove the flag.
static cl::opt<unsigned> static cl::opt<unsigned>
@ -291,6 +292,10 @@ class RAGreedy : public MachineFunctionPass,
/// Callee-save register cost, calculated once per machine function. /// Callee-save register cost, calculated once per machine function.
BlockFrequency CSRCost; BlockFrequency CSRCost;
/// Run or not the local reassignment heuristic. This information is
/// obtained from the TargetSubtargetInfo.
bool EnableLocalReassign;
public: public:
RAGreedy(); RAGreedy();
@ -737,7 +742,7 @@ bool RAGreedy::canEvictInterference(LiveInterval &VirtReg, unsigned PhysReg,
// Evicting another local live range in this case could lead to suboptimal // Evicting another local live range in this case could lead to suboptimal
// coloring. // coloring.
if (!MaxCost.isMax() && IsLocal && LIS->intervalIsInOneMBB(*Intf) && if (!MaxCost.isMax() && IsLocal && LIS->intervalIsInOneMBB(*Intf) &&
(!EnableLocalReassignment || !canReassign(*Intf, PhysReg))) { (!EnableLocalReassign || !canReassign(*Intf, PhysReg))) {
return false; return false;
} }
} }
@ -2314,9 +2319,14 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
<< "********** Function: " << mf.getName() << '\n'); << "********** Function: " << mf.getName() << '\n');
MF = &mf; MF = &mf;
TRI = MF->getTarget().getRegisterInfo(); const TargetMachine &TM = MF->getTarget();
TII = MF->getTarget().getInstrInfo(); TRI = TM.getRegisterInfo();
TII = TM.getInstrInfo();
RCI.runOnMachineFunction(mf); RCI.runOnMachineFunction(mf);
EnableLocalReassign = EnableLocalReassignment ||
TM.getSubtargetImpl()->enableRALocalReassignment(TM.getOptLevel());
if (VerifyEnabled) if (VerifyEnabled)
MF->verify(this, "Before greedy register allocator"); MF->verify(this, "Before greedy register allocator");

View File

@ -47,6 +47,11 @@ bool TargetSubtargetInfo::enableMachineScheduler() const {
return false; return false;
} }
bool TargetSubtargetInfo::enableRALocalReassignment(
CodeGenOpt::Level OptLevel) const {
return true;
}
bool TargetSubtargetInfo::enablePostMachineScheduler() const { bool TargetSubtargetInfo::enablePostMachineScheduler() const {
return false; return false;
} }