[PATCH] D145864: [CodeGen] Introduce threshold option to constrain stack slot sharing during stack coloring.
Valery Pykhtin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 12 03:33:50 PDT 2023
vpykhtin created this revision.
vpykhtin added reviewers: resistor, arsenm, Nicola, dexonsmith.
Herald added subscribers: kosarev, hiraditya, tpr.
Herald added a project: All.
vpykhtin requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
AMDGPU code with enabled address sanitizer generates tons of stack objects (> 200000) and
takes forever to compile due to the time spent on slot sharing.
I made up the threshold value, not sure what it should be (apparently more than 42) but
on the other hand - the more stack objects you have the more useful is sharing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145864
Files:
llvm/lib/CodeGen/StackSlotColoring.cpp
Index: llvm/lib/CodeGen/StackSlotColoring.cpp
===================================================================
--- llvm/lib/CodeGen/StackSlotColoring.cpp
+++ llvm/lib/CodeGen/StackSlotColoring.cpp
@@ -50,6 +50,12 @@
cl::init(false), cl::Hidden,
cl::desc("Suppress slot sharing during stack coloring"));
+static cl::opt<unsigned>
+ SlotSharingThreshold("-stack-slot-sharing-threshold", cl::init(1000),
+ cl::Hidden,
+ cl::desc("Suppress slot sharing during stack coloring "
+ "if the number of slots exceeds this value"));
+
static cl::opt<int> DCELimit("ssc-dce-limit", cl::init(-1), cl::Hidden);
STATISTIC(NumEliminated, "Number of stack slots eliminated due to coloring");
@@ -117,7 +123,7 @@
void InitializeSlots();
void ScanForSpillSlotRefs(MachineFunction &MF);
bool OverlapWithAssignments(LiveInterval *li, int Color) const;
- int ColorSlot(LiveInterval *li);
+ int ColorSlot(LiveInterval *li, bool TryShareSlots = true);
bool ColorSlots(MachineFunction &MF);
void RewriteInstruction(MachineInstr &MI, SmallVectorImpl<int> &SlotMapping,
MachineFunction &MF);
@@ -261,13 +267,13 @@
}
/// ColorSlot - Assign a "color" (stack slot) to the specified stack slot.
-int StackSlotColoring::ColorSlot(LiveInterval *li) {
+int StackSlotColoring::ColorSlot(LiveInterval *li, bool TryShareSlots) {
int Color = -1;
bool Share = false;
int FI = Register::stackSlot2Index(li->reg());
uint8_t StackID = MFI->getStackID(FI);
- if (!DisableSharing) {
+ if (TryShareSlots) {
// Check if it's possible to reuse any of the used colors.
Color = UsedColors[StackID].find_first();
@@ -321,12 +327,14 @@
SmallVector<float, 16> SlotWeights(NumObjs, 0.0);
SmallVector<SmallVector<int, 4>, 16> RevMap(NumObjs);
BitVector UsedColors(NumObjs);
+ const bool TryShareSlots =
+ !DisableSharing && SSIntervals.size() < SlotSharingThreshold;
LLVM_DEBUG(dbgs() << "Color spill slot intervals:\n");
bool Changed = false;
for (LiveInterval *li : SSIntervals) {
int SS = Register::stackSlot2Index(li->reg());
- int NewSS = ColorSlot(li);
+ int NewSS = ColorSlot(li, TryShareSlots);
assert(NewSS >= 0 && "Stack coloring failed?");
SlotMapping[SS] = NewSS;
RevMap[NewSS].push_back(SS);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145864.504417.patch
Type: text/x-patch
Size: 2416 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230312/85223da8/attachment.bin>
More information about the llvm-commits
mailing list