Skip to content

Commit

Permalink
[RegAllocGreedy] Provide a subtarget hook to disable the local reassi…
Browse files Browse the repository at this point in the history
…gnment

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>


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212204 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Quentin Colombet committed Jul 2, 2014
1 parent f9b6d03 commit 5599fde
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions include/llvm/Target/TargetSubtargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
AntiDepBreakMode& Mode,
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
/// scheduling, DAGCombine, etc.).
virtual bool useAA() const;
Expand Down
18 changes: 14 additions & 4 deletions lib/CodeGen/RegAllocGreedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <queue>

using namespace llvm;
Expand Down Expand Up @@ -83,7 +84,7 @@ static cl::opt<bool> EnableLocalReassignment(
"enable-local-reassign", cl::Hidden,
cl::desc("Local reassignment can yield better allocation decisions, but "
"may be compile time intensive"),
cl::init(true));
cl::init(false));

// FIXME: Find a good default for this flag and remove the flag.
static cl::opt<unsigned>
Expand Down Expand Up @@ -291,6 +292,10 @@ class RAGreedy : public MachineFunctionPass,
/// Callee-save register cost, calculated once per machine function.
BlockFrequency CSRCost;

/// Run or not the local reassignment heuristic. This information is
/// obtained from the TargetSubtargetInfo.
bool EnableLocalReassign;

public:
RAGreedy();

Expand Down Expand Up @@ -737,7 +742,7 @@ bool RAGreedy::canEvictInterference(LiveInterval &VirtReg, unsigned PhysReg,
// Evicting another local live range in this case could lead to suboptimal
// coloring.
if (!MaxCost.isMax() && IsLocal && LIS->intervalIsInOneMBB(*Intf) &&
(!EnableLocalReassignment || !canReassign(*Intf, PhysReg))) {
(!EnableLocalReassign || !canReassign(*Intf, PhysReg))) {
return false;
}
}
Expand Down Expand Up @@ -2314,9 +2319,14 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
<< "********** Function: " << mf.getName() << '\n');

MF = &mf;
TRI = MF->getTarget().getRegisterInfo();
TII = MF->getTarget().getInstrInfo();
const TargetMachine &TM = MF->getTarget();
TRI = TM.getRegisterInfo();
TII = TM.getInstrInfo();
RCI.runOnMachineFunction(mf);

EnableLocalReassign = EnableLocalReassignment ||
TM.getSubtargetImpl()->enableRALocalReassignment(TM.getOptLevel());

if (VerifyEnabled)
MF->verify(this, "Before greedy register allocator");

Expand Down
5 changes: 5 additions & 0 deletions lib/Target/TargetSubtargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ bool TargetSubtargetInfo::enableMachineScheduler() const {
return false;
}

bool TargetSubtargetInfo::enableRALocalReassignment(
CodeGenOpt::Level OptLevel) const {
return true;
}

bool TargetSubtargetInfo::enablePostMachineScheduler() const {
return false;
}
Expand Down

0 comments on commit 5599fde

Please sign in to comment.