Skip to content

[NewPM] Add pass options for InternalizePass to preserve GVs (reland) #92383

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 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion llvm/lib/Passes/PassRegistry.def
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions llvm/test/Transforms/Internalize/lists.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading