Skip to content

[MLGO] Add Threshold to Prevent Pathological Compile Time Cases #119807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
Loading