summaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen
diff options
context:
space:
mode:
authorMogball <jeffniu22@gmail.com>2022-06-23 20:48:30 +0000
committerMogball <jeffniu22@gmail.com>2022-06-27 15:57:21 -0700
commit92bdc5c3e55fb1d48fe3a2bfad99911e8534db92 (patch)
treeadbd831497d95b5657be88f3ac654731d1294942 /mlir/lib/TableGen
parent7b2355277950e5b42f04c0bdbc7fb8a2c4f5e308 (diff)
downloadllvm-92bdc5c3e55fb1d48fe3a2bfad99911e8534db92.tar.gz
[mlir][ods] Add convertFromStorage field to parameters
This patch adds a `convertFromStorage` field to attribute or type parameters that can implement more complex logic for converting from the parameter's C++ storage type (e.g. `Optional<SmallVector<T>>`) to its C++ type (e.g. `Optional<ArrayRef<T>>`). Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D128293
Diffstat (limited to 'mlir/lib/TableGen')
-rw-r--r--mlir/lib/TableGen/AttrOrTypeDef.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/mlir/lib/TableGen/AttrOrTypeDef.cpp b/mlir/lib/TableGen/AttrOrTypeDef.cpp
index 4479a64940bc..a202cb5d47d3 100644
--- a/mlir/lib/TableGen/AttrOrTypeDef.cpp
+++ b/mlir/lib/TableGen/AttrOrTypeDef.cpp
@@ -229,14 +229,9 @@ StringRef AttrOrTypeParameter::getComparator() const {
}
StringRef AttrOrTypeParameter::getCppType() const {
- llvm::Init *parameterType = getDef();
- if (auto *stringType = dyn_cast<llvm::StringInit>(parameterType))
+ if (auto *stringType = dyn_cast<llvm::StringInit>(getDef()))
return stringType->getValue();
- if (auto *param = dyn_cast<llvm::DefInit>(parameterType))
- return param->getDef()->getValueAsString("cppType");
- llvm::PrintFatalError(
- "Parameters DAG arguments must be either strings or defs "
- "which inherit from AttrOrTypeParameter\n");
+ return getDefValue<llvm::StringInit>("cppType").getValue();
}
StringRef AttrOrTypeParameter::getCppAccessorType() const {
@@ -248,6 +243,11 @@ StringRef AttrOrTypeParameter::getCppStorageType() const {
return getDefValue<llvm::StringInit>("cppStorageType").value_or(getCppType());
}
+StringRef AttrOrTypeParameter::getConvertFromStorage() const {
+ return getDefValue<llvm::StringInit>("convertFromStorage")
+ .getValueOr("$_self");
+}
+
Optional<StringRef> AttrOrTypeParameter::getParser() const {
return getDefValue<llvm::StringInit>("parser");
}