Put Operator and PredCNF into the tblgen namespace

PiperOrigin-RevId: 228429130
This commit is contained in:
Lei Zhang 2019-01-08 17:19:37 -08:00 committed by jpienaar
parent b2cc2c344e
commit 3e5ee82b81
7 changed files with 42 additions and 25 deletions

View File

@ -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_

View File

@ -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_

View File

@ -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();
}

View File

@ -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";

View File

@ -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");

View File

@ -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.

View File

@ -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));