This revision adds support for generating utilities for passes such as options/statistics/etc. that can be inferred from the tablegen definition. This removes additional boilerplate from the pass, and also makes it easier to remove the reliance on the pass registry to provide certain things(e.g. the pass argument). Differential Revision: https://reviews.llvm.org/D76659
91 lines
2.8 KiB
C++
91 lines
2.8 KiB
C++
//===- Pass.cpp - Pass related classes ------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/TableGen/Pass.h"
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::tblgen;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// PassOption
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
StringRef PassOption::getCppVariableName() const {
|
|
return def->getValueAsString("cppName");
|
|
}
|
|
|
|
StringRef PassOption::getArgument() const {
|
|
return def->getValueAsString("argument");
|
|
}
|
|
|
|
StringRef PassOption::getType() const { return def->getValueAsString("type"); }
|
|
|
|
Optional<StringRef> PassOption::getDefaultValue() const {
|
|
StringRef defaultVal = def->getValueAsString("defaultValue");
|
|
return defaultVal.empty() ? Optional<StringRef>() : defaultVal;
|
|
}
|
|
|
|
StringRef PassOption::getDescription() const {
|
|
return def->getValueAsString("description");
|
|
}
|
|
|
|
Optional<StringRef> PassOption::getAdditionalFlags() const {
|
|
StringRef additionalFlags = def->getValueAsString("additionalOptFlags");
|
|
return additionalFlags.empty() ? Optional<StringRef>() : additionalFlags;
|
|
}
|
|
|
|
bool PassOption::isListOption() const {
|
|
return def->isSubClassOf("ListOption");
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// PassStatistic
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
StringRef PassStatistic::getCppVariableName() const {
|
|
return def->getValueAsString("cppName");
|
|
}
|
|
|
|
StringRef PassStatistic::getName() const {
|
|
return def->getValueAsString("name");
|
|
}
|
|
|
|
StringRef PassStatistic::getDescription() const {
|
|
return def->getValueAsString("description");
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Pass
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
Pass::Pass(const llvm::Record *def) : def(def) {
|
|
for (auto *init : def->getValueAsListOfDefs("options"))
|
|
options.push_back(PassOption(init));
|
|
for (auto *init : def->getValueAsListOfDefs("statistics"))
|
|
statistics.push_back(PassStatistic(init));
|
|
}
|
|
|
|
StringRef Pass::getArgument() const {
|
|
return def->getValueAsString("argument");
|
|
}
|
|
|
|
StringRef Pass::getSummary() const { return def->getValueAsString("summary"); }
|
|
|
|
StringRef Pass::getDescription() const {
|
|
return def->getValueAsString("description");
|
|
}
|
|
|
|
StringRef Pass::getConstructor() const {
|
|
return def->getValueAsString("constructor");
|
|
}
|
|
|
|
ArrayRef<PassOption> Pass::getOptions() const { return options; }
|
|
|
|
ArrayRef<PassStatistic> Pass::getStatistics() const { return statistics; }
|