Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 5599fde

Browse files
author
Quentin Colombet
committed
[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> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212204 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f9b6d03 commit 5599fde

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

include/llvm/Target/TargetSubtargetInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
100100
AntiDepBreakMode& Mode,
101101
RegClassVector& CriticalPathRCs) const;
102102

103+
/// \brief True if the subtarget should run the local reassignment
104+
/// heuristic of the register allocator.
105+
/// This heuristic may be compile time intensive, \p OptLevel provides
106+
/// a finer grain to tune the register allocator.
107+
virtual bool enableRALocalReassignment(CodeGenOpt::Level OptLevel) const;
108+
103109
/// \brief Enable use of alias analysis during code generation (during MI
104110
/// scheduling, DAGCombine, etc.).
105111
virtual bool useAA() const;

lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Support/ErrorHandling.h"
4545
#include "llvm/Support/Timer.h"
4646
#include "llvm/Support/raw_ostream.h"
47+
#include "llvm/Target/TargetSubtargetInfo.h"
4748
#include <queue>
4849

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

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

295+
/// Run or not the local reassignment heuristic. This information is
296+
/// obtained from the TargetSubtargetInfo.
297+
bool EnableLocalReassign;
298+
294299
public:
295300
RAGreedy();
296301

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

23162321
MF = &mf;
2317-
TRI = MF->getTarget().getRegisterInfo();
2318-
TII = MF->getTarget().getInstrInfo();
2322+
const TargetMachine &TM = MF->getTarget();
2323+
TRI = TM.getRegisterInfo();
2324+
TII = TM.getInstrInfo();
23192325
RCI.runOnMachineFunction(mf);
2326+
2327+
EnableLocalReassign = EnableLocalReassignment ||
2328+
TM.getSubtargetImpl()->enableRALocalReassignment(TM.getOptLevel());
2329+
23202330
if (VerifyEnabled)
23212331
MF->verify(this, "Before greedy register allocator");
23222332

lib/Target/TargetSubtargetInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ bool TargetSubtargetInfo::enableMachineScheduler() const {
4747
return false;
4848
}
4949

50+
bool TargetSubtargetInfo::enableRALocalReassignment(
51+
CodeGenOpt::Level OptLevel) const {
52+
return true;
53+
}
54+
5055
bool TargetSubtargetInfo::enablePostMachineScheduler() const {
5156
return false;
5257
}

0 commit comments

Comments
 (0)