Skip to content

Commit

Permalink
[NewPM] Add pass options for InternalizePass to preserve GVs (reland) (
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored and giordano committed Jun 18, 2024
1 parent 947be24 commit 922424c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
18 changes: 18 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,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 @@ -77,7 +77,6 @@ MODULE_PASS("inliner-wrapper-no-mandatory-first",
MODULE_PASS("insert-gcov-profiling", GCOVProfilerPass())
MODULE_PASS("instrorderfile", InstrOrderFilePass())
MODULE_PASS("instrprof", InstrProfilingLoweringPass())
MODULE_PASS("internalize", InternalizePass())
MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
MODULE_PASS("iroutliner", IROutlinerPass())
MODULE_PASS("jmc-instrumenter", JMCInstrumenterPass())
Expand Down Expand Up @@ -172,6 +171,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

0 comments on commit 922424c

Please sign in to comment.