aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen/Dialect.cpp
diff options
context:
space:
mode:
authorJacques Pienaar <jpienaar@google.com>2021-10-14 15:58:44 -0700
committerJacques Pienaar <jpienaar@google.com>2021-10-14 15:58:44 -0700
commit65c9907c809a275e57bd925d1eda5a743a462d20 (patch)
tree287250e56a7c409f420dfa4d04270ad1002f6ebb /mlir/lib/TableGen/Dialect.cpp
parent6965a776ee192cb4c1a2618c270254fbf70879df (diff)
[mlir][ods] Enable emitting getter/setter prefix
Allow emitting get & set prefix for accessors generated for ops. If enabled, then the argument/return/region name gets converted from snake_case to UpperCamel and prefix added. The attribute also allows generating both the current "raw" method along with the prefix'd one to make it easier to stage changes. The option is added on the dialect and currently defaults to existing raw behavior. The expectation is that the staging where both are generated would be short lived and so optimized to keeping the changes local/less invasive (it just generates two functions for each accessor with the same body - most of these internally again call a helper function). But generation can be optimized if needed. I'm unsure about OpAdaptor classes as there it is all get methods (it is a named view into raw data structures), so prefix doesn't add much. This starts with emitting raw-only form (as current behavior) as default, then one can opt-in to raw & prefixed, then just prefixed. The default in OpBase will switch to prefixed-only to be consistent with MLIR style guide. And the option potentially removed later (considered enabling specifying prefix but current discussion more pro keeping it limited and stuck with that). Also add more explicit checking for pruned functions to avoid emitting where no function was added (and so avoiding dereferencing nullptr) during op def/decl generation. See https://bugs.llvm.org/show_bug.cgi?id=51916 for further discussion. Differential Revision: https://reviews.llvm.org/D111033
Diffstat (limited to 'mlir/lib/TableGen/Dialect.cpp')
-rw-r--r--mlir/lib/TableGen/Dialect.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/mlir/lib/TableGen/Dialect.cpp b/mlir/lib/TableGen/Dialect.cpp
index 59e7593c9425..7b5e89a7e6c9 100644
--- a/mlir/lib/TableGen/Dialect.cpp
+++ b/mlir/lib/TableGen/Dialect.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "mlir/TableGen/Dialect.h"
+#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
using namespace mlir;
@@ -89,6 +90,13 @@ bool Dialect::hasOperationInterfaceFallback() const {
return def->getValueAsBit("hasOperationInterfaceFallback");
}
+Dialect::EmitPrefix Dialect::getEmitAccessorPrefix() const {
+ int prefix = def->getValueAsInt("emitAccessorPrefix");
+ if (prefix < 0 || prefix > static_cast<int>(EmitPrefix::Both))
+ PrintFatalError(def->getLoc(), "Invalid accessor prefix value");
+ return static_cast<EmitPrefix>(prefix);
+}
+
bool Dialect::operator==(const Dialect &other) const {
return def == other.def;
}