Skip to content
Prev Previous commit
Next Next commit
Review suggestions.
  • Loading branch information
DirtyHairy committed Jul 15, 2024
commit 807368bedf6c655726e237086bad7d90cbffa76e
4 changes: 2 additions & 2 deletions src/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct PassRegistry {
using Creator = std::function<Pass*()>;

void registerPass(const char* name, const char* description, Creator create);
;

// Register a pass that's used for internal testing. These passes do not show
// up in --help.
void
Expand Down Expand Up @@ -328,7 +328,7 @@ struct PassRunner {

// Add a pass using its name.
void add(std::string passName,
std::optional<std::string> passArg = std::optional<std::string>());
std::optional<std::string> passArg = std::nullopt);

// Add a pass given an instance.
void add(std::unique_ptr<Pass> pass) { doAdd(std::move(pass)); }
Expand Down
15 changes: 5 additions & 10 deletions src/passes/pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void PassRegistry::registerPass(const char* name,
const char* description,
Creator create) {
assert(passInfos.find(name) == passInfos.end());
passInfos[name] = PassInfo(description, create, false);
passInfos[name] = PassInfo(description, create);
}

void PassRegistry::registerTestPass(const char* name,
Expand Down Expand Up @@ -74,13 +74,7 @@ std::vector<std::string> PassRegistry::getRegisteredNames() {
}

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

return false;
return passInfos.count(name) > 0;
}

std::string PassRegistry::getPassDescription(std::string name) {
Expand Down Expand Up @@ -1045,8 +1039,9 @@ bool PassRunner::shouldPreserveDWARF() {
}

bool Pass::hasArgument(const std::string& key) {
return (key == name) ? passArg.has_value()
: getPassOptions().hasArgument(key);
// An argument with the name of the pass is stored on the instance. Other
// arguments are in the global storage.
return key == name ? passArg.has_value() : getPassOptions().hasArgument(key);
}

std::string Pass::getArgument(const std::string& key,
Expand Down
10 changes: 5 additions & 5 deletions src/tools/optimization-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,16 @@ 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) {
for (auto i = passes.rbegin(); i != passes.rend(); i++) {
if (i->name != key) {
continue;
}

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

iPass->argument = value;
i->argument = value;
return;
}

Expand Down