summaryrefslogtreecommitdiffstats
path: root/mlir
diff options
context:
space:
mode:
authorLei Zhang <antiagainst@google.com>2019-01-08 17:19:37 -0800
committerjpienaar <jpienaar@google.com>2019-03-29 15:05:38 -0700
commit3e5ee82b817ce0c0188f046b5ef3b01a329d8041 (patch)
tree5af6fe28afeaf17baf2d01feb29f7997e965ed86 /mlir
parentb2cc2c344e6d295d1ad09221935e3430dd5bfb3c (diff)
downloadbcm5719-llvm-3e5ee82b817ce0c0188f046b5ef3b01a329d8041.tar.gz
bcm5719-llvm-3e5ee82b817ce0c0188f046b5ef3b01a329d8041.zip
Put Operator and PredCNF into the tblgen namespace
PiperOrigin-RevId: 228429130
Diffstat (limited to 'mlir')
-rw-r--r--mlir/include/mlir/TableGen/Operator.h2
-rw-r--r--mlir/include/mlir/TableGen/Predicate.h2
-rw-r--r--mlir/lib/TableGen/Operator.cpp46
-rw-r--r--mlir/lib/TableGen/Predicate.cpp6
-rw-r--r--mlir/lib/TableGen/Type.cpp2
-rw-r--r--mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp2
-rw-r--r--mlir/tools/mlir-tblgen/RewriterGen.cpp7
7 files changed, 42 insertions, 25 deletions
diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h
index 6cc32ac7ccb..54f404a060d 100644
--- a/mlir/include/mlir/TableGen/Operator.h
+++ b/mlir/include/mlir/TableGen/Operator.h
@@ -35,6 +35,7 @@ class StringInit;
} // end namespace llvm
namespace mlir {
+namespace tblgen {
// Wrapper class that contains a MLIR op's information (e.g., operands,
// atributes) defined in TableGen and provides helper methods for
@@ -128,6 +129,7 @@ private:
const llvm::Record &def;
};
+} // end namespace tblgen
} // end namespace mlir
#endif // MLIR_TABLEGEN_OPERATOR_H_
diff --git a/mlir/include/mlir/TableGen/Predicate.h b/mlir/include/mlir/TableGen/Predicate.h
index 11b58370837..a89fbf15e48 100644
--- a/mlir/include/mlir/TableGen/Predicate.h
+++ b/mlir/include/mlir/TableGen/Predicate.h
@@ -31,6 +31,7 @@ class Record;
} // end namespace llvm
namespace mlir {
+namespace tblgen {
// Predicate in Conjunctive Normal Form (CNF).
//
@@ -67,6 +68,7 @@ private:
const llvm::Record *def;
};
+} // end namespace tblgen
} // end namespace mlir
#endif // MLIR_TABLEGEN_PREDICATE_H_
diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp
index b0efc7c9912..04f1457c6a4 100644
--- a/mlir/lib/TableGen/Operator.cpp
+++ b/mlir/lib/TableGen/Operator.cpp
@@ -28,56 +28,64 @@
#include "llvm/TableGen/Record.h"
using namespace mlir;
+
using llvm::DagInit;
using llvm::DefInit;
using llvm::Record;
-Operator::Operator(const llvm::Record &def) : def(def) {
+tblgen::Operator::Operator(const llvm::Record &def) : def(def) {
SplitString(def.getName(), splittedDefName, "_");
populateOperandsAndAttributes();
}
-const SmallVectorImpl<StringRef> &Operator::getSplitDefName() const {
+const SmallVectorImpl<StringRef> &tblgen::Operator::getSplitDefName() const {
return splittedDefName;
}
-StringRef Operator::getOperationName() const {
+StringRef tblgen::Operator::getOperationName() const {
return def.getValueAsString("opName");
}
-StringRef Operator::cppClassName() const { return getSplitDefName().back(); }
-std::string Operator::qualifiedCppClassName() const {
+StringRef tblgen::Operator::cppClassName() const {
+ return getSplitDefName().back();
+}
+std::string tblgen::Operator::qualifiedCppClassName() const {
return llvm::join(getSplitDefName(), "::");
}
-StringRef Operator::getArgName(int index) const {
+StringRef tblgen::Operator::getArgName(int index) const {
DagInit *argumentValues = def.getValueAsDag("arguments");
return argumentValues->getArgName(index)->getValue();
}
-auto Operator::attribute_begin() -> attribute_iterator {
+auto tblgen::Operator::attribute_begin() -> attribute_iterator {
return attributes.begin();
}
-auto Operator::attribute_end() -> attribute_iterator {
+auto tblgen::Operator::attribute_end() -> attribute_iterator {
return attributes.end();
}
-auto Operator::getAttributes() -> llvm::iterator_range<attribute_iterator> {
+auto tblgen::Operator::getAttributes()
+ -> llvm::iterator_range<attribute_iterator> {
return {attribute_begin(), attribute_end()};
}
-auto Operator::operand_begin() -> operand_iterator { return operands.begin(); }
-auto Operator::operand_end() -> operand_iterator { return operands.end(); }
-auto Operator::getOperands() -> llvm::iterator_range<operand_iterator> {
+auto tblgen::Operator::operand_begin() -> operand_iterator {
+ return operands.begin();
+}
+auto tblgen::Operator::operand_end() -> operand_iterator {
+ return operands.end();
+}
+auto tblgen::Operator::getOperands() -> llvm::iterator_range<operand_iterator> {
return {operand_begin(), operand_end()};
}
-auto Operator::getArg(int index) -> Argument {
+auto tblgen::Operator::getArg(int index) -> Argument {
if (index < nativeAttrStart)
return {&operands[index]};
return {&attributes[index - nativeAttrStart]};
}
-void Operator::populateOperandsAndAttributes() {
+void tblgen::Operator::populateOperandsAndAttributes() {
auto &recordKeeper = def.getRecords();
auto attrClass = recordKeeper.getClass("Attr");
auto derivedAttrClass = recordKeeper.getClass("DerivedAttr");
@@ -142,7 +150,7 @@ void Operator::populateOperandsAndAttributes() {
}
}
-std::string mlir::Operator::Attribute::getName() const {
+std::string tblgen::Operator::Attribute::getName() const {
std::string ret = name->getAsUnquotedString();
// TODO(jpienaar): Revise this post dialect prefixing attribute discussion.
auto split = StringRef(ret).split("__");
@@ -151,18 +159,18 @@ std::string mlir::Operator::Attribute::getName() const {
return llvm::join_items("$", split.first, split.second);
}
-StringRef mlir::Operator::Attribute::getReturnType() const {
+StringRef tblgen::Operator::Attribute::getReturnType() const {
return record->getValueAsString("returnType").trim();
}
-StringRef mlir::Operator::Attribute::getStorageType() const {
+StringRef tblgen::Operator::Attribute::getStorageType() const {
return record->getValueAsString("storageType").trim();
}
-bool mlir::Operator::Operand::hasMatcher() const {
+bool tblgen::Operator::Operand::hasMatcher() const {
return !tblgen::Type(defInit).getPredicate().isEmpty();
}
-std::string mlir::Operator::Operand::createTypeMatcherTemplate() const {
+std::string tblgen::Operator::Operand::createTypeMatcherTemplate() const {
return tblgen::Type(defInit).getPredicate().createTypeMatcherTemplate();
}
diff --git a/mlir/lib/TableGen/Predicate.cpp b/mlir/lib/TableGen/Predicate.cpp
index 265ed69c684..88d08f565c9 100644
--- a/mlir/lib/TableGen/Predicate.cpp
+++ b/mlir/lib/TableGen/Predicate.cpp
@@ -27,7 +27,7 @@
using namespace mlir;
-PredCNF::PredCNF(const llvm::Init *init) : def(nullptr) {
+tblgen::PredCNF::PredCNF(const llvm::Init *init) : def(nullptr) {
if (const auto *defInit = dyn_cast<llvm::DefInit>(init)) {
def = defInit->getDef();
assert(def->isSubClassOf("PredCNF") &&
@@ -35,14 +35,14 @@ PredCNF::PredCNF(const llvm::Init *init) : def(nullptr) {
}
}
-const llvm::ListInit *PredCNF::getConditions() const {
+const llvm::ListInit *tblgen::PredCNF::getConditions() const {
if (!def)
return nullptr;
return def->getValueAsListInit("conditions");
}
-std::string PredCNF::createTypeMatcherTemplate() const {
+std::string tblgen::PredCNF::createTypeMatcherTemplate() const {
const auto *conjunctiveList = getConditions();
if (!conjunctiveList)
return "true";
diff --git a/mlir/lib/TableGen/Type.cpp b/mlir/lib/TableGen/Type.cpp
index da6b8818d3e..dbcf386cdc3 100644
--- a/mlir/lib/TableGen/Type.cpp
+++ b/mlir/lib/TableGen/Type.cpp
@@ -42,7 +42,7 @@ StringRef tblgen::Type::getBuilderCall() const {
return {};
}
-PredCNF tblgen::Type::getPredicate() const {
+tblgen::PredCNF tblgen::Type::getPredicate() const {
auto *val = def.getValue("predicate");
assert(val && "TableGen 'Type' class should have 'predicate' field");
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 965f08d5330..ca5602935ad 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -32,6 +32,8 @@
using namespace llvm;
using namespace mlir;
+using mlir::tblgen::Operator;
+
static const char *const generatedArgName = "_arg";
// Helper macro that returns indented os.
diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp
index bd0a019b4ec..4e8c2fdf15b 100644
--- a/mlir/tools/mlir-tblgen/RewriterGen.cpp
+++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp
@@ -37,6 +37,9 @@
using namespace llvm;
using namespace mlir;
+using mlir::tblgen::Operator;
+using mlir::tblgen::Type;
+
namespace {
// Wrapper around dag argument.
@@ -89,7 +92,7 @@ private:
void Pattern::emitAttributeValue(Record *constAttr) {
Record *attr = constAttr->getValueAsDef("attr");
auto value = constAttr->getValue("value");
- tblgen::Type type(attr->getValueAsDef("type"));
+ Type type(attr->getValueAsDef("type"));
auto storageType = attr->getValueAsString("storageType").trim();
// For attributes stored as strings we do not need to query builder etc.
@@ -308,7 +311,7 @@ void Pattern::emit(StringRef rewriteName) {
// TODO(jpienaar): Refactor out into map to avoid recomputing these.
auto argument = resultOp.getArg(i);
- if (!argument.is<mlir::Operator::Attribute *>())
+ if (!argument.is<Operator::Attribute *>())
PrintFatalError(pattern->getLoc(),
Twine("expected attribute ") + Twine(i));
OpenPOWER on IntegriCloud