Skip to content

Commit e6334a3

Browse files
committed
Support setting pass main argument again with --pass-arg
1 parent 01a3165 commit e6334a3

File tree

6 files changed

+43
-2
lines changed

6 files changed

+43
-2
lines changed

src/pass.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct PassRegistry {
4646
registerTestPass(const char* name, const char* description, Creator create);
4747
std::unique_ptr<Pass> createPass(std::string name);
4848
std::vector<std::string> getRegisteredNames();
49+
bool containsPass(const std::string& name);
4950
std::string getPassDescription(std::string name);
5051
bool isPassHidden(std::string name);
5152

src/passes/pass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ std::vector<std::string> PassRegistry::getRegisteredNames() {
7373
return ret;
7474
}
7575

76+
bool PassRegistry::containsPass(const std::string& name) {
77+
for (auto& [passName, _] : passInfos) {
78+
if (passName == name) {
79+
return true;
80+
}
81+
}
82+
83+
return false;
84+
}
85+
7686
std::string PassRegistry::getPassDescription(std::string name) {
7787
assert(passInfos.find(name) != passInfos.end());
7888
return passInfos[name].description;

src/tools/optimization-options.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,27 @@ struct OptimizationOptions : public ToolOptions {
328328
}
329329
}
330330

331+
void addPassArg(const std::string& key, const std::string& value) override {
332+
for (auto iPass = passes.rbegin(); iPass != passes.rend(); iPass++) {
333+
if (iPass->name != key) {
334+
continue;
335+
}
336+
337+
if (iPass->argument.has_value()) {
338+
Fatal() << iPass->name << " already set to " << *(iPass->argument);
339+
}
340+
341+
iPass->argument = value;
342+
return;
343+
}
344+
345+
if (!PassRegistry::get()->containsPass(key)) {
346+
return ToolOptions::addPassArg(key, value);
347+
}
348+
349+
Fatal() << "can't set " << key << ": pass not enabled";
350+
}
351+
331352
bool runningDefaultOptimizationPasses() {
332353
for (auto& pass : passes) {
333354
if (pass.name == DEFAULT_OPT_PASSES) {

src/tools/tool-options.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ struct ToolOptions : public Options {
139139
key = argument.substr(0, colon);
140140
value = argument.substr(colon + 1);
141141
}
142-
passOptions.arguments[key] = value;
142+
143+
addPassArg(key, value);
143144
})
144145
.add(
145146
"--closed-world",
@@ -213,6 +214,12 @@ struct ToolOptions : public Options {
213214
module.features.disable(disabledFeatures);
214215
}
215216

217+
virtual void addPassArg(const std::string& key, const std::string& value) {
218+
passOptions.arguments[key] = value;
219+
}
220+
221+
virtual ~ToolOptions() = default;
222+
216223
private:
217224
FeatureSet enabledFeatures = FeatureSet::Default;
218225
FeatureSet disabledFeatures = FeatureSet::None;

test/lit/passes/extract-function.wast

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
22
;; RUN: foreach %s %t wasm-opt --extract-function=foo -S -o - | filecheck %s
3+
;; RUN: foreach %s %t wasm-opt --extract-function --pass-arg=extract-function@foo -S -o - | filecheck %s
34
;; RUN: foreach %s %t wasm-opt --extract-function-index=0 -S -o - | filecheck %s
5+
;; RUN: foreach %s %t wasm-opt --extract-function-index --pass-arg=extract-function-index@0 -S -o - | filecheck %s
46

57
(module
68
;; CHECK: (type $0 (func))

test/passes/set-globals.passes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
set-globals=foo=1337,bar=42
1+
set-globals_pass-arg=set-globals@foo=1337,bar=42

0 commit comments

Comments
 (0)