| 1 | //===- Pass.cpp - Pass related classes ------------------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "mlir/TableGen/Pass.h" |
| 10 | #include "llvm/TableGen/Record.h" |
| 11 | |
| 12 | using namespace mlir; |
| 13 | using namespace mlir::tblgen; |
| 14 | |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | // PassOption |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | StringRef PassOption::getCppVariableName() const { |
| 20 | return def->getValueAsString(FieldName: "cppName"); |
| 21 | } |
| 22 | |
| 23 | StringRef PassOption::getArgument() const { |
| 24 | return def->getValueAsString(FieldName: "argument"); |
| 25 | } |
| 26 | |
| 27 | StringRef PassOption::getType() const { return def->getValueAsString(FieldName: "type"); } |
| 28 | |
| 29 | std::optional<StringRef> PassOption::getDefaultValue() const { |
| 30 | StringRef defaultVal = def->getValueAsString(FieldName: "defaultValue"); |
| 31 | return defaultVal.empty() ? std::optional<StringRef>() : defaultVal; |
| 32 | } |
| 33 | |
| 34 | StringRef PassOption::getDescription() const { |
| 35 | return def->getValueAsString(FieldName: "description"); |
| 36 | } |
| 37 | |
| 38 | std::optional<StringRef> PassOption::getAdditionalFlags() const { |
| 39 | StringRef additionalFlags = def->getValueAsString(FieldName: "additionalOptFlags"); |
| 40 | return additionalFlags.empty() ? std::optional<StringRef>() : additionalFlags; |
| 41 | } |
| 42 | |
| 43 | bool PassOption::isListOption() const { |
| 44 | return def->isSubClassOf(Name: "ListOption"); |
| 45 | } |
| 46 | |
| 47 | //===----------------------------------------------------------------------===// |
| 48 | // PassStatistic |
| 49 | //===----------------------------------------------------------------------===// |
| 50 | |
| 51 | StringRef PassStatistic::getCppVariableName() const { |
| 52 | return def->getValueAsString(FieldName: "cppName"); |
| 53 | } |
| 54 | |
| 55 | StringRef PassStatistic::getName() const { |
| 56 | return def->getValueAsString(FieldName: "name"); |
| 57 | } |
| 58 | |
| 59 | StringRef PassStatistic::getDescription() const { |
| 60 | return def->getValueAsString(FieldName: "description"); |
| 61 | } |
| 62 | |
| 63 | //===----------------------------------------------------------------------===// |
| 64 | // Pass |
| 65 | //===----------------------------------------------------------------------===// |
| 66 | |
| 67 | Pass::Pass(const llvm::Record *def) : def(def) { |
| 68 | for (auto *init : def->getValueAsListOfDefs(FieldName: "options")) |
| 69 | options.emplace_back(args&: init); |
| 70 | for (auto *init : def->getValueAsListOfDefs(FieldName: "statistics")) |
| 71 | statistics.emplace_back(args&: init); |
| 72 | for (StringRef dialect : def->getValueAsListOfStrings(FieldName: "dependentDialects")) |
| 73 | dependentDialects.push_back(x: dialect); |
| 74 | } |
| 75 | |
| 76 | StringRef Pass::getArgument() const { |
| 77 | return def->getValueAsString(FieldName: "argument"); |
| 78 | } |
| 79 | |
| 80 | StringRef Pass::getBaseClass() const { |
| 81 | return def->getValueAsString(FieldName: "baseClass"); |
| 82 | } |
| 83 | |
| 84 | StringRef Pass::getSummary() const { return def->getValueAsString(FieldName: "summary"); } |
| 85 | |
| 86 | StringRef Pass::getDescription() const { |
| 87 | return def->getValueAsString(FieldName: "description"); |
| 88 | } |
| 89 | |
| 90 | StringRef Pass::getConstructor() const { |
| 91 | return def->getValueAsString(FieldName: "constructor"); |
| 92 | } |
| 93 | |
| 94 | ArrayRef<StringRef> Pass::getDependentDialects() const { |
| 95 | return dependentDialects; |
| 96 | } |
| 97 | |
| 98 | ArrayRef<PassOption> Pass::getOptions() const { return options; } |
| 99 | |
| 100 | ArrayRef<PassStatistic> Pass::getStatistics() const { return statistics; } |
| 101 |
