[llvm] 60325ab - [MLGO] Add Threshold to Prevent Pathological Compile Time Cases (#119807)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 12 20:46:49 PST 2024
Author: Aiden Grossman
Date: 2024-12-12T20:46:45-08:00
New Revision: 60325abeb3226b17c28429dfa6e175f25c171ec0
URL: https://github.com/llvm/llvm-project/commit/60325abeb3226b17c28429dfa6e175f25c171ec0
DIFF: https://github.com/llvm/llvm-project/commit/60325abeb3226b17c28429dfa6e175f25c171ec0.diff
LOG: [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.
Added:
Modified:
llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 67ce0a69d849a5..23ab021c099456 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -63,6 +63,12 @@ static cl::opt<std::string> InteractiveChannelBaseName(
"outgoing name should be "
"<regalloc-evict-interactive-channel-base>.out"));
+static cl::opt<unsigned>
+ MaxCascade("mlregalloc-max-cascade", cl::Hidden,
+ cl::desc("The maximum number of times a live range can be "
+ "evicted before preventing it from being evicted"),
+ cl::init(20));
+
// Options that only make sense in development mode
#ifdef LLVM_HAVE_TFLITE
#include "RegAllocScore.h"
@@ -643,8 +649,16 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
RegClassInfo.getNumAllocatableRegs(MRI->getRegClass(VirtReg.reg())) <
RegClassInfo.getNumAllocatableRegs(
MRI->getRegClass(Intf->reg())));
- // Only evict older cascades or live ranges without a cascade.
+
unsigned IntfCascade = RA.getExtraInfo().getCascade(Intf->reg());
+ // There is a potential that the model could be adversarial and
+ // continually evict live ranges over and over again, leading to a
+ // large amount of compile time being spent in regalloc. If we hit the
+ // threshold, prevent the range from being evicted.
+ if (IntfCascade >= MaxCascade)
+ return false;
+
+ // Only evict older cascades or live ranges without a cascade.
if (Cascade <= IntfCascade) {
if (!Urgent)
return false;
More information about the llvm-commits
mailing list