Skip to content

Commit 60325ab

Browse files
[MLGO] Add Threshold to Prevent Pathological Compile Time Cases (#119807)
This patch adds a threshold flag, -mlregalloc-max-cascade, to prevent live ranges from being evicted more than is necessary. After deploying a new regalloc model, we ran into some pathological cases where the model decided it wanted to ping-pong evictions, taking up a large amount of compile time. This threshold is mostly a stop gap while we continue to investigate other solutions and work on minimizing/constructing test cases.
1 parent 3133acf commit 60325ab

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ static cl::opt<std::string> InteractiveChannelBaseName(
6363
"outgoing name should be "
6464
"<regalloc-evict-interactive-channel-base>.out"));
6565

66+
static cl::opt<unsigned>
67+
MaxCascade("mlregalloc-max-cascade", cl::Hidden,
68+
cl::desc("The maximum number of times a live range can be "
69+
"evicted before preventing it from being evicted"),
70+
cl::init(20));
71+
6672
// Options that only make sense in development mode
6773
#ifdef LLVM_HAVE_TFLITE
6874
#include "RegAllocScore.h"
@@ -643,8 +649,16 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
643649
RegClassInfo.getNumAllocatableRegs(MRI->getRegClass(VirtReg.reg())) <
644650
RegClassInfo.getNumAllocatableRegs(
645651
MRI->getRegClass(Intf->reg())));
646-
// Only evict older cascades or live ranges without a cascade.
652+
647653
unsigned IntfCascade = RA.getExtraInfo().getCascade(Intf->reg());
654+
// There is a potential that the model could be adversarial and
655+
// continually evict live ranges over and over again, leading to a
656+
// large amount of compile time being spent in regalloc. If we hit the
657+
// threshold, prevent the range from being evicted.
658+
if (IntfCascade >= MaxCascade)
659+
return false;
660+
661+
// Only evict older cascades or live ranges without a cascade.
648662
if (Cascade <= IntfCascade) {
649663
if (!Urgent)
650664
return false;

0 commit comments

Comments
 (0)