Skip to content

[MLGO] Error if default eviction advisor is requested with model #102409

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boomanaiden154
Copy link
Contributor

This patch causes the default Regalloc eviction advisor to emit an error if a model is specified. This ensures that someone passing -regalloc-model will get an error if they forget to pass -regalloc-enable-advisor=development instead of having the compiler silently ignore the flag. This does not emit a warning in the -regalloc-enable-advisor=release case, but that should be much less common as it is an explicit flag instead of the default.

This patch causes the default Regalloc eviction advisor to emit an error
if a model is specified. This ensures that someone passing
-regalloc-model will get an error if they forget to pass
-regalloc-enable-advisor=development instead of having the compiler
silently ignore the flag. This does not emit a warning in the
-regalloc-enable-advisor=release case, but that should be much less
common as it is an explicit flag instead of the default.
@boomanaiden154 boomanaiden154 requested a review from mtrofin August 8, 2024 01:28
@llvmbot llvmbot added the mlgo label Aug 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 8, 2024

@llvm/pr-subscribers-mlgo

Author: Aiden Grossman (boomanaiden154)

Changes

This patch causes the default Regalloc eviction advisor to emit an error if a model is specified. This ensures that someone passing -regalloc-model will get an error if they forget to pass -regalloc-enable-advisor=development instead of having the compiler silently ignore the flag. This does not emit a warning in the -regalloc-enable-advisor=release case, but that should be much less common as it is an explicit flag instead of the default.


Full diff: https://github.com/llvm/llvm-project/pull/102409.diff

3 Files Affected:

  • (modified) llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp (+1-1)
  • (modified) llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp (+12)
  • (added) llvm/test/CodeGen/MLRegAlloc/dev-mode-default-advisor-model-error.ll (+14)
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 4f0fab8e58bf83..3fa359d89ce2bf 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -72,7 +72,7 @@ static cl::opt<std::string> TrainingLog(
     "regalloc-training-log", cl::Hidden,
     cl::desc("Training log for the register allocator eviction model"));
 
-static cl::opt<std::string> ModelUnderTraining(
+cl::opt<std::string> ModelUnderTraining(
     "regalloc-model", cl::Hidden,
     cl::desc("The model being trained for register allocation eviction"));
 
diff --git a/llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp b/llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
index a1dccc4d59723b..cf5f760afbe51d 100644
--- a/llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
+++ b/llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
@@ -44,6 +44,10 @@ static cl::opt<bool> EnableLocalReassignment(
              "may be compile time intensive"),
     cl::init(false));
 
+#ifdef LLVM_HAVE_TFLITE
+extern cl::opt<std::string> ModelUnderTraining;
+#endif // #ifdef LLVM_HAVE_TFLITE
+
 namespace llvm {
 cl::opt<unsigned> EvictInterferenceCutoff(
     "regalloc-eviction-max-interference-cutoff", cl::Hidden,
@@ -85,6 +89,14 @@ class DefaultEvictionAdvisorAnalysis final
     if (NotAsRequested)
       M.getContext().emitError("Requested regalloc eviction advisor analysis "
                                "could not be created. Using default");
+
+#ifdef LLVM_HAVE_TFLITE
+    if (!ModelUnderTraining.empty())
+      M.getContext().emitError(
+          "A model has been passed in, but the default eviction advisor "
+          "analysis was requested. The model will not be used.");
+#endif // #ifdef LLVM_HAVE_TFLITE
+
     return RegAllocEvictionAdvisorAnalysis::doInitialization(M);
   }
   const bool NotAsRequested;
diff --git a/llvm/test/CodeGen/MLRegAlloc/dev-mode-default-advisor-model-error.ll b/llvm/test/CodeGen/MLRegAlloc/dev-mode-default-advisor-model-error.ll
new file mode 100644
index 00000000000000..e88046d32ef763
--- /dev/null
+++ b/llvm/test/CodeGen/MLRegAlloc/dev-mode-default-advisor-model-error.ll
@@ -0,0 +1,14 @@
+; REQUIRES: have_tflite
+; REQUIRES: x86_64-linux
+;
+; Checking that if we specify a model, but do not specify the development
+; advisor, we get an error.
+;
+; RUN: not llc -mtriple=x86_64-linux-unknown -regalloc=greedy -regalloc-enable-advisor=default \
+; RUN:   -regalloc-model=/model_foo %s -o /dev/null 2>&1 | FileCheck %s
+
+; CHECK: A model has been passed in, but the default eviction advisor analysis was requested. The model will not be used.
+
+define i32 @foo() {
+  ret i32 0
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants