-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Support][NFC] Move OptimizationLevel to the Support directory #157057
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-mlir-execution-engine @llvm/pr-subscribers-clang Author: David Sherwood (david-arm) ChangesSometimes code depends upon the constant variables declared in OptimizationLevel (e.g. see #156802), which then requires them to add a dependency on the Passes directory. Given that code is much more likely to depend upon Support than Passes I believe it makes sense to move OptimizationLevel to Support. The Passes component already depends upon Support. Full diff: https://github.com/llvm/llvm-project/pull/157057.diff 8 Files Affected:
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 798b34b3ef0af..edaf0fa887720 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -34,9 +34,9 @@
#include "llvm/IRPrinter/IRPrintingPasses.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/MC/TargetRegistry.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 9cdb7ca7dbc9b..64bdb84a68d78 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -19,9 +19,9 @@
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/RegAllocCommon.h"
#include "llvm/IR/PassManager.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/PGOOptions.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/Inliner.h"
diff --git a/llvm/include/llvm/Passes/OptimizationLevel.h b/llvm/include/llvm/Support/OptimizationLevel.h
similarity index 100%
rename from llvm/include/llvm/Passes/OptimizationLevel.h
rename to llvm/include/llvm/Support/OptimizationLevel.h
diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt
index 91c8c4f67074d..6f1ade87bc431 100644
--- a/llvm/lib/Passes/CMakeLists.txt
+++ b/llvm/lib/Passes/CMakeLists.txt
@@ -1,6 +1,5 @@
add_llvm_component_library(LLVMPasses
CodeGenPassBuilder.cpp
- OptimizationLevel.cpp
PassBuilder.cpp
PassBuilderBindings.cpp
PassBuilderPipelines.cpp
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 587f0ece0859b..ef18bd132499f 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -184,12 +184,12 @@
#include "llvm/IR/SafepointIRVerifier.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IRPrinter/IRPrintingPasses.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/Regex.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 98821bb1408a7..cd6fc51ceafec 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -26,10 +26,10 @@
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/PGOOptions.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Target/TargetMachine.h"
@@ -2355,4 +2355,4 @@ AAManager PassBuilder::buildDefaultAAPipeline() {
bool PassBuilder::isInstrumentedPGOUse() const {
return (PGOOpt && PGOOpt->Action == PGOOptions::IRUse) ||
!UseCtxProfile.empty();
-}
\ No newline at end of file
+}
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index b29dda46b757f..cb882f80bc467 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -224,6 +224,7 @@ add_llvm_component_library(LLVMSupport
MSP430AttributeParser.cpp
Mustache.cpp
NativeFormatting.cpp
+ OptimizationLevel.cpp
OptimizedStructLayout.cpp
Optional.cpp
OptionStrCmp.cpp
diff --git a/llvm/lib/Passes/OptimizationLevel.cpp b/llvm/lib/Support/OptimizationLevel.cpp
similarity index 95%
rename from llvm/lib/Passes/OptimizationLevel.cpp
rename to llvm/lib/Support/OptimizationLevel.cpp
index a1f8c1e14b1f0..28b742f609065 100644
--- a/llvm/lib/Passes/OptimizationLevel.cpp
+++ b/llvm/lib/Support/OptimizationLevel.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/OptimizationLevel.h"
using namespace llvm;
|
@llvm/pr-subscribers-llvm-support Author: David Sherwood (david-arm) ChangesSometimes code depends upon the constant variables declared in OptimizationLevel (e.g. see #156802), which then requires them to add a dependency on the Passes directory. Given that code is much more likely to depend upon Support than Passes I believe it makes sense to move OptimizationLevel to Support. The Passes component already depends upon Support. Full diff: https://github.com/llvm/llvm-project/pull/157057.diff 8 Files Affected:
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index 798b34b3ef0af..edaf0fa887720 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -34,9 +34,9 @@
#include "llvm/IRPrinter/IRPrintingPasses.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/MC/TargetRegistry.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 9cdb7ca7dbc9b..64bdb84a68d78 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -19,9 +19,9 @@
#include "llvm/CodeGen/MachinePassManager.h"
#include "llvm/CodeGen/RegAllocCommon.h"
#include "llvm/IR/PassManager.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/PGOOptions.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/Inliner.h"
diff --git a/llvm/include/llvm/Passes/OptimizationLevel.h b/llvm/include/llvm/Support/OptimizationLevel.h
similarity index 100%
rename from llvm/include/llvm/Passes/OptimizationLevel.h
rename to llvm/include/llvm/Support/OptimizationLevel.h
diff --git a/llvm/lib/Passes/CMakeLists.txt b/llvm/lib/Passes/CMakeLists.txt
index 91c8c4f67074d..6f1ade87bc431 100644
--- a/llvm/lib/Passes/CMakeLists.txt
+++ b/llvm/lib/Passes/CMakeLists.txt
@@ -1,6 +1,5 @@
add_llvm_component_library(LLVMPasses
CodeGenPassBuilder.cpp
- OptimizationLevel.cpp
PassBuilder.cpp
PassBuilderBindings.cpp
PassBuilderPipelines.cpp
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 587f0ece0859b..ef18bd132499f 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -184,12 +184,12 @@
#include "llvm/IR/SafepointIRVerifier.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IRPrinter/IRPrintingPasses.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/Regex.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 98821bb1408a7..cd6fc51ceafec 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -26,10 +26,10 @@
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
-#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/OptimizationLevel.h"
#include "llvm/Support/PGOOptions.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Target/TargetMachine.h"
@@ -2355,4 +2355,4 @@ AAManager PassBuilder::buildDefaultAAPipeline() {
bool PassBuilder::isInstrumentedPGOUse() const {
return (PGOOpt && PGOOpt->Action == PGOOptions::IRUse) ||
!UseCtxProfile.empty();
-}
\ No newline at end of file
+}
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index b29dda46b757f..cb882f80bc467 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -224,6 +224,7 @@ add_llvm_component_library(LLVMSupport
MSP430AttributeParser.cpp
Mustache.cpp
NativeFormatting.cpp
+ OptimizationLevel.cpp
OptimizedStructLayout.cpp
Optional.cpp
OptionStrCmp.cpp
diff --git a/llvm/lib/Passes/OptimizationLevel.cpp b/llvm/lib/Support/OptimizationLevel.cpp
similarity index 95%
rename from llvm/lib/Passes/OptimizationLevel.cpp
rename to llvm/lib/Support/OptimizationLevel.cpp
index a1f8c1e14b1f0..28b742f609065 100644
--- a/llvm/lib/Passes/OptimizationLevel.cpp
+++ b/llvm/lib/Support/OptimizationLevel.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Passes/OptimizationLevel.h"
+#include "llvm/Support/OptimizationLevel.h"
using namespace llvm;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we should split Support into "ReallySupport" and "RandomStuffThatIRAndCodeGenUse"
Sometimes code depends upon the constant variables declared in OptimizationLevel (e.g. see llvm#156802), which then requires them to add a dependency on the Passes directory. Given that code is much more likely to depend upon Support than Passes I believe it makes sense to move OptimizationLevel to Support. The Passes component already depends upon Support.
a28f0fc
to
38a6525
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This OptimizationClass class is pretty trivial. I think it makes sense to move OptimizationLevel
to Support to avoid an unnecessary dependence on Passes
when needing to reference OptimizationLevel::O0
, for example.
I always thought of ADT and Support libraries as being useful for other projects, OptimizationLevel seems too llvm-specific to me. Could CodeGen directory be a better choice? Assuming this enum is not used by the middle end, that would create a circular dependency otherwise. |
And what's wrong with Passes anyway?
This doesn't look a very strong point to me. We could say this about nearly everything and move it all to Support :) |
That would be nice, and I'd love to move libSupport at the top-level (only the pieces that matches the "generic aspect" of it), but the reality today is that beyond filesystem abstractions, thread pool, and other generic things, there are also things like |
Perhaps the TargetParser directory is more suitable for them. Not sure what they are used for. |
See #156802 for a motivation for this change. If anybody wants to reference a constant variable from OptimizationLevel (OptimizationLevel::O0, for example) they have to add the extra Passes dependency, which seems a bit much for one variable. It felt like there wasn't really an obvious reason why OptimizationLevel had to live in the Passes directory either, and since most passes seem to require the Support directory anyway I thought it made sense to move it there? Having said that, I'm happy moving it somewhere else that isn't Passes if there are good suggestions! |
It's closer but not quite right. I think there probably should be some kind of ABI-information for this sort of stuff. TargetParser is more specific to frontend-backend interactions |
|
As an alternative: can this be just made a header-only implementation? |
Sometimes code depends upon the constant variables declared in OptimizationLevel (e.g. see #156802), which then requires them to add a dependency on the Passes directory. Given that code is much more likely to depend upon Support than Passes I believe it makes sense to move OptimizationLevel to Support. The Passes component already depends upon Support.
This PR was inspired by a suggestion from @sdesmalen-arm!