Skip to content

Commit a12f18b

Browse files
committed
Allow multiple invocations with arguments for all passes, allow --pass-arg only for additional arguments.
1 parent d74f5b1 commit a12f18b

20 files changed

+92
-99
lines changed

src/binaryen-c.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5451,7 +5451,9 @@ void BinaryenModuleRunPasses(BinaryenModuleRef module,
54515451
PassRunner passRunner((Module*)module);
54525452
passRunner.options = globalPassOptions;
54535453
for (BinaryenIndex i = 0; i < numPasses; i++) {
5454-
passRunner.add(passes[i]);
5454+
passRunner.add(passes[i]), globalPassOptions.arguments.count(passes[i]) > 0
5455+
? globalPassOptions.arguments[passes[i]]
5456+
: std::optional<std::string>();
54555457
}
54565458
passRunner.run();
54575459
}
@@ -5696,7 +5698,10 @@ void BinaryenFunctionRunPasses(BinaryenFunctionRef func,
56965698
PassRunner passRunner((Module*)module);
56975699
passRunner.options = globalPassOptions;
56985700
for (BinaryenIndex i = 0; i < numPasses; i++) {
5699-
passRunner.add(passes[i]);
5701+
passRunner.add(passes[i],
5702+
globalPassOptions.arguments.count(passes[i]) > 0
5703+
? globalPassOptions.arguments[passes[i]]
5704+
: std::optional<std::string>());
57005705
}
57015706
passRunner.runOnFunction((Function*)func);
57025707
}

src/pass.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ struct PassRegistry {
3838

3939
using Creator = std::function<Pass*()>;
4040

41-
void registerPass(const char* name,
42-
const char* description,
43-
Creator create,
44-
bool allowMultipleInstancesWithArgs = false);
41+
void registerPass(const char* name, const char* description, Creator create);
4542
;
4643
// Register a pass that's used for internal testing. These passes do not show
4744
// up in --help.
@@ -51,7 +48,6 @@ struct PassRegistry {
5148
std::vector<std::string> getRegisteredNames();
5249
std::string getPassDescription(std::string name);
5350
bool isPassHidden(std::string name);
54-
bool doesPassAllowMultipleInstancesWithArgs(std::string name);
5551

5652
private:
5753
void registerPasses();
@@ -60,14 +56,9 @@ struct PassRegistry {
6056
std::string description;
6157
Creator create;
6258
bool hidden;
63-
bool allowMultipleInstancesWithArgs;
6459
PassInfo() = default;
65-
PassInfo(std::string description,
66-
Creator create,
67-
bool hidden = false,
68-
bool allowMultipleInstancesWithArgs = false)
69-
: description(description), create(create), hidden(hidden),
70-
allowMultipleInstancesWithArgs(allowMultipleInstancesWithArgs) {}
60+
PassInfo(std::string description, Creator create, bool hidden = false)
61+
: description(description), create(create), hidden(hidden) {}
7162
};
7263
std::map<std::string, PassInfo> passInfos;
7364
};
@@ -495,7 +486,7 @@ class Pass {
495486
// to imports must override this to return true.
496487
virtual bool addsEffects() { return false; }
497488

498-
void setPassArg(std::string value) { passArg = value; }
489+
void setPassArg(const std::string& value) { passArg = value; }
499490

500491
std::string name;
501492

@@ -508,6 +499,12 @@ class Pass {
508499
PassOptions& getPassOptions() { return runner->options; }
509500

510501
protected:
502+
bool hasArgument(const std::string& key);
503+
std::string getArgument(const std::string& key,
504+
const std::string& errorTextIfMissing);
505+
std::string getArgumentOrDefault(const std::string& key,
506+
const std::string& defaultValue);
507+
511508
std::optional<std::string> passArg;
512509

513510
Pass() = default;

src/passes/Asyncify.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,54 +1608,49 @@ struct Asyncify : public Pass {
16081608
bool addsEffects() override { return true; }
16091609

16101610
void run(Module* module) override {
1611-
auto& options = getPassOptions();
1612-
bool optimize = options.optimizeLevel > 0;
1611+
bool optimize = getPassOptions().optimizeLevel > 0;
16131612

16141613
// Find which things can change the state.
16151614
auto stateChangingImports = String::trim(read_possible_response_file(
1616-
options.getArgumentOrDefault("asyncify-imports", "")));
1617-
auto ignoreImports =
1618-
options.getArgumentOrDefault("asyncify-ignore-imports", "");
1615+
getArgumentOrDefault("asyncify-imports", "")));
1616+
auto ignoreImports = getArgumentOrDefault("asyncify-ignore-imports", "");
16191617
bool allImportsCanChangeState =
16201618
stateChangingImports == "" && ignoreImports == "";
16211619
String::Split listedImports(stateChangingImports,
16221620
String::Split::NewLineOr(","));
16231621
// canIndirectChangeState is the default. asyncify-ignore-indirect sets it
16241622
// to false.
1625-
auto canIndirectChangeState =
1626-
!options.hasArgument("asyncify-ignore-indirect");
1623+
auto canIndirectChangeState = !hasArgument("asyncify-ignore-indirect");
16271624
std::string removeListInput =
1628-
options.getArgumentOrDefault("asyncify-removelist", "");
1625+
getArgumentOrDefault("asyncify-removelist", "");
16291626
if (removeListInput.empty()) {
16301627
// Support old name for now to avoid immediate breakage TODO remove
1631-
removeListInput = options.getArgumentOrDefault("asyncify-blacklist", "");
1628+
removeListInput = getArgumentOrDefault("asyncify-blacklist", "");
16321629
}
16331630
String::Split removeList(
16341631
String::trim(read_possible_response_file(removeListInput)),
16351632
String::Split::NewLineOr(","));
1636-
String::Split addList(
1637-
String::trim(read_possible_response_file(
1638-
options.getArgumentOrDefault("asyncify-addlist", ""))),
1639-
String::Split::NewLineOr(","));
1640-
std::string onlyListInput =
1641-
options.getArgumentOrDefault("asyncify-onlylist", "");
1633+
String::Split addList(String::trim(read_possible_response_file(
1634+
getArgumentOrDefault("asyncify-addlist", ""))),
1635+
String::Split::NewLineOr(","));
1636+
std::string onlyListInput = getArgumentOrDefault("asyncify-onlylist", "");
16421637
if (onlyListInput.empty()) {
16431638
// Support old name for now to avoid immediate breakage TODO remove
1644-
onlyListInput = options.getArgumentOrDefault("asyncify-whitelist", "");
1639+
onlyListInput = getArgumentOrDefault("asyncify-whitelist", "");
16451640
}
16461641
String::Split onlyList(
16471642
String::trim(read_possible_response_file(onlyListInput)),
16481643
String::Split::NewLineOr(","));
1649-
auto asserts = options.hasArgument("asyncify-asserts");
1650-
auto verbose = options.hasArgument("asyncify-verbose");
1651-
auto relocatable = options.hasArgument("asyncify-relocatable");
1652-
auto secondaryMemory = options.hasArgument("asyncify-in-secondary-memory");
1653-
auto propagateAddList = options.hasArgument("asyncify-propagate-addlist");
1644+
auto asserts = hasArgument("asyncify-asserts");
1645+
auto verbose = hasArgument("asyncify-verbose");
1646+
auto relocatable = hasArgument("asyncify-relocatable");
1647+
auto secondaryMemory = hasArgument("asyncify-in-secondary-memory");
1648+
auto propagateAddList = hasArgument("asyncify-propagate-addlist");
16541649

16551650
// Ensure there is a memory, as we need it.
16561651
if (secondaryMemory) {
16571652
auto secondaryMemorySizeString =
1658-
options.getArgumentOrDefault("asyncify-secondary-memory-size", "1");
1653+
getArgumentOrDefault("asyncify-secondary-memory-size", "1");
16591654
Address secondaryMemorySize = std::stoi(secondaryMemorySizeString);
16601655
asyncifyMemory = createSecondaryMemory(module, secondaryMemorySize);
16611656
} else {

src/passes/Directize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct Directize : public Pass {
203203

204204
// TODO: consider a per-table option here
205205
auto initialContentsImmutable =
206-
getPassOptions().hasArgument("directize-initial-contents-immutable");
206+
hasArgument("directize-initial-contents-immutable");
207207

208208
// Set up the initial info.
209209
TableInfoMap tables;

src/passes/ExtractFunction.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct ExtractFunction : public Pass {
6262
bool addsEffects() override { return true; }
6363

6464
void run(Module* module) override {
65-
Name name = getPassOptions().getArgument(
65+
Name name = getArgument(
6666
"extract-function",
6767
"ExtractFunction usage: wasm-opt --extract-function=FUNCTION_NAME");
6868
extract(getPassRunner(), module, name);
@@ -74,10 +74,9 @@ struct ExtractFunctionIndex : public Pass {
7474
bool addsEffects() override { return true; }
7575

7676
void run(Module* module) override {
77-
std::string index =
78-
getPassOptions().getArgument("extract-function-index",
79-
"ExtractFunctionIndex usage: wasm-opt "
80-
"--extract-function-index=FUNCTION_INDEX");
77+
std::string index = getArgument("extract-function-index",
78+
"ExtractFunctionIndex usage: wasm-opt "
79+
"--extract-function-index=FUNCTION_INDEX");
8180
for (char c : index) {
8281
if (!std::isdigit(c)) {
8382
Fatal() << "Expected numeric function index";

src/passes/FuncCastEmulation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ struct FuncCastEmulation : public Pass {
157157
bool addsEffects() override { return true; }
158158

159159
void run(Module* module) override {
160-
Index numParams = std::stoul(
161-
getPassOptions().getArgumentOrDefault("max-func-params", "16"));
160+
Index numParams = std::stoul(getArgumentOrDefault("max-func-params", "16"));
162161
// we just need the one ABI function type for all indirect calls
163162
HeapType ABIType(
164163
Signature(Type(std::vector<Type>(numParams, Type::i64)), Type::i64));

src/passes/JSPI.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,17 @@ struct JSPI : public Pass {
8383
void run(Module* module) override {
8484
Builder builder(*module);
8585

86-
auto& options = getPassOptions();
8786
// Find which imports can suspend.
88-
auto stateChangingImports = String::trim(read_possible_response_file(
89-
options.getArgumentOrDefault("jspi-imports", "")));
87+
auto stateChangingImports = String::trim(
88+
read_possible_response_file(getArgumentOrDefault("jspi-imports", "")));
9089
String::Split listedImports(stateChangingImports, ",");
9190

9291
// Find which exports should create a promise.
93-
auto stateChangingExports = String::trim(read_possible_response_file(
94-
options.getArgumentOrDefault("jspi-exports", "")));
92+
auto stateChangingExports = String::trim(
93+
read_possible_response_file(getArgumentOrDefault("jspi-exports", "")));
9594
String::Split listedExports(stateChangingExports, ",");
9695

97-
bool wasmSplit = options.hasArgument("jspi-split-module");
96+
bool wasmSplit = hasArgument("jspi-split-module");
9897
if (wasmSplit) {
9998
// Make an import for the load secondary module function so a JSPI wrapper
10099
// version will be created.

src/passes/LegalizeJSInterface.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ struct LegalizeJSInterface : public Pass {
6464
setTempRet0 = nullptr;
6565
getTempRet0 = nullptr;
6666
auto exportOriginals =
67-
getPassOptions().hasArgument("legalize-js-interface-export-originals");
68-
exportedHelpers =
69-
getPassOptions().hasArgument("legalize-js-interface-exported-helpers");
67+
hasArgument("legalize-js-interface-export-originals");
68+
exportedHelpers = hasArgument("legalize-js-interface-exported-helpers");
7069
// for each illegal export, we must export a legalized stub instead
7170
std::vector<std::unique_ptr<Export>> newExports;
7271
for (auto& ex : module->exports) {

src/passes/LogExecution.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ struct LogExecution : public WalkerPass<PostWalker<LogExecution>> {
4646
bool addsEffects() override { return true; }
4747

4848
void run(Module* module) override {
49-
auto& options = getPassOptions();
50-
loggerModule = options.getArgumentOrDefault("log-execution", "");
49+
loggerModule = getArgumentOrDefault("log-execution", "");
5150
super::run(module);
5251
}
5352

src/passes/NoInline.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ struct NoInline : public Pass {
4949

5050
void run(Module* module) override {
5151
std::string pattern =
52-
passArg ? *passArg
53-
: getPassOptions().getArgument(
54-
name, "Usage usage: wasm-opt --" + name + "=WILDCARD");
52+
getArgument(name, "Usage usage: wasm-opt --" + name + "=WILDCARD");
5553

5654
for (auto& func : module->functions) {
5755
if (!String::wildcardMatch(pattern, func->name.toString())) {

0 commit comments

Comments
 (0)