summaryrefslogtreecommitdiffstats
path: root/mlir/lib/TableGen
diff options
context:
space:
mode:
authorLei Zhang <antiagainst@google.com>2019-07-01 05:26:14 -0700
committerjpienaar <jpienaar@google.com>2019-07-01 09:55:47 -0700
commit9dd182e0fa3aeb178d274dc0d64b5891436fba47 (patch)
tree6c7d2bfbe7e6e93801bbeb70d2278d50c151fe86 /mlir/lib/TableGen
parente7f51ad08a309e8175eae2e2b37ebefa5ae0da1c (diff)
downloadbcm5719-llvm-9dd182e0fa3aeb178d274dc0d64b5891436fba47.tar.gz
bcm5719-llvm-9dd182e0fa3aeb178d274dc0d64b5891436fba47.zip
[ODS] Introduce IntEnumAttr
In ODS, right now we use StringAttrs to emulate enum attributes. It is suboptimal if the op actually can and wants to store the enum as a single integer value; we are paying extra cost on storing and comparing the attribute value. This CL introduces a new enum attribute subclass that are backed by IntegerAttr. The downside with IntegerAttr-backed enum attributes is that the assembly form now uses integer values, which is less obvious than the StringAttr-backed ones. However, that can be remedied by defining custom assembly form with the help of the conversion utility functions generated via EnumsGen. Choices are given to the dialect writers to decide which one to use for their enum attributes. PiperOrigin-RevId: 255935542
Diffstat (limited to 'mlir/lib/TableGen')
-rw-r--r--mlir/lib/TableGen/Attribute.cpp15
-rw-r--r--mlir/lib/TableGen/Pattern.cpp2
2 files changed, 13 insertions, 4 deletions
diff --git a/mlir/lib/TableGen/Attribute.cpp b/mlir/lib/TableGen/Attribute.cpp
index 1107048bb88..d292f2bdac6 100644
--- a/mlir/lib/TableGen/Attribute.cpp
+++ b/mlir/lib/TableGen/Attribute.cpp
@@ -136,8 +136,12 @@ StringRef tblgen::ConstantAttr::getConstantValue() const {
tblgen::EnumAttrCase::EnumAttrCase(const llvm::DefInit *init)
: Attribute(init) {
- assert(def->isSubClassOf("EnumAttrCase") &&
- "must be subclass of TableGen 'EnumAttrCase' class");
+ assert(def->isSubClassOf("EnumAttrCaseInfo") &&
+ "must be subclass of TableGen 'EnumAttrInfo' class");
+}
+
+bool tblgen::EnumAttrCase::isStrCase() const {
+ return def->isSubClassOf("EnumAttrCase");
}
StringRef tblgen::EnumAttrCase::getSymbol() const {
@@ -145,11 +149,12 @@ StringRef tblgen::EnumAttrCase::getSymbol() const {
}
int64_t tblgen::EnumAttrCase::getValue() const {
+ assert(isStrCase() && "cannot get value for EnumAttrCase");
return def->getValueAsInt("value");
}
tblgen::EnumAttr::EnumAttr(const llvm::Record *record) : Attribute(record) {
- assert(def->isSubClassOf("EnumAttr") &&
+ assert(def->isSubClassOf("EnumAttrInfo") &&
"must be subclass of TableGen 'EnumAttr' class");
}
@@ -158,6 +163,10 @@ tblgen::EnumAttr::EnumAttr(const llvm::Record &record) : Attribute(&record) {}
tblgen::EnumAttr::EnumAttr(const llvm::DefInit *init)
: EnumAttr(init->getDef()) {}
+bool tblgen::EnumAttr::isStrEnum() const {
+ return def->isSubClassOf("EnumAttr");
+}
+
StringRef tblgen::EnumAttr::getEnumClassName() const {
return def->getValueAsString("className");
}
diff --git a/mlir/lib/TableGen/Pattern.cpp b/mlir/lib/TableGen/Pattern.cpp
index e2ddcbae076..467c3d5c177 100644
--- a/mlir/lib/TableGen/Pattern.cpp
+++ b/mlir/lib/TableGen/Pattern.cpp
@@ -54,7 +54,7 @@ bool tblgen::DagLeaf::isConstantAttr() const {
}
bool tblgen::DagLeaf::isEnumAttrCase() const {
- return isSubClassOf("EnumAttrCase");
+ return isSubClassOf("EnumAttrCaseInfo");
}
tblgen::Constraint tblgen::DagLeaf::getAsConstraint() const {
OpenPOWER on IntegriCloud