-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
[NewPM] Add pass options for InternalizePass to preserve GVs (reland) #92383
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…#91334) This PR adds a string interface to `InternalizePass`' `MustPreserveGV` option, which is a callback function to indicate if a GV is not to be internalized. This is for use in LLVM.jl, the Julia wrapper for LLVM, which uses the C API and is thus required to use the PassBuilder string API for building NewPM pipelines.
@llvm/pr-subscribers-llvm-transforms Author: Tim Besard (maleadt) ChangesReland of #91334, which broke the gcc7 buildbot and was reverted in #92321. cc @joker-eph Full diff: https://github.com/llvm/llvm-project/pull/92383.diff 3 Files Affected:
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index e4131706aba01..734ca4d5deec9 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1142,6 +1142,24 @@ Expected<GlobalMergeOptions> parseGlobalMergeOptions(StringRef Params) {
return Result;
}
+Expected<SmallVector<std::string, 0>> parseInternalizeGVs(StringRef Params) {
+ SmallVector<std::string, 1> PreservedGVs;
+ while (!Params.empty()) {
+ StringRef ParamName;
+ std::tie(ParamName, Params) = Params.split(';');
+
+ if (ParamName.consume_front("preserve-gv=")) {
+ PreservedGVs.push_back(ParamName.str());
+ } else {
+ return make_error<StringError>(
+ formatv("invalid Internalize pass parameter '{0}' ", ParamName).str(),
+ inconvertibleErrorCode());
+ }
+ }
+
+ return Expected<SmallVector<std::string, 0>>(std::move(PreservedGVs));
+}
+
} // namespace
/// Tests whether a pass name starts with a valid prefix for a default pipeline
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index e5ce6cb7da649..50682ca4970f1 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -78,7 +78,6 @@ MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
MODULE_PASS("instrorderfile", InstrOrderFilePass())
MODULE_PASS("instrprof", InstrProfilingLoweringPass())
MODULE_PASS("ctx-instr-lower", PGOCtxProfLoweringPass())
-MODULE_PASS("internalize", InternalizePass())
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
MODULE_PASS("iroutliner", IROutlinerPass())
MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
@@ -175,6 +174,20 @@ MODULE_PASS_WITH_PARAMS(
"hwasan", "HWAddressSanitizerPass",
[](HWAddressSanitizerOptions Opts) { return HWAddressSanitizerPass(Opts); },
parseHWASanPassOptions, "kernel;recover")
+MODULE_PASS_WITH_PARAMS(
+ "internalize", "InternalizePass",
+ [](SmallVector<std::string, 0> PreservedGVs) {
+ if (PreservedGVs.empty())
+ return InternalizePass();
+ auto MustPreserveGV = [=](const GlobalValue &GV) {
+ for (auto &PreservedGV : PreservedGVs)
+ if (GV.getName() == PreservedGV)
+ return true;
+ return false;
+ };
+ return InternalizePass(MustPreserveGV);
+ },
+ parseInternalizeGVs, "preserve-gv=GV")
MODULE_PASS_WITH_PARAMS(
"ipsccp", "IPSCCPPass", [](IPSCCPOptions Opts) { return IPSCCPPass(Opts); },
parseIPSCCPOptions, "no-func-spec;func-spec")
diff --git a/llvm/test/Transforms/Internalize/lists.ll b/llvm/test/Transforms/Internalize/lists.ll
index df408f906b780..83dad03d75eae 100644
--- a/llvm/test/Transforms/Internalize/lists.ll
+++ b/llvm/test/Transforms/Internalize/lists.ll
@@ -13,6 +13,11 @@
; -file and -list options should be merged, the apifile contains foo and j
; RUN: opt < %s -passes=internalize -internalize-public-api-list bar -internalize-public-api-file %S/apifile -S | FileCheck --check-prefix=FOO_J_AND_BAR %s
+; specifying through pass builder option
+; RUN: opt < %s -passes='internalize<preserve-gv=foo;preserve-gv=j>' -S | FileCheck --check-prefix=FOO_AND_J %s
+; RUN: opt < %s -passes='internalize<preserve-gv=foo;preserve-gv=bar>' -S | FileCheck --check-prefix=FOO_AND_BAR %s
+; RUN: opt < %s -passes='internalize<preserve-gv=foo;preserve-gv=j;preserve-gv=bar>' -S | FileCheck --check-prefix=FOO_J_AND_BAR %s
+
; ALL: @i = internal global
; FOO_AND_J: @i = internal global
; FOO_AND_BAR: @i = internal global
|
aeubanks
approved these changes
May 16, 2024
maleadt
added a commit
to JuliaLang/llvm-project
that referenced
this pull request
May 17, 2024
maleadt
added a commit
to JuliaLang/llvm-project
that referenced
this pull request
May 17, 2024
This was referenced May 17, 2024
giordano
pushed a commit
to JuliaLang/llvm-project
that referenced
this pull request
Jun 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reland of #91334, which broke the gcc7 buildbot and was reverted in #92321.
Work around the failure by being explicit about returning an
Expected
.cc @joker-eph