• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
getCppVariableName() const19 StringRef PassOption::getCppVariableName() const {
20   return def->getValueAsString("cppName");
21 }
22 
getArgument() const23 StringRef PassOption::getArgument() const {
24   return def->getValueAsString("argument");
25 }
26 
getType() const27 StringRef PassOption::getType() const { return def->getValueAsString("type"); }
28 
getDefaultValue() const29 Optional<StringRef> PassOption::getDefaultValue() const {
30   StringRef defaultVal = def->getValueAsString("defaultValue");
31   return defaultVal.empty() ? Optional<StringRef>() : defaultVal;
32 }
33 
getDescription() const34 StringRef PassOption::getDescription() const {
35   return def->getValueAsString("description");
36 }
37 
getAdditionalFlags() const38 Optional<StringRef> PassOption::getAdditionalFlags() const {
39   StringRef additionalFlags = def->getValueAsString("additionalOptFlags");
40   return additionalFlags.empty() ? Optional<StringRef>() : additionalFlags;
41 }
42 
isListOption() const43 bool PassOption::isListOption() const {
44   return def->isSubClassOf("ListOption");
45 }
46 
47 //===----------------------------------------------------------------------===//
48 // PassStatistic
49 //===----------------------------------------------------------------------===//
50 
getCppVariableName() const51 StringRef PassStatistic::getCppVariableName() const {
52   return def->getValueAsString("cppName");
53 }
54 
getName() const55 StringRef PassStatistic::getName() const {
56   return def->getValueAsString("name");
57 }
58 
getDescription() const59 StringRef PassStatistic::getDescription() const {
60   return def->getValueAsString("description");
61 }
62 
63 //===----------------------------------------------------------------------===//
64 // Pass
65 //===----------------------------------------------------------------------===//
66 
Pass(const llvm::Record * def)67 Pass::Pass(const llvm::Record *def) : def(def) {
68   for (auto *init : def->getValueAsListOfDefs("options"))
69     options.push_back(PassOption(init));
70   for (auto *init : def->getValueAsListOfDefs("statistics"))
71     statistics.push_back(PassStatistic(init));
72   for (StringRef dialect : def->getValueAsListOfStrings("dependentDialects"))
73     dependentDialects.push_back(dialect);
74 }
75 
getArgument() const76 StringRef Pass::getArgument() const {
77   return def->getValueAsString("argument");
78 }
79 
getBaseClass() const80 StringRef Pass::getBaseClass() const {
81   return def->getValueAsString("baseClass");
82 }
83 
getSummary() const84 StringRef Pass::getSummary() const { return def->getValueAsString("summary"); }
85 
getDescription() const86 StringRef Pass::getDescription() const {
87   return def->getValueAsString("description");
88 }
89 
getConstructor() const90 StringRef Pass::getConstructor() const {
91   return def->getValueAsString("constructor");
92 }
getDependentDialects() const93 ArrayRef<StringRef> Pass::getDependentDialects() const {
94   return dependentDialects;
95 }
96 
getOptions() const97 ArrayRef<PassOption> Pass::getOptions() const { return options; }
98 
getStatistics() const99 ArrayRef<PassStatistic> Pass::getStatistics() const { return statistics; }
100