NFC: Simplify named attribute in TableGen generators

Now, op attribute names don't have '.' in their names so the special handling for it
    can be removed. Attributes for functions still have dialect prefix with '.' as separator but TableGen does not deal with functions.

    TESTED with existing unit tests

--

PiperOrigin-RevId: 243287462
This commit is contained in:
Smit Hinsu 2019-04-12 10:24:59 -07:00 committed by Mehdi Amini
parent 2dc6d205ac
commit 0047ef9765
5 changed files with 8 additions and 28 deletions

View File

@ -44,9 +44,6 @@ namespace tblgen {
// A struct wrapping an op attribute and its name together
struct NamedAttribute {
// Returns the MLIR attribute name.
std::string getName() const;
llvm::StringRef name;
Attribute attr;
};

View File

@ -16,19 +16,10 @@
// =============================================================================
#include "mlir/TableGen/Argument.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/TableGen/Record.h"
using namespace mlir;
std::string tblgen::NamedAttribute::getName() const {
// TODO(jpienaar): Revise this post dialect prefixing attribute discussion.
auto split = name.split("__");
if (split.second.empty())
return name;
return llvm::join_items(".", split.first, split.second);
}
bool tblgen::NamedTypeConstraint::hasPredicate() const {
return !constraint.getPredicate().isNull();
}

View File

@ -426,17 +426,10 @@ void OpEmitter::genAttrGetters() {
FmtContext fctx;
fctx.withBuilder("mlir::Builder(this->getContext())");
for (auto &namedAttr : op.getAttributes()) {
auto name = namedAttr.getName();
const auto &name = namedAttr.name;
const auto &attr = namedAttr.attr;
// Determine the name of the attribute getter. The name matches the
// attribute name excluding dialect prefix.
StringRef getter = name;
auto it = getter.split('.');
if (!it.second.empty())
getter = it.second;
auto &method = opClass.newMethod(attr.getReturnType(), getter);
auto &method = opClass.newMethod(attr.getReturnType(), name);
auto &body = method.body();
// Emit the derived attribute body.
@ -625,9 +618,8 @@ void OpEmitter::genStandaloneParamBuilder(bool useOperandType,
if (emitNotNullCheck) {
method.body() << formatv(" if ({0}) ", namedAttr.name) << "{\n";
}
method.body() << formatv(" {0}->addAttribute(\"{1}\", {2});\n",
builderOpState, namedAttr.getName(),
namedAttr.name);
method.body() << formatv(" {0}->addAttribute(\"{1}\", {1});\n",
builderOpState, namedAttr.name);
if (emitNotNullCheck) {
method.body() << " }\n";
}
@ -800,9 +792,9 @@ void OpEmitter::genVerifier() {
if (attr.isDerivedAttr())
continue;
auto attrName = namedAttr.getName();
auto attrName = namedAttr.name;
// Prefix with `tblgen_` to avoid hiding the attribute accessor.
auto varName = tblgenNamePrefix + namedAttr.name;
auto varName = tblgenNamePrefix + attrName;
body << formatv(" auto {0} = this->getAttr(\"{1}\");\n", varName,
attrName);

View File

@ -117,7 +117,7 @@ static void emitOpDoc(const RecordKeeper &recordKeeper, raw_ostream &os) {
<< "| :-------: | :-------: | ----------- |\n";
}
for (auto namedAttr : op.getAttributes()) {
os << "| `" << namedAttr.getName() << "` | `"
os << "| `" << namedAttr.name << "` | `"
<< namedAttr.attr.getStorageType() << "` | "
<< namedAttr.attr.getDescription() << " attribute |\n";
}

View File

@ -345,7 +345,7 @@ void PatternEmitter::emitAttributeMatch(DagNode tree, int index, int depth,
indent += 2;
os.indent(indent) << formatv(
"auto attr = op{0}->getAttrOfType<{1}>(\"{2}\");\n", depth,
attr.getStorageType(), namedAttr->getName());
attr.getStorageType(), namedAttr->name);
// TODO(antiagainst): This should use getter method to avoid duplication.
if (attr.hasDefaultValueInitializer()) {