-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Revert "[MLIR][TableGen] Use const pointers for various Init
objects"
#112506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Mehdi Amini (joker-eph) ChangesReverts llvm/llvm-project#112316 Bots are failing. Patch is 24.45 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112506.diff 14 Files Affected:
diff --git a/mlir/include/mlir/TableGen/AttrOrTypeDef.h b/mlir/include/mlir/TableGen/AttrOrTypeDef.h
index c3d730e42ef70e..36744c85bc7086 100644
--- a/mlir/include/mlir/TableGen/AttrOrTypeDef.h
+++ b/mlir/include/mlir/TableGen/AttrOrTypeDef.h
@@ -105,7 +105,7 @@ class AttrOrTypeParameter {
std::optional<StringRef> getDefaultValue() const;
/// Return the underlying def of this parameter.
- const llvm::Init *getDef() const;
+ llvm::Init *getDef() const;
/// The parameter is pointer-comparable.
bool operator==(const AttrOrTypeParameter &other) const {
diff --git a/mlir/include/mlir/TableGen/Dialect.h b/mlir/include/mlir/TableGen/Dialect.h
index ea8f40555e4451..3530d240c976c6 100644
--- a/mlir/include/mlir/TableGen/Dialect.h
+++ b/mlir/include/mlir/TableGen/Dialect.h
@@ -92,7 +92,7 @@ class Dialect {
/// dialect.
bool usePropertiesForAttributes() const;
- const llvm::DagInit *getDiscardableAttributes() const;
+ llvm::DagInit *getDiscardableAttributes() const;
const llvm::Record *getDef() const { return def; }
diff --git a/mlir/include/mlir/TableGen/Operator.h b/mlir/include/mlir/TableGen/Operator.h
index 9e570373d9cd32..768291a3a7267b 100644
--- a/mlir/include/mlir/TableGen/Operator.h
+++ b/mlir/include/mlir/TableGen/Operator.h
@@ -119,15 +119,14 @@ class Operator {
/// A utility iterator over a list of variable decorators.
struct VariableDecoratorIterator
- : public llvm::mapped_iterator<const llvm::Init *const *,
- VariableDecorator (*)(
- const llvm::Init *)> {
+ : public llvm::mapped_iterator<llvm::Init *const *,
+ VariableDecorator (*)(llvm::Init *)> {
/// Initializes the iterator to the specified iterator.
- VariableDecoratorIterator(const llvm::Init *const *it)
- : llvm::mapped_iterator<const llvm::Init *const *,
- VariableDecorator (*)(const llvm::Init *)>(
- it, &unwrap) {}
- static VariableDecorator unwrap(const llvm::Init *init);
+ VariableDecoratorIterator(llvm::Init *const *it)
+ : llvm::mapped_iterator<llvm::Init *const *,
+ VariableDecorator (*)(llvm::Init *)>(it,
+ &unwrap) {}
+ static VariableDecorator unwrap(llvm::Init *init);
};
using var_decorator_iterator = VariableDecoratorIterator;
using var_decorator_range = llvm::iterator_range<VariableDecoratorIterator>;
diff --git a/mlir/lib/TableGen/AttrOrTypeDef.cpp b/mlir/lib/TableGen/AttrOrTypeDef.cpp
index e72ca155bcf765..9b9d9fd2317d99 100644
--- a/mlir/lib/TableGen/AttrOrTypeDef.cpp
+++ b/mlir/lib/TableGen/AttrOrTypeDef.cpp
@@ -40,7 +40,7 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
auto *builderList =
dyn_cast_or_null<llvm::ListInit>(def->getValueInit("builders"));
if (builderList && !builderList->empty()) {
- for (const llvm::Init *init : builderList->getValues()) {
+ for (llvm::Init *init : builderList->getValues()) {
AttrOrTypeBuilder builder(cast<llvm::DefInit>(init)->getDef(),
def->getLoc());
@@ -58,8 +58,8 @@ AttrOrTypeDef::AttrOrTypeDef(const llvm::Record *def) : def(def) {
if (auto *traitList = def->getValueAsListInit("traits")) {
SmallPtrSet<const llvm::Init *, 32> traitSet;
traits.reserve(traitSet.size());
- llvm::unique_function<void(const llvm::ListInit *)> processTraitList =
- [&](const llvm::ListInit *traitList) {
+ llvm::unique_function<void(llvm::ListInit *)> processTraitList =
+ [&](llvm::ListInit *traitList) {
for (auto *traitInit : *traitList) {
if (!traitSet.insert(traitInit).second)
continue;
@@ -335,9 +335,7 @@ std::optional<StringRef> AttrOrTypeParameter::getDefaultValue() const {
return result && !result->empty() ? result : std::nullopt;
}
-const llvm::Init *AttrOrTypeParameter::getDef() const {
- return def->getArg(index);
-}
+llvm::Init *AttrOrTypeParameter::getDef() const { return def->getArg(index); }
std::optional<Constraint> AttrOrTypeParameter::getConstraint() const {
if (auto *param = dyn_cast<llvm::DefInit>(getDef()))
@@ -351,7 +349,7 @@ std::optional<Constraint> AttrOrTypeParameter::getConstraint() const {
//===----------------------------------------------------------------------===//
bool AttributeSelfTypeParameter::classof(const AttrOrTypeParameter *param) {
- const llvm::Init *paramDef = param->getDef();
+ llvm::Init *paramDef = param->getDef();
if (auto *paramDefInit = dyn_cast<llvm::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..de930cb4007032 100644
--- a/mlir/lib/TableGen/Attribute.cpp
+++ b/mlir/lib/TableGen/Attribute.cpp
@@ -126,7 +126,7 @@ StringRef Attribute::getDerivedCodeBody() const {
Dialect Attribute::getDialect() const {
const llvm::RecordVal *record = def->getValue("dialect");
if (record && record->getValue()) {
- if (const DefInit *init = dyn_cast<DefInit>(record->getValue()))
+ if (DefInit *init = dyn_cast<DefInit>(record->getValue()))
return Dialect(init->getDef());
}
return Dialect(nullptr);
diff --git a/mlir/lib/TableGen/Dialect.cpp b/mlir/lib/TableGen/Dialect.cpp
index ef39818e439b3e..081f6e56f9ded4 100644
--- a/mlir/lib/TableGen/Dialect.cpp
+++ b/mlir/lib/TableGen/Dialect.cpp
@@ -106,7 +106,7 @@ bool Dialect::usePropertiesForAttributes() const {
return def->getValueAsBit("usePropertiesForAttributes");
}
-const llvm::DagInit *Dialect::getDiscardableAttributes() const {
+llvm::DagInit *Dialect::getDiscardableAttributes() const {
return def->getValueAsDag("discardableAttrs");
}
diff --git a/mlir/lib/TableGen/Interfaces.cpp b/mlir/lib/TableGen/Interfaces.cpp
index 4a6709a43d0a8f..a209b003b0f3bb 100644
--- a/mlir/lib/TableGen/Interfaces.cpp
+++ b/mlir/lib/TableGen/Interfaces.cpp
@@ -22,7 +22,7 @@ using namespace mlir::tblgen;
//===----------------------------------------------------------------------===//
InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) {
- const llvm::DagInit *args = def->getValueAsDag("arguments");
+ llvm::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(),
@@ -78,7 +78,7 @@ Interface::Interface(const llvm::Record *def) : def(def) {
// Initialize the interface methods.
auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("methods"));
- for (const llvm::Init *init : listInit->getValues())
+ for (llvm::Init *init : listInit->getValues())
methods.emplace_back(cast<llvm::DefInit>(init)->getDef());
// Initialize the interface base classes.
@@ -98,7 +98,7 @@ Interface::Interface(const llvm::Record *def) : def(def) {
baseInterfaces.push_back(std::make_unique<Interface>(baseInterface));
basesAdded.insert(baseInterface.getName());
};
- for (const llvm::Init *init : basesInit->getValues())
+ for (llvm::Init *init : basesInit->getValues())
addBaseInterfaceFn(Interface(cast<llvm::DefInit>(init)->getDef()));
}
diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp
index 86670e9f87127c..6a33ff5ecd6721 100644
--- a/mlir/lib/TableGen/Operator.cpp
+++ b/mlir/lib/TableGen/Operator.cpp
@@ -161,7 +161,7 @@ std::string Operator::getQualCppClassName() const {
StringRef Operator::getCppNamespace() const { return cppNamespace; }
int Operator::getNumResults() const {
- const DagInit *results = def.getValueAsDag("results");
+ DagInit *results = def.getValueAsDag("results");
return results->getNumArgs();
}
@@ -198,12 +198,12 @@ auto Operator::getResults() const -> const_value_range {
}
TypeConstraint Operator::getResultTypeConstraint(int index) const {
- const DagInit *results = def.getValueAsDag("results");
+ DagInit *results = def.getValueAsDag("results");
return TypeConstraint(cast<DefInit>(results->getArg(index)));
}
StringRef Operator::getResultName(int index) const {
- const DagInit *results = def.getValueAsDag("results");
+ DagInit *results = def.getValueAsDag("results");
return results->getArgNameStr(index);
}
@@ -241,7 +241,7 @@ Operator::arg_range Operator::getArgs() const {
}
StringRef Operator::getArgName(int index) const {
- const DagInit *argumentValues = def.getValueAsDag("arguments");
+ DagInit *argumentValues = def.getValueAsDag("arguments");
return argumentValues->getArgNameStr(index);
}
@@ -557,7 +557,7 @@ void Operator::populateOpStructure() {
auto *opVarClass = recordKeeper.getClass("OpVariable");
numNativeAttributes = 0;
- const DagInit *argumentValues = def.getValueAsDag("arguments");
+ DagInit *argumentValues = def.getValueAsDag("arguments");
unsigned numArgs = argumentValues->getNumArgs();
// Mapping from name of to argument or result index. Arguments are indexed
@@ -721,8 +721,8 @@ void Operator::populateOpStructure() {
" to precede it in traits list");
};
- std::function<void(const llvm::ListInit *)> insert;
- insert = [&](const llvm::ListInit *traitList) {
+ std::function<void(llvm::ListInit *)> insert;
+ insert = [&](llvm::ListInit *traitList) {
for (auto *traitInit : *traitList) {
auto *def = cast<DefInit>(traitInit)->getDef();
if (def->isSubClassOf("TraitList")) {
@@ -780,7 +780,7 @@ void Operator::populateOpStructure() {
auto *builderList =
dyn_cast_or_null<llvm::ListInit>(def.getValueInit("builders"));
if (builderList && !builderList->empty()) {
- for (const llvm::Init *init : builderList->getValues())
+ for (llvm::Init *init : builderList->getValues())
builders.emplace_back(cast<llvm::DefInit>(init)->getDef(), def.getLoc());
} else if (skipDefaultBuilders()) {
PrintFatalError(
@@ -818,8 +818,7 @@ bool Operator::hasAssemblyFormat() const {
}
StringRef Operator::getAssemblyFormat() const {
- return TypeSwitch<const llvm::Init *, StringRef>(
- def.getValueInit("assemblyFormat"))
+ return TypeSwitch<llvm::Init *, StringRef>(def.getValueInit("assemblyFormat"))
.Case<llvm::StringInit>([&](auto *init) { return init->getValue(); });
}
@@ -833,7 +832,7 @@ void Operator::print(llvm::raw_ostream &os) const {
}
}
-auto Operator::VariableDecoratorIterator::unwrap(const llvm::Init *init)
+auto Operator::VariableDecoratorIterator::unwrap(llvm::Init *init)
-> VariableDecorator {
return VariableDecorator(cast<llvm::DefInit>(init)->getDef());
}
diff --git a/mlir/lib/TableGen/Pattern.cpp b/mlir/lib/TableGen/Pattern.cpp
index bee20354387fd6..6437839ef20849 100644
--- a/mlir/lib/TableGen/Pattern.cpp
+++ b/mlir/lib/TableGen/Pattern.cpp
@@ -700,7 +700,7 @@ int Pattern::getBenefit() const {
// The initial benefit value is a heuristic with number of ops in the source
// pattern.
int initBenefit = getSourcePattern().getNumOps();
- const llvm::DagInit *delta = def.getValueAsDag("benefitDelta");
+ llvm::DagInit *delta = def.getValueAsDag("benefitDelta");
if (delta->getNumArgs() != 1 || !isa<llvm::IntInit>(delta->getArg(0))) {
PrintFatalError(&def,
"The 'addBenefit' takes and only takes one integer value");
diff --git a/mlir/lib/TableGen/Type.cpp b/mlir/lib/TableGen/Type.cpp
index c3b813ec598d0a..cda752297988bb 100644
--- a/mlir/lib/TableGen/Type.cpp
+++ b/mlir/lib/TableGen/Type.cpp
@@ -50,7 +50,7 @@ std::optional<StringRef> TypeConstraint::getBuilderCall() const {
const llvm::RecordVal *builderCall = baseType->getValue("builderCall");
if (!builderCall || !builderCall->getValue())
return std::nullopt;
- return TypeSwitch<const llvm::Init *, std::optional<StringRef>>(
+ return TypeSwitch<llvm::Init *, std::optional<StringRef>>(
builderCall->getValue())
.Case<llvm::StringInit>([&](auto *init) {
StringRef value = init->getValue();
diff --git a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
index 20ad4292a548bf..7119324dd125d5 100644
--- a/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
+++ b/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
@@ -30,8 +30,8 @@ enum DeprecatedAction { None, Warn, Error };
static DeprecatedAction actionOnDeprecatedValue;
// Returns if there is a use of `deprecatedInit` in `field`.
-static bool findUse(const Init *field, const Init *deprecatedInit,
- llvm::DenseMap<const Init *, bool> &known) {
+static bool findUse(Init *field, Init *deprecatedInit,
+ llvm::DenseMap<Init *, bool> &known) {
if (field == deprecatedInit)
return true;
@@ -64,13 +64,13 @@ static bool findUse(const Init *field, const Init *deprecatedInit,
if (findUse(dagInit->getOperator(), deprecatedInit, known))
return memoize(true);
- return memoize(llvm::any_of(dagInit->getArgs(), [&](const Init *arg) {
+ return memoize(llvm::any_of(dagInit->getArgs(), [&](Init *arg) {
return findUse(arg, deprecatedInit, known);
}));
}
- if (const ListInit *li = dyn_cast<ListInit>(field)) {
- return memoize(llvm::any_of(li->getValues(), [&](const Init *jt) {
+ if (ListInit *li = dyn_cast<ListInit>(field)) {
+ return memoize(llvm::any_of(li->getValues(), [&](Init *jt) {
return findUse(jt, deprecatedInit, known);
}));
}
@@ -83,8 +83,8 @@ static bool findUse(const Init *field, const Init *deprecatedInit,
}
// Returns if there is a use of `deprecatedInit` in `record`.
-static bool findUse(Record &record, const Init *deprecatedInit,
- llvm::DenseMap<const Init *, bool> &known) {
+static bool findUse(Record &record, Init *deprecatedInit,
+ llvm::DenseMap<Init *, bool> &known) {
return llvm::any_of(record.getValues(), [&](const RecordVal &val) {
return findUse(val.getValue(), deprecatedInit, known);
});
@@ -100,7 +100,7 @@ static void warnOfDeprecatedUses(const RecordKeeper &records) {
if (!r || !r->getValue())
continue;
- llvm::DenseMap<const Init *, bool> hasUse;
+ llvm::DenseMap<Init *, bool> hasUse;
if (auto *si = dyn_cast<StringInit>(r->getValue())) {
for (auto &jt : records.getDefs()) {
// Skip anonymous defs.
diff --git a/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp b/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
index 6a3d5a25e28cd9..86ebaf2cf27dfe 100644
--- a/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
+++ b/mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp
@@ -46,9 +46,8 @@ class Generator {
private:
/// Emits parse calls to construct given kind.
void emitParseHelper(StringRef kind, StringRef returnType, StringRef builder,
- ArrayRef<const Init *> args,
- ArrayRef<std::string> argNames, StringRef failure,
- mlir::raw_indented_ostream &ios);
+ ArrayRef<Init *> args, ArrayRef<std::string> argNames,
+ StringRef failure, mlir::raw_indented_ostream &ios);
/// Emits print instructions.
void emitPrintHelper(const Record *memberRec, StringRef kind,
@@ -136,12 +135,10 @@ void Generator::emitParse(StringRef kind, const Record &x) {
R"(static {0} read{1}(MLIRContext* context, DialectBytecodeReader &reader) )";
mlir::raw_indented_ostream os(output);
std::string returnType = getCType(&x);
- os << formatv(head,
- kind == "attribute" ? "::mlir::Attribute" : "::mlir::Type",
- x.getName());
- const DagInit *members = x.getValueAsDag("members");
- SmallVector<std::string> argNames = llvm::to_vector(
- map_range(members->getArgNames(), [](const StringInit *init) {
+ os << formatv(head, kind == "attribute" ? "::mlir::Attribute" : "::mlir::Type", x.getName());
+ DagInit *members = x.getValueAsDag("members");
+ SmallVector<std::string> argNames =
+ llvm::to_vector(map_range(members->getArgNames(), [](StringInit *init) {
return init->getAsUnquotedString();
}));
StringRef builder = x.getValueAsString("cBuilder").trim();
@@ -151,7 +148,7 @@ void Generator::emitParse(StringRef kind, const Record &x) {
}
void printParseConditional(mlir::raw_indented_ostream &ios,
- ArrayRef<const Init *> args,
+ ArrayRef<Init *> args,
ArrayRef<std::string> argNames) {
ios << "if ";
auto parenScope = ios.scope("(", ") {");
@@ -162,7 +159,7 @@ void printParseConditional(mlir::raw_indented_ostream &ios,
};
auto parsedArgs =
- llvm::to_vector(make_filter_range(args, [](const Init *const attr) {
+ llvm::to_vector(make_filter_range(args, [](Init *const attr) {
const Record *def = cast<DefInit>(attr)->getDef();
if (def->isSubClassOf("Array"))
return true;
@@ -171,7 +168,7 @@ void printParseConditional(mlir::raw_indented_ostream &ios,
interleave(
zip(parsedArgs, argNames),
- [&](std::tuple<const Init *&, const std::string &> it) {
+ [&](std::tuple<llvm::Init *&, const std::string &> it) {
const Record *attr = cast<DefInit>(std::get<0>(it))->getDef();
std::string parser;
if (auto optParser = attr->getValueAsOptionalString("cParser")) {
@@ -199,7 +196,7 @@ void printParseConditional(mlir::raw_indented_ostream &ios,
}
void Generator::emitParseHelper(StringRef kind, StringRef returnType,
- StringRef builder, ArrayRef<const Init *> args,
+ StringRef builder, ArrayRef<Init *> args,
ArrayRef<std::string> argNames,
StringRef failure,
mlir::raw_indented_ostream &ios) {
@@ -213,7 +210,7 @@ void Generator::emitParseHelper(StringRef kind, StringRef returnType,
// Print decls.
std::string lastCType = "";
for (auto [arg, name] : zip(args, argNames)) {
- const DefInit *first = dyn_cast<DefInit>(arg);
+ DefInit *first = dyn_cast<DefInit>(arg);
if (!first)
PrintFatalError("Unexpected type for " + name);
const Record *def = first->getDef();
@@ -254,14 +251,13 @@ void Generator::emitParseHelper(StringRef kind, StringRef returnType,
std::string returnType = getCType(def);
ios << "auto " << listHelperName(name) << " = [&]() -> FailureOr<"
<< returnType << "> ";
- SmallVector<const Init *> args;
+ SmallVector<Init *> args;
SmallVector<std::string> argNames;
if (def->isSubClassOf("CompositeBytecode")) {
- const DagInit *members = def->getValueAsDag("members");
- args = llvm::to_vector(map_range(
- members->getArgs(), [](Init *init) { return (const Init *)init; }));
+ DagInit *members = def->getValueAsDag("members");
+ args = llvm::to_vector(members->getArgs());
argNames = llvm::to_vector(
- map_range(members->getArgNames(), [](const StringInit *init) {
+ map_range(members->getArgNames(), [](StringInit *init) {
return init->getAsUnquotedString();
}));
} else {
@@ -336,7 +332,7 @@ void Generator::emitPrint(StringRef kind, StringRef type,
auto *members = rec->getValueAsDag("members");
for (auto [arg, name] :
llvm::zip(members->getArgs(), members->getArgNames())) {
- const DefInit *def = dyn_cast<DefInit>(arg);
+ DefInit *def = dyn_cast<DefInit>(arg);
assert(def);
const Record *memberRec = def->getDef();
emitPrintHelper(memberRec, kind, kind, name->getAsUnquotedString(), os);
@@ -389,7 +385,7 @@ void Generator::emitPrintHelper(const Record *memberRec, StringRef kind,
auto *members = memberRec->getValueAsDag("members");
for (auto [arg, argName] :
zip(members->getArgs(), members->getArgNames())) {
- const DefInit *def = dyn_cast<DefInit>(arg);
+ DefInit *def = dyn_cast<DefInit>(arg);
assert(def);
emitPrintHelper(def->getDef(), kind, parent,
argName->getAsUnquotedString(), ios);
diff --git a/mlir/tools/mlir-tblgen/DialectGen.cpp b/mlir/tools/mlir-tblgen/DialectG...
[truncated]
|
Thanks @joker-eph. This fell through the cracks after I initially observed the failure. Let me try to reproduce locally |
jurahul
added a commit
to jurahul/llvm-project
that referenced
this pull request
Oct 16, 2024
…` objects" (llvm#112506)" This reverts commit 0eed305.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
mlir:core
MLIR Core Infrastructure
mlir
skip-precommit-approval
PR for CI feedback, not intended for review
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #112316
Bots are failing.