[Mlir-commits] [mlir] [NFC][MLIR][TableGen] Eliminate `llvm::` for commonly used types (PR #112456)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 17 08:17:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
Eliminate `llvm::` namespace qualifier for commonly used types in MLIR TableGen backends to reduce code clutter.
---
Patch is 47.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112456.diff
9 Files Affected:
- (modified) mlir/lib/TableGen/AttrOrTypeDef.cpp (+41-40)
- (modified) mlir/lib/TableGen/Attribute.cpp (+12-13)
- (modified) mlir/lib/TableGen/Builder.cpp (+14-10)
- (modified) mlir/lib/TableGen/CodeGenHelpers.cpp (+9-9)
- (modified) mlir/lib/TableGen/Interfaces.cpp (+17-13)
- (modified) mlir/lib/TableGen/Operator.cpp (+19-19)
- (modified) mlir/lib/TableGen/Pattern.cpp (+65-61)
- (modified) mlir/lib/TableGen/Predicate.cpp (+13-10)
- (modified) mlir/lib/TableGen/Type.cpp (+3-2)
``````````diff
diff --git a/mlir/lib/TableGen/AttrOrTypeDef.cpp b/mlir/lib/TableGen/AttrOrTypeDef.cpp
index e72ca155bcf765..9e8f789d71b5ea 100644
--- a/mlir/lib/TableGen/AttrOrTypeDef.cpp
+++ b/mlir/lib/TableGen/AttrOrTypeDef.cpp
@@ -17,6 +17,12 @@
using namespace mlir;
using namespace mlir::tblgen;
+using llvm::DefInit;
+using llvm::Init;
+using llvm::ListInit;
+using llvm::Record;
+using llvm::RecordVal;
+using llvm::StringInit;
//===----------------------------------------------------------------------===//
// AttrOrTypeBuilder
@@ -35,14 +41,13 @@ bool AttrOrTypeBuilder::hasInferredContextParameter() const {
// AttrOrTypeDef
//===----------------------------------------------------------------------===//
-AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
+AttrOrTypeDef::AttrOrTypeDef(const Record *def) : def(def) {
// Populate the builders.
- auto *builderList =
- dyn_cast_or_null<llvm::ListInit>(def->getValueInit("builders"));
+ const auto *builderList =
+ dyn_cast_or_null<ListInit>(def->getValueInit("builders"));
if (builderList && !builderList->empty()) {
- for (const llvm::Init *init : builderList->getValues()) {
- AttrOrTypeBuilder builder(cast<llvm::DefInit>(init)->getDef(),
- def->getLoc());
+ for (const Init *init : builderList->getValues()) {
+ AttrOrTypeBuilder builder(cast<DefInit>(init)->getDef(), def->getLoc());
// Ensure that all parameters have names.
for (const AttrOrTypeBuilder::Parameter ¶m :
@@ -56,16 +61,16 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
// Populate the traits.
if (auto *traitList = def->getValueAsListInit("traits")) {
- SmallPtrSet<const llvm::Init *, 32> traitSet;
+ SmallPtrSet<const Init *, 32> traitSet;
traits.reserve(traitSet.size());
- llvm::unique_function<void(const llvm::ListInit *)> processTraitList =
- [&](const llvm::ListInit *traitList) {
+ llvm::unique_function<void(const ListInit *)> processTraitList =
+ [&](const ListInit *traitList) {
for (auto *traitInit : *traitList) {
if (!traitSet.insert(traitInit).second)
continue;
// If this is an interface, add any bases to the trait list.
- auto *traitDef = cast<llvm::DefInit>(traitInit)->getDef();
+ auto *traitDef = cast<DefInit>(traitInit)->getDef();
if (traitDef->isSubClassOf("Interface")) {
if (auto *bases = traitDef->getValueAsListInit("baseInterfaces"))
processTraitList(bases);
@@ -111,7 +116,7 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
}
Dialect AttrOrTypeDef::getDialect() const {
- auto *dialect = dyn_cast<llvm::DefInit>(def->getValue("dialect")->getValue());
+ const auto *dialect = dyn_cast<DefInit>(def->getValue("dialect")->getValue());
return Dialect(dialect ? dialect->getDef() : nullptr);
}
@@ -126,8 +131,8 @@ StringRef AttrOrTypeDef::getCppBaseClassName() const {
}
bool AttrOrTypeDef::hasDescription() const {
- const llvm::RecordVal *desc = def->getValue("description");
- return desc && isa<llvm::StringInit>(desc->getValue());
+ const RecordVal *desc = def->getValue("description");
+ return desc && isa<StringInit>(desc->getValue());
}
StringRef AttrOrTypeDef::getDescription() const {
@@ -135,8 +140,8 @@ StringRef AttrOrTypeDef::getDescription() const {
}
bool AttrOrTypeDef::hasSummary() const {
- const llvm::RecordVal *summary = def->getValue("summary");
- return summary && isa<llvm::StringInit>(summary->getValue());
+ const RecordVal *summary = def->getValue("summary");
+ return summary && isa<StringInit>(summary->getValue());
}
StringRef AttrOrTypeDef::getSummary() const {
@@ -249,9 +254,9 @@ StringRef TypeDef::getTypeName() const {
template <typename InitT>
auto AttrOrTypeParameter::getDefValue(StringRef name) const {
std::optional<decltype(std::declval<InitT>().getValue())> result;
- if (auto *param = dyn_cast<llvm::DefInit>(getDef()))
- if (auto *init = param->getDef()->getValue(name))
- if (auto *value = dyn_cast_or_null<InitT>(init->getValue()))
+ if (const auto *param = dyn_cast<DefInit>(getDef()))
+ if (const auto *init = param->getDef()->getValue(name))
+ if (const auto *value = dyn_cast_or_null<InitT>(init->getValue()))
result = value->getValue();
return result;
}
@@ -270,20 +275,20 @@ std::string AttrOrTypeParameter::getAccessorName() const {
}
std::optional<StringRef> AttrOrTypeParameter::getAllocator() const {
- return getDefValue<llvm::StringInit>("allocator");
+ return getDefValue<StringInit>("allocator");
}
StringRef AttrOrTypeParameter::getComparator() const {
- return getDefValue<llvm::StringInit>("comparator").value_or("$_lhs == $_rhs");
+ return getDefValue<StringInit>("comparator").value_or("$_lhs == $_rhs");
}
StringRef AttrOrTypeParameter::getCppType() const {
- if (auto *stringType = dyn_cast<llvm::StringInit>(getDef()))
+ if (auto *stringType = dyn_cast<StringInit>(getDef()))
return stringType->getValue();
- auto cppType = getDefValue<llvm::StringInit>("cppType");
+ auto cppType = getDefValue<StringInit>("cppType");
if (cppType)
return *cppType;
- if (auto *init = dyn_cast<llvm::DefInit>(getDef()))
+ if (const auto *init = dyn_cast<DefInit>(getDef()))
llvm::PrintFatalError(
init->getDef()->getLoc(),
Twine("Missing `cppType` field in Attribute/Type parameter: ") +
@@ -295,34 +300,33 @@ StringRef AttrOrTypeParameter::getCppType() const {
}
StringRef AttrOrTypeParameter::getCppAccessorType() const {
- return getDefValue<llvm::StringInit>("cppAccessorType")
- .value_or(getCppType());
+ return getDefValue<StringInit>("cppAccessorType").value_or(getCppType());
}
StringRef AttrOrTypeParameter::getCppStorageType() const {
- return getDefValue<llvm::StringInit>("cppStorageType").value_or(getCppType());
+ return getDefValue<StringInit>("cppStorageType").value_or(getCppType());
}
StringRef AttrOrTypeParameter::getConvertFromStorage() const {
- return getDefValue<llvm::StringInit>("convertFromStorage").value_or("$_self");
+ return getDefValue<StringInit>("convertFromStorage").value_or("$_self");
}
std::optional<StringRef> AttrOrTypeParameter::getParser() const {
- return getDefValue<llvm::StringInit>("parser");
+ return getDefValue<StringInit>("parser");
}
std::optional<StringRef> AttrOrTypeParameter::getPrinter() const {
- return getDefValue<llvm::StringInit>("printer");
+ return getDefValue<StringInit>("printer");
}
std::optional<StringRef> AttrOrTypeParameter::getSummary() const {
- return getDefValue<llvm::StringInit>("summary");
+ return getDefValue<StringInit>("summary");
}
StringRef AttrOrTypeParameter::getSyntax() const {
- if (auto *stringType = dyn_cast<llvm::StringInit>(getDef()))
+ if (auto *stringType = dyn_cast<StringInit>(getDef()))
return stringType->getValue();
- return getDefValue<llvm::StringInit>("syntax").value_or(getCppType());
+ return getDefValue<StringInit>("syntax").value_or(getCppType());
}
bool AttrOrTypeParameter::isOptional() const {
@@ -330,17 +334,14 @@ bool AttrOrTypeParameter::isOptional() const {
}
std::optional<StringRef> AttrOrTypeParameter::getDefaultValue() const {
- std::optional<StringRef> result =
- getDefValue<llvm::StringInit>("defaultValue");
+ std::optional<StringRef> result = getDefValue<StringInit>("defaultValue");
return result && !result->empty() ? result : std::nullopt;
}
-const llvm::Init *AttrOrTypeParameter::getDef() const {
- return def->getArg(index);
-}
+const Init *AttrOrTypeParameter::getDef() const { return def->getArg(index); }
std::optional<Constraint> AttrOrTypeParameter::getConstraint() const {
- if (auto *param = dyn_cast<llvm::DefInit>(getDef()))
+ if (const auto *param = dyn_cast<DefInit>(getDef()))
if (param->getDef()->isSubClassOf("Constraint"))
return Constraint(param->getDef());
return std::nullopt;
@@ -351,8 +352,8 @@ std::optional<Constraint> AttrOrTypeParameter::getConstraint() const {
//===----------------------------------------------------------------------===//
bool AttributeSelfTypeParameter::classof(const AttrOrTypeParameter *param) {
- const llvm::Init *paramDef = param->getDef();
- if (auto *paramDefInit = dyn_cast<llvm::DefInit>(paramDef))
+ const Init *paramDef = param->getDef();
+ if (const auto *paramDefInit = dyn_cast<DefInit>(paramDef))
return paramDefInit->getDef()->isSubClassOf("AttributeSelfTypeParameter");
return false;
}
diff --git a/mlir/lib/TableGen/Attribute.cpp b/mlir/lib/TableGen/Attribute.cpp
index 887553bca66102..f9fc58a40f334c 100644
--- a/mlir/lib/TableGen/Attribute.cpp
+++ b/mlir/lib/TableGen/Attribute.cpp
@@ -71,7 +71,7 @@ StringRef Attribute::getReturnType() const {
// Return the type constraint corresponding to the type of this attribute, or
// std::nullopt if this is not a TypedAttr.
std::optional<Type> Attribute::getValueType() const {
- if (auto *defInit = dyn_cast<llvm::DefInit>(def->getValueInit("valueType")))
+ if (const auto *defInit = dyn_cast<DefInit>(def->getValueInit("valueType")))
return Type(defInit->getDef());
return std::nullopt;
}
@@ -92,8 +92,7 @@ StringRef Attribute::getConstBuilderTemplate() const {
}
Attribute Attribute::getBaseAttr() const {
- if (const auto *defInit =
- llvm::dyn_cast<llvm::DefInit>(def->getValueInit("baseAttr"))) {
+ if (const auto *defInit = dyn_cast<DefInit>(def->getValueInit("baseAttr"))) {
return Attribute(defInit).getBaseAttr();
}
return *this;
@@ -132,7 +131,7 @@ Dialect Attribute::getDialect() const {
return Dialect(nullptr);
}
-const llvm::Record &Attribute::getDef() const { return *def; }
+const Record &Attribute::getDef() const { return *def; }
ConstantAttr::ConstantAttr(const DefInit *init) : def(init->getDef()) {
assert(def->isSubClassOf("ConstantAttr") &&
@@ -147,12 +146,12 @@ StringRef ConstantAttr::getConstantValue() const {
return def->getValueAsString("value");
}
-EnumAttrCase::EnumAttrCase(const llvm::Record *record) : Attribute(record) {
+EnumAttrCase::EnumAttrCase(const Record *record) : Attribute(record) {
assert(isSubClassOf("EnumAttrCaseInfo") &&
"must be subclass of TableGen 'EnumAttrInfo' class");
}
-EnumAttrCase::EnumAttrCase(const llvm::DefInit *init)
+EnumAttrCase::EnumAttrCase(const DefInit *init)
: EnumAttrCase(init->getDef()) {}
StringRef EnumAttrCase::getSymbol() const {
@@ -163,16 +162,16 @@ StringRef EnumAttrCase::getStr() const { return def->getValueAsString("str"); }
int64_t EnumAttrCase::getValue() const { return def->getValueAsInt("value"); }
-const llvm::Record &EnumAttrCase::getDef() const { return *def; }
+const Record &EnumAttrCase::getDef() const { return *def; }
-EnumAttr::EnumAttr(const llvm::Record *record) : Attribute(record) {
+EnumAttr::EnumAttr(const Record *record) : Attribute(record) {
assert(isSubClassOf("EnumAttrInfo") &&
"must be subclass of TableGen 'EnumAttr' class");
}
-EnumAttr::EnumAttr(const llvm::Record &record) : Attribute(&record) {}
+EnumAttr::EnumAttr(const Record &record) : Attribute(&record) {}
-EnumAttr::EnumAttr(const llvm::DefInit *init) : EnumAttr(init->getDef()) {}
+EnumAttr::EnumAttr(const DefInit *init) : EnumAttr(init->getDef()) {}
bool EnumAttr::classof(const Attribute *attr) {
return attr->isSubClassOf("EnumAttrInfo");
@@ -218,8 +217,8 @@ std::vector<EnumAttrCase> EnumAttr::getAllCases() const {
std::vector<EnumAttrCase> cases;
cases.reserve(inits->size());
- for (const llvm::Init *init : *inits) {
- cases.emplace_back(cast<llvm::DefInit>(init));
+ for (const Init *init : *inits) {
+ cases.emplace_back(cast<DefInit>(init));
}
return cases;
@@ -229,7 +228,7 @@ bool EnumAttr::genSpecializedAttr() const {
return def->getValueAsBit("genSpecializedAttr");
}
-const llvm::Record *EnumAttr::getBaseAttrClass() const {
+const Record *EnumAttr::getBaseAttrClass() const {
return def->getValueAsDef("baseAttrClass");
}
diff --git a/mlir/lib/TableGen/Builder.cpp b/mlir/lib/TableGen/Builder.cpp
index 044765c726019d..a94e1cca5fc59e 100644
--- a/mlir/lib/TableGen/Builder.cpp
+++ b/mlir/lib/TableGen/Builder.cpp
@@ -12,6 +12,11 @@
using namespace mlir;
using namespace mlir::tblgen;
+using llvm::DagInit;
+using llvm::DefInit;
+using llvm::Init;
+using llvm::Record;
+using llvm::StringInit;
//===----------------------------------------------------------------------===//
// Builder::Parameter
@@ -19,9 +24,9 @@ using namespace mlir::tblgen;
/// Return a string containing the C++ type of this parameter.
StringRef Builder::Parameter::getCppType() const {
- if (const auto *stringInit = dyn_cast<llvm::StringInit>(def))
+ if (const auto *stringInit = dyn_cast<StringInit>(def))
return stringInit->getValue();
- const llvm::Record *record = cast<llvm::DefInit>(def)->getDef();
+ const Record *record = cast<DefInit>(def)->getDef();
// Inlining the first part of `Record::getValueAsString` to give better
// error messages.
const llvm::RecordVal *type = record->getValue("type");
@@ -35,9 +40,9 @@ StringRef Builder::Parameter::getCppType() const {
/// Return an optional string containing the default value to use for this
/// parameter.
std::optional<StringRef> Builder::Parameter::getDefaultValue() const {
- if (isa<llvm::StringInit>(def))
+ if (isa<StringInit>(def))
return std::nullopt;
- const llvm::Record *record = cast<llvm::DefInit>(def)->getDef();
+ const Record *record = cast<DefInit>(def)->getDef();
std::optional<StringRef> value =
record->getValueAsOptionalString("defaultValue");
return value && !value->empty() ? value : std::nullopt;
@@ -47,18 +52,17 @@ std::optional<StringRef> Builder::Parameter::getDefaultValue() const {
// Builder
//===----------------------------------------------------------------------===//
-Builder::Builder(const llvm::Record *record, ArrayRef<SMLoc> loc)
- : def(record) {
+Builder::Builder(const Record *record, ArrayRef<SMLoc> loc) : def(record) {
// Initialize the parameters of the builder.
- const llvm::DagInit *dag = def->getValueAsDag("dagParams");
- auto *defInit = dyn_cast<llvm::DefInit>(dag->getOperator());
+ const DagInit *dag = def->getValueAsDag("dagParams");
+ auto *defInit = dyn_cast<DefInit>(dag->getOperator());
if (!defInit || defInit->getDef()->getName() != "ins")
PrintFatalError(def->getLoc(), "expected 'ins' in builders");
bool seenDefaultValue = false;
for (unsigned i = 0, e = dag->getNumArgs(); i < e; ++i) {
- const llvm::StringInit *paramName = dag->getArgName(i);
- const llvm::Init *paramValue = dag->getArg(i);
+ const StringInit *paramName = dag->getArgName(i);
+ const Init *paramValue = dag->getArg(i);
Parameter param(paramName ? paramName->getValue()
: std::optional<StringRef>(),
paramValue);
diff --git a/mlir/lib/TableGen/CodeGenHelpers.cpp b/mlir/lib/TableGen/CodeGenHelpers.cpp
index 2f13887aa0bbeb..747af1ce5a4d3d 100644
--- a/mlir/lib/TableGen/CodeGenHelpers.cpp
+++ b/mlir/lib/TableGen/CodeGenHelpers.cpp
@@ -24,32 +24,32 @@ using namespace mlir::tblgen;
/// Generate a unique label based on the current file name to prevent name
/// collisions if multiple generated files are included at once.
-static std::string getUniqueOutputLabel(const llvm::RecordKeeper &records,
+static std::string getUniqueOutputLabel(const RecordKeeper &records,
StringRef tag) {
// Use the input file name when generating a unique name.
std::string inputFilename = records.getInputFilename();
// Drop all but the base filename.
- StringRef nameRef = llvm::sys::path::filename(inputFilename);
+ StringRef nameRef = sys::path::filename(inputFilename);
nameRef.consume_back(".td");
// Sanitize any invalid characters.
std::string uniqueName(tag);
for (char c : nameRef) {
- if (llvm::isAlnum(c) || c == '_')
+ if (isAlnum(c) || c == '_')
uniqueName.push_back(c);
else
- uniqueName.append(llvm::utohexstr((unsigned char)c));
+ uniqueName.append(utohexstr((unsigned char)c));
}
return uniqueName;
}
StaticVerifierFunctionEmitter::StaticVerifierFunctionEmitter(
- raw_ostream &os, const llvm::RecordKeeper &records, StringRef tag)
+ raw_ostream &os, const RecordKeeper &records, StringRef tag)
: os(os), uniqueOutputLabel(getUniqueOutputLabel(records, tag)) {}
void StaticVerifierFunctionEmitter::emitOpConstraints(
- ArrayRef<const llvm::Record *> opDefs) {
+ ArrayRef<const Record *> opDefs) {
NamespaceEmitter namespaceEmitter(os, Operator(*opDefs[0]).getCppNamespace());
emitTypeConstraints();
emitAttrConstraints();
@@ -58,7 +58,7 @@ void StaticVerifierFunctionEmitter::emitOpConstraints(
}
void StaticVerifierFunctionEmitter::emitPatternConstraints(
- const llvm::ArrayRef<DagLeaf> constraints) {
+ const ArrayRef<DagLeaf> constraints) {
collectPatternConstraints(constraints);
emitPatternConstraints();
}
@@ -298,7 +298,7 @@ void StaticVerifierFunctionEmitter::collectOpConstraints(
}
void StaticVerifierFunctionEmitter::collectPatternConstraints(
- const llvm::ArrayRef<DagLeaf> constraints) {
+ const ArrayRef<DagLeaf> constraints) {
for (auto &leaf : constraints) {
assert(leaf.isOperandMatcher() || leaf.isAttrMatcher());
collectConstraint(
@@ -313,7 +313,7 @@ void StaticVerifierFunctionEmitter::collectPatternConstraints(
std::string mlir::tblgen::escapeString(StringRef value) {
std::string ret;
- llvm::raw_string_ostream os(ret);
+ raw_string_ostream os(ret);
os.write_escaped(value);
return ret;
}
diff --git a/mlir/lib/TableGen/Interfaces.cpp b/mlir/lib/TableGen/Interfaces.cpp
index 4a6709a43d0a8f..dc9a74c4e8a90a 100644
--- a/mlir/lib/TableGen/Interfaces.cpp
+++ b/mlir/lib/TableGen/Interfaces.cpp
@@ -16,17 +16,22 @@
using namespace mlir;
using namespace mlir::tblgen;
+using llvm::DagInit;
+using llvm::DefInit;
+using llvm::Init;
+using llvm::ListInit;
+using llvm::Record;
+using llvm::StringInit;
//===----------------------------------------------------------------------===//
// InterfaceMethod
//===----------------------------------------------------------------------===//
-InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) {
- const llvm::DagInit *args = def->getValueAsDag("arguments");
+InterfaceMethod::InterfaceMethod(const Record *def) : def(def) {
+ const DagInit *args = def->getValueAsDag("arguments");
for (unsigned i = 0, e = args->getNumArgs(); i != e; ++i) {
- arguments.push_back(
- {llvm::cast<llvm::StringInit>(args->getArg(i))->getValue(),
- args->getArgNameStr(i)});
+ arguments.push_back({cast<StringInit>(args->getArg(i))->getValue(),
+ args->getArgNameStr(i)});
}
}
@@ -72,18 +77,17 @@ bool InterfaceMethod::arg_empty() const { return arguments.empty(); }
// Interface
//===----------------------------------------------------------------------===//
-Interface::Interface(const llvm::Record *def) : def(def) {
+Interface::Interface(const Record *def) : def(def) {
assert(def->isSubClassOf("Interface") &&
"must be subclass of TableGen 'Interface' class");
// Initialize the interface methods.
- auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("methods"));
- for (const llvm::Init *init : listInit->getValues())
- methods.emplace_back(cast<llvm::DefInit>(init)->getDef());
+ auto *listInit = dyn_cast<ListInit>(def->getValueInit("methods"));
+ for (const Init *init : listInit->getValues())
+ methods.emplace_back(cast<DefInit>(init)->getDef());
// Initialize the interface base classes.
- auto *basesInit =
- dyn_cast<llvm::ListInit>(def->getValueInit("baseInterfaces"));
+ auto *basesInit = dyn_cast<ListInit>(def->getValueInit("baseInterfaces"));
// Chained inheritance will produce duplicates in the base interface set.
StringSet<> basesAdded;
llvm::unique_function<void(Interface)> addBaseInterfaceFn =
@@ -98,8 +102,8 @@ Interface::Interface(const llvm::Record *def) : def(def) {
baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
basesAdded.insert(baseInterface.getName(...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/112456
More information about the Mlir-commits
mailing list