diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp --- a/llvm/lib/CodeGen/StackSlotColoring.cpp +++ b/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 + 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 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 &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 SlotWeights(NumObjs, 0.0); SmallVector, 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);