Skip to content

Commit

Permalink
Support setting pass main argument again with --pass-arg
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtyHairy committed Jun 29, 2024
1 parent 01a3165 commit e6334a3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct PassRegistry {
registerTestPass(const char* name, const char* description, Creator create);
std::unique_ptr<Pass> createPass(std::string name);
std::vector<std::string> getRegisteredNames();
bool containsPass(const std::string& name);
std::string getPassDescription(std::string name);
bool isPassHidden(std::string name);

Expand Down
10 changes: 10 additions & 0 deletions src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ std::vector<std::string> PassRegistry::getRegisteredNames() {
return ret;
}

bool PassRegistry::containsPass(const std::string& name) {
for (auto& [passName, _] : passInfos) {
if (passName == name) {
return true;
}
}

return false;
}

std::string PassRegistry::getPassDescription(std::string name) {
assert(passInfos.find(name) != passInfos.end());
return passInfos[name].description;
Expand Down
21 changes: 21 additions & 0 deletions src/tools/optimization-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,27 @@ struct OptimizationOptions : public ToolOptions {
}
}

void addPassArg(const std::string& key, const std::string& value) override {
for (auto iPass = passes.rbegin(); iPass != passes.rend(); iPass++) {
if (iPass->name != key) {
continue;
}

if (iPass->argument.has_value()) {
Fatal() << iPass->name << " already set to " << *(iPass->argument);
}

iPass->argument = value;
return;
}

if (!PassRegistry::get()->containsPass(key)) {
return ToolOptions::addPassArg(key, value);
}

Fatal() << "can't set " << key << ": pass not enabled";
}

bool runningDefaultOptimizationPasses() {
for (auto& pass : passes) {
if (pass.name == DEFAULT_OPT_PASSES) {
Expand Down
9 changes: 8 additions & 1 deletion src/tools/tool-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ struct ToolOptions : public Options {
key = argument.substr(0, colon);
value = argument.substr(colon + 1);
}
passOptions.arguments[key] = value;

addPassArg(key, value);
})
.add(
"--closed-world",
Expand Down Expand Up @@ -213,6 +214,12 @@ struct ToolOptions : public Options {
module.features.disable(disabledFeatures);
}

virtual void addPassArg(const std::string& key, const std::string& value) {
passOptions.arguments[key] = value;
}

virtual ~ToolOptions() = default;

private:
FeatureSet enabledFeatures = FeatureSet::Default;
FeatureSet disabledFeatures = FeatureSet::None;
Expand Down
2 changes: 2 additions & 0 deletions test/lit/passes/extract-function.wast
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt --extract-function=foo -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --extract-function --pass-arg=extract-function@foo -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --extract-function-index=0 -S -o - | filecheck %s
;; RUN: foreach %s %t wasm-opt --extract-function-index --pass-arg=extract-function-index@0 -S -o - | filecheck %s

(module
;; CHECK: (type $0 (func))
Expand Down
2 changes: 1 addition & 1 deletion test/passes/set-globals.passes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set-globals=foo=1337,bar=42
set-globals_pass-arg=set-globals@foo=1337,bar=42

0 comments on commit e6334a3

Please sign in to comment.