Skip to content

Commit f5d3fce

Browse files
Fix "Option 'o' registered more than once!" for merge-module-summary
1 parent 74389af commit f5d3fce

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

include/swift/Option/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace options {
3939
SupplementaryOutput = (1 << 14),
4040
SwiftAPIExtractOption = (1 << 15),
4141
SwiftSymbolGraphExtractOption = (1 << 16),
42+
SwiftMergeModuleSummaryOption = (1 << 17),
4243
};
4344

4445
enum ID {

include/swift/Option/Options.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def SwiftAPIExtractOption : OptionFlag;
6161
// The option should be accepted by swift-symbolgraph-extract.
6262
def SwiftSymbolGraphExtractOption : OptionFlag;
6363

64+
def SwiftMergeModuleSummaryOption : OptionFlag;
65+
6466
/////////
6567
// Options
6668

@@ -177,6 +179,7 @@ def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
177179
def help : Flag<["-", "--"], "help">,
178180
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
179181
SwiftIndentOption, SwiftAPIExtractOption,
182+
SwiftMergeModuleSummaryOption,
180183
SwiftSymbolGraphExtractOption]>,
181184
HelpText<"Display available options">;
182185
def h : Flag<["-"], "h">, Alias<help>;
@@ -200,6 +203,7 @@ def _DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>,
200203
def o : JoinedOrSeparate<["-"], "o">,
201204
Flags<[FrontendOption, AutolinkExtractOption, ModuleWrapOption,
202205
NoInteractiveOption, SwiftIndentOption, ArgumentIsPath,
206+
SwiftMergeModuleSummaryOption,
203207
SwiftAPIExtractOption]>,
204208
HelpText<"Write output to <file>">, MetaVarName<"<file>">;
205209

@@ -1043,7 +1047,7 @@ def Xclang_linker : Separate<["-"], "Xclang-linker">, Flags<[HelpHidden]>,
10431047
MetaVarName<"<arg>">, HelpText<"Pass <arg> to Clang when it is use for linking.">;
10441048

10451049
def Xllvm : Separate<["-"], "Xllvm">,
1046-
Flags<[FrontendOption, HelpHidden]>,
1050+
Flags<[FrontendOption, HelpHidden, SwiftMergeModuleSummaryOption]>,
10471051
MetaVarName<"<arg>">, HelpText<"Pass <arg> to LLVM.">;
10481052

10491053
def resource_dir : Separate<["-"], "resource-dir">,

test/LTO/module_summary_generic_type_ref.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-sib -emit-module-summary-path %t/default_wt.swiftmodule.summary -module-name default_wt -Xllvm -module-summary-embed-debug-name %s
3-
// RUN: %swift_frontend_plain -merge-module-summary %t/default_wt.swiftmodule.summary -module-summary-embed-debug-name -o %t/default_wt.swiftmodule.merged-summary
3+
// RUN: %swift_frontend_plain -merge-module-summary %t/default_wt.swiftmodule.summary -Xllvm -module-summary-embed-debug-name -o %t/default_wt.swiftmodule.merged-summary
44
// RUN: %swift-module-summary-test --to-yaml %t/default_wt.swiftmodule.merged-summary -o %t/default_wt.merged-summary.yaml
55

66
// Ensure that optimizer won't eliminate PrimitiveSequenceType.getPrimitiveSequence

tools/driver/cross_module_opt_main.cpp

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,48 @@ using namespace llvm::opt;
2626
using namespace swift;
2727
using namespace modulesummary;
2828

29+
class MergeModuleSummaryInvocation {
30+
public:
31+
std::string OutputFilename;
32+
std::vector<std::string> InputFilenames;
33+
34+
bool parseArgs(ArrayRef<const char *> Args, DiagnosticEngine &Diags) {
35+
using namespace options;
36+
37+
std::unique_ptr<llvm::opt::OptTable> Table = createSwiftOptTable();
38+
unsigned MissingIndex;
39+
unsigned MissingCount;
40+
llvm::opt::InputArgList ParsedArgs =
41+
Table->ParseArgs(Args, MissingIndex, MissingCount, SwiftMergeModuleSummaryOption);
42+
43+
if (MissingCount) {
44+
Diags.diagnose(SourceLoc(), diag::error_missing_arg_value,
45+
ParsedArgs.getArgString(MissingIndex), MissingCount);
46+
return true;
47+
}
48+
49+
for (const Arg *A : ParsedArgs.filtered(OPT_INPUT)) {
50+
InputFilenames.push_back(A->getValue());
51+
}
52+
53+
if (const Arg *A = ParsedArgs.getLastArg(OPT_o)) {
54+
OutputFilename = A->getValue();
55+
}
56+
57+
std::vector<const char *> LLVMArgs {""};
58+
for (const Arg *A : ParsedArgs.filtered(OPT_Xllvm)) {
59+
LLVMArgs.push_back(A->getValue());
60+
}
61+
62+
llvm::cl::ParseCommandLineOptions(LLVMArgs.size(), LLVMArgs.data(), "");
63+
return false;
64+
}
65+
};
66+
2967
static llvm::cl::opt<std::string>
3068
LTOPrintLiveTrace("lto-print-live-trace", llvm::cl::init(""),
3169
llvm::cl::desc("Print liveness trace for the symbol"));
3270

33-
static llvm::cl::list<std::string>
34-
InputFilenames(llvm::cl::Positional, llvm::cl::desc("[input files...]"));
35-
static llvm::cl::opt<std::string>
36-
OutputFilename("o", llvm::cl::desc("output filename"));
37-
3871
static llvm::DenseSet<GUID> computePreservedGUIDs(ModuleSummaryIndex *summary) {
3972
llvm::DenseSet<GUID> Set(1);
4073
for (auto FI = summary->functions_begin(), FE = summary->functions_end();
@@ -239,21 +272,24 @@ int cross_module_opt_main(ArrayRef<const char *> Args, const char *Argv0,
239272
void *MainAddr) {
240273
INITIALIZE_LLVM();
241274

242-
llvm::cl::ParseCommandLineOptions(Args.size(), Args.data(), "Swift LTO\n");
243-
244275
CompilerInstance Instance;
245276
PrintingDiagnosticConsumer PDC;
246277
Instance.addDiagnosticConsumer(&PDC);
247278

248-
if (InputFilenames.empty()) {
279+
MergeModuleSummaryInvocation Invocation;
280+
if (Invocation.parseArgs(Args, Instance.getDiags())) {
281+
return true;
282+
}
283+
284+
if (Invocation.InputFilenames.empty()) {
249285
Instance.getDiags().diagnose(SourceLoc(),
250286
diag::error_mode_requires_an_input_file);
251287
return 1;
252288
}
253289

254290
auto TheSummary = std::make_unique<ModuleSummaryIndex>();
255291

256-
for (auto Filename : InputFilenames) {
292+
for (auto Filename : Invocation.InputFilenames) {
257293
LLVM_DEBUG(llvm::dbgs() << "Loading module summary " << Filename << "\n");
258294
auto ErrOrBuf = llvm::MemoryBuffer::getFile(Filename);
259295
if (!ErrOrBuf) {
@@ -276,6 +312,6 @@ int cross_module_opt_main(ArrayRef<const char *> Args, const char *Argv0,
276312
markDeadSymbols(*TheSummary.get(), PreservedGUIDs);
277313

278314
modulesummary::writeModuleSummaryIndex(*TheSummary, Instance.getDiags(),
279-
OutputFilename);
315+
Invocation.OutputFilename);
280316
return 0;
281317
}

0 commit comments

Comments
 (0)