[PATCH] D125102: [RagAllocGreedy] New hook regClassPriorityTrumpsGlobalness
Jay Foad via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 6 09:10:25 PDT 2022
foad created this revision.
foad added reviewers: arsenm, qcolombet, qiucf.
Herald added subscribers: hiraditya, MatzeB.
Herald added a project: All.
foad requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Add a new TargetRegisterInfo hook to allow targets to tweak the
priority of live ranges, so that AllocationPriority of the register
class will be treated as more important than whether the range is local
to a basic block or global. This is determined per-MachineFunction.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125102
Files:
llvm/include/llvm/CodeGen/TargetRegisterInfo.h
llvm/lib/CodeGen/RegAllocGreedy.cpp
llvm/lib/CodeGen/RegAllocGreedy.h
Index: llvm/lib/CodeGen/RegAllocGreedy.h
===================================================================
--- llvm/lib/CodeGen/RegAllocGreedy.h
+++ llvm/lib/CodeGen/RegAllocGreedy.h
@@ -322,6 +322,10 @@
/// Function
ArrayRef<uint8_t> RegCosts;
+ /// Flags for the live range priority calculation, determined once per
+ /// machine function.
+ bool RegClassPriorityTrumpsGlobalness;
+
public:
RAGreedy(const RegClassFilterFunc F = allocateAllRegClasses);
Index: llvm/lib/CodeGen/RegAllocGreedy.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -305,6 +305,7 @@
const TargetRegisterClass &RC = *MRI->getRegClass(Reg);
bool ForceGlobal = !ReverseLocal &&
(Size / SlotIndex::InstrDist) > (2 * RCI.getNumAllocatableRegs(&RC));
+ unsigned GlobalBit = 0;
if (Stage == RS_Assign && !ForceGlobal && !LI->empty() &&
LIS->intervalIsInOneMBB(*LI)) {
@@ -323,9 +324,13 @@
// Allocate global and split ranges in long->short order. Long ranges that
// don't fit should be spilled (or split) ASAP so they don't create
// interference. Mark a bit to prioritize global above local ranges.
- Prio = (1u << 29) + Size;
+ Prio = Size;
+ GlobalBit = 1;
}
- Prio |= RC.AllocationPriority << 24;
+ if (RegClassPriorityTrumpsGlobalness)
+ Prio |= RC.AllocationPriority << 25 | GlobalBit << 24;
+ else
+ Prio |= GlobalBit << 29 | RC.AllocationPriority << 24;
// Mark a higher bit to prioritize global and local above RS_Split.
Prio |= (1u << 31);
@@ -2692,6 +2697,7 @@
initializeCSRCost();
RegCosts = TRI->getRegisterCosts(*MF);
+ RegClassPriorityTrumpsGlobalness = TRI->regClassPriorityTrumpsGlobalness(*MF);
ExtraInfo.emplace();
EvictAdvisor =
Index: llvm/include/llvm/CodeGen/TargetRegisterInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetRegisterInfo.h
+++ llvm/include/llvm/CodeGen/TargetRegisterInfo.h
@@ -1076,6 +1076,14 @@
return false;
}
+ /// When prioritizing live ranges in register allocation, if this hook returns
+ /// true then the AllocationPriority of the register class will be treated as
+ /// more important than whether the range is local to a basic block or global.
+ virtual bool
+ regClassPriorityTrumpsGlobalness(const MachineFunction &MF) const {
+ return false;
+ }
+
//===--------------------------------------------------------------------===//
/// Debug information queries.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125102.427659.patch
Type: text/x-patch
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220506/1f18ed11/attachment.bin>
More information about the llvm-commits
mailing list