summaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen/Operator.cpp
diff options
context:
space:
mode:
authorRiver Riddle <riddleriver@gmail.com>2020-03-06 13:55:36 -0800
committerRiver Riddle <riddleriver@gmail.com>2020-03-06 14:04:36 -0800
commit20dca52288adfb64cdeb25fd25fbe0bb8628e7c3 (patch)
tree3f658106486194dda5d36e5fc0b3ba591aeed7ff /mlir/lib/TableGen/Operator.cpp
parentf8923584da83be461aafab3f45cc41f872fa7d74 (diff)
[mlir][SideEffects] Enable specifying side effects directly on the arguments/results of an operation.
Summary: New classes are added to ODS to enable specifying additional information on the arguments and results of an operation. These classes, `Arg` and `Res` allow for adding a description and a set of 'decorators' along with the constraint. This enables specifying the side effects of an operation directly on the arguments and results themselves. Example: ``` def LoadOp : Std_Op<"load"> { let arguments = (ins Arg<AnyMemRef, "the MemRef to load from", [MemRead]>:$memref, Variadic<Index>:$indices); } ``` Differential Revision: https://reviews.llvm.org/D74440
Diffstat (limited to 'mlir/lib/TableGen/Operator.cpp')
-rw-r--r--mlir/lib/TableGen/Operator.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp
index 007d8ab7bd69..6492b772e4b7 100644
--- a/mlir/lib/TableGen/Operator.cpp
+++ b/mlir/lib/TableGen/Operator.cpp
@@ -109,6 +109,15 @@ StringRef tblgen::Operator::getResultName(int index) const {
return results->getArgNameStr(index);
}
+auto tblgen::Operator::getResultDecorators(int index) const
+ -> var_decorator_range {
+ Record *result =
+ cast<DefInit>(def.getValueAsDag("results")->getArg(index))->getDef();
+ if (!result->isSubClassOf("OpVariable"))
+ return var_decorator_range(nullptr, nullptr);
+ return *result->getValueAsListInit("decorators");
+}
+
unsigned tblgen::Operator::getNumVariadicResults() const {
return std::count_if(
results.begin(), results.end(),
@@ -138,6 +147,15 @@ StringRef tblgen::Operator::getArgName(int index) const {
return argumentValues->getArgName(index)->getValue();
}
+auto tblgen::Operator::getArgDecorators(int index) const
+ -> var_decorator_range {
+ Record *arg =
+ cast<DefInit>(def.getValueAsDag("arguments")->getArg(index))->getDef();
+ if (!arg->isSubClassOf("OpVariable"))
+ return var_decorator_range(nullptr, nullptr);
+ return *arg->getValueAsListInit("decorators");
+}
+
const tblgen::OpTrait *tblgen::Operator::getTrait(StringRef trait) const {
for (const auto &t : traits) {
if (auto opTrait = dyn_cast<tblgen::NativeOpTrait>(&t)) {
@@ -226,6 +244,7 @@ void tblgen::Operator::populateOpStructure() {
auto typeConstraintClass = recordKeeper.getClass("TypeConstraint");
auto attrClass = recordKeeper.getClass("Attr");
auto derivedAttrClass = recordKeeper.getClass("DerivedAttr");
+ auto opVarClass = recordKeeper.getClass("OpVariable");
numNativeAttributes = 0;
DagInit *argumentValues = def.getValueAsDag("arguments");
@@ -240,10 +259,12 @@ void tblgen::Operator::populateOpStructure() {
PrintFatalError(def.getLoc(),
Twine("undefined type for argument #") + Twine(i));
Record *argDef = argDefInit->getDef();
+ if (argDef->isSubClassOf(opVarClass))
+ argDef = argDef->getValueAsDef("constraint");
if (argDef->isSubClassOf(typeConstraintClass)) {
operands.push_back(
- NamedTypeConstraint{givenName, TypeConstraint(argDefInit)});
+ NamedTypeConstraint{givenName, TypeConstraint(argDef)});
} else if (argDef->isSubClassOf(attrClass)) {
if (givenName.empty())
PrintFatalError(argDef->getLoc(), "attributes must be named");
@@ -285,6 +306,8 @@ void tblgen::Operator::populateOpStructure() {
int operandIndex = 0, attrIndex = 0;
for (unsigned i = 0; i != numArgs; ++i) {
Record *argDef = dyn_cast<DefInit>(argumentValues->getArg(i))->getDef();
+ if (argDef->isSubClassOf(opVarClass))
+ argDef = argDef->getValueAsDef("constraint");
if (argDef->isSubClassOf(typeConstraintClass)) {
arguments.emplace_back(&operands[operandIndex++]);
@@ -303,11 +326,14 @@ void tblgen::Operator::populateOpStructure() {
// Handle results.
for (unsigned i = 0, e = resultsDag->getNumArgs(); i < e; ++i) {
auto name = resultsDag->getArgNameStr(i);
- auto *resultDef = dyn_cast<DefInit>(resultsDag->getArg(i));
- if (!resultDef) {
+ auto *resultInit = dyn_cast<DefInit>(resultsDag->getArg(i));
+ if (!resultInit) {
PrintFatalError(def.getLoc(),
Twine("undefined type for result #") + Twine(i));
}
+ auto *resultDef = resultInit->getDef();
+ if (resultDef->isSubClassOf(opVarClass))
+ resultDef = resultDef->getValueAsDef("constraint");
results.push_back({name, TypeConstraint(resultDef)});
}
@@ -394,3 +420,8 @@ void tblgen::Operator::print(llvm::raw_ostream &os) const {
os << "[operand] " << arg.get<NamedTypeConstraint *>()->name << '\n';
}
}
+
+auto tblgen::Operator::VariableDecoratorIterator::unwrap(llvm::Init *init)
+ -> VariableDecorator {
+ return VariableDecorator(cast<llvm::DefInit>(init)->getDef());
+}