From 50e4ca3a5c365b0bde36b122cc34256406723049 Mon Sep 17 00:00:00 2001 From: Mariusz Sikora Date: Wed, 23 Oct 2024 14:45:00 -0400 Subject: [PATCH] Change all 'Init' pointers to const This change reflect upstream change: https://github.com/llvm/llvm-project/pull/112705 --- include/llvm-dialects/TableGen/Constraints.h | 21 +++++++++++--------- include/llvm-dialects/TableGen/DialectType.h | 2 +- include/llvm-dialects/TableGen/Dialects.h | 15 +++++++------- include/llvm-dialects/TableGen/Evaluator.h | 2 +- include/llvm-dialects/TableGen/NamedValue.h | 4 ++-- include/llvm-dialects/TableGen/Predicates.h | 14 ++++++------- lib/TableGen/Constraints.cpp | 15 +++++--------- lib/TableGen/DialectType.cpp | 2 +- lib/TableGen/Dialects.cpp | 6 ++++-- lib/TableGen/Evaluator.cpp | 2 +- lib/TableGen/NamedValue.cpp | 4 ++-- lib/TableGen/Operations.cpp | 8 ++++---- lib/TableGen/Predicates.cpp | 12 +++++------ 13 files changed, 54 insertions(+), 53 deletions(-) diff --git a/include/llvm-dialects/TableGen/Constraints.h b/include/llvm-dialects/TableGen/Constraints.h index f89aefb..b3bea23 100644 --- a/include/llvm-dialects/TableGen/Constraints.h +++ b/include/llvm-dialects/TableGen/Constraints.h @@ -76,14 +76,15 @@ class ConstraintSystem { llvm::ArrayRef variables() const { return m_variables; } - bool addConstraint(llvm::raw_ostream &errs, llvm::Init *init, Variable *self); + bool addConstraint(llvm::raw_ostream &errs, const llvm::Init *init, + Variable *self); void merge(ConstraintSystem &&rhs); void print(llvm::raw_ostream &out, llvm::StringRef prefix) const; void dump() const; private: - bool addConstraintImpl(llvm::raw_ostream &errs, llvm::Init *init, + bool addConstraintImpl(llvm::raw_ostream &errs, const llvm::Init *init, Variable *self); void addVariable(Variable *variable); void addGlobalVariable(Variable *variable); @@ -117,7 +118,7 @@ class Constraint { virtual void print(llvm::raw_ostream &out, llvm::StringRef prefix) const = 0; Kind getKind() const { return m_kind; } - llvm::Init *getInit() const { return m_init; } + const llvm::Init *getInit() const { return m_init; } Variable *getSelf() const { return m_self; } llvm::ArrayRef variables() const { return m_variables; } @@ -134,7 +135,7 @@ class Constraint { /// Only for error messages: The TableGen init (if any) from which this /// constraint was derived. - llvm::Init *m_init = nullptr; + const llvm::Init *m_init = nullptr; /// Only for error messages: The variable in the valued position that this /// constraint originally appeared in (if any). @@ -178,13 +179,15 @@ class LogicOr : public Constraint { void print(llvm::raw_ostream &out, llvm::StringRef prefix) const override; llvm::ArrayRef branches() const { return m_branches; } - llvm::ArrayRef branchInits() const { return m_branchInits; } + llvm::ArrayRef branchInits() const { + return m_branchInits; + } private: std::vector m_branches; /// Only for error messages. - std::vector m_branchInits; + std::vector m_branchInits; }; class MetaType { @@ -226,7 +229,7 @@ class Attr : public MetaType { llvm::StringRef getName() const; llvm::StringRef getCppType() const { return m_cppType; } - llvm::Init *getLlvmType() const { return m_llvmType; } + const llvm::Init *getLlvmType() const { return m_llvmType; } llvm::StringRef getToLlvmValue() const { return m_toLlvmValue; } llvm::StringRef getFromLlvmValue() const { return m_fromLlvmValue; } llvm::StringRef getToUnsigned() const { return m_toUnsigned; } @@ -236,7 +239,7 @@ class Attr : public MetaType { // Set the LLVMType once -- used during initialization to break a circular // dependency in how IntegerType is defined. - void setLlvmType(llvm::Init *llvmType) { + void setLlvmType(const llvm::Init *llvmType) { assert(!m_llvmType); assert(llvmType); m_llvmType = llvmType; @@ -245,7 +248,7 @@ class Attr : public MetaType { private: RecordTy *m_record = nullptr; std::string m_cppType; - llvm::Init *m_llvmType = nullptr; + const llvm::Init *m_llvmType = nullptr; std::string m_toLlvmValue; std::string m_fromLlvmValue; std::string m_toUnsigned; diff --git a/include/llvm-dialects/TableGen/DialectType.h b/include/llvm-dialects/TableGen/DialectType.h index 6a83de0..f7a725b 100644 --- a/include/llvm-dialects/TableGen/DialectType.h +++ b/include/llvm-dialects/TableGen/DialectType.h @@ -35,7 +35,7 @@ class DialectType : public BaseCppPredicate { } bool init(llvm::raw_ostream &errs, GenDialectsContext &context, - llvm::Init *theInit) override final; + const llvm::Init *theInit) override final; llvm::ArrayRef typeArguments() const { return arguments().drop_front(1); diff --git a/include/llvm-dialects/TableGen/Dialects.h b/include/llvm-dialects/TableGen/Dialects.h index 4999e1b..671baf9 100644 --- a/include/llvm-dialects/TableGen/Dialects.h +++ b/include/llvm-dialects/TableGen/Dialects.h @@ -74,13 +74,13 @@ class GenDialectsContext { const llvm::DenseSet &dialects); Trait *getTrait(RecordTy *traitRec); - Predicate *getPredicate(llvm::Init *init, llvm::raw_ostream &errs); + Predicate *getPredicate(const llvm::Init *init, llvm::raw_ostream &errs); Attr *getAttr(RecordTy *record, llvm::raw_ostream &errs); OpClass *getOpClass(RecordTy *opClassRec); GenDialect *getDialect(RecordTy *dialectRec); - llvm::Init *getVoidTy() const { return m_voidTy; } - llvm::Init *getAny() const { return m_any; } + const llvm::Init *getVoidTy() const { return m_voidTy; } + const llvm::Init *getAny() const { return m_any; } private: GenDialectsContext(const GenDialectsContext &rhs) = delete; @@ -88,13 +88,14 @@ class GenDialectsContext { GenDialectsContext(GenDialectsContext &&rhs) = delete; GenDialectsContext &operator=(GenDialectsContext &&rhs) = delete; - Predicate *getPredicateImpl(llvm::Init *record, llvm::raw_ostream &errs); + Predicate *getPredicateImpl(const llvm::Init *record, + llvm::raw_ostream &errs); - llvm::Init *m_voidTy = nullptr; - llvm::Init *m_any = nullptr; + const llvm::Init *m_voidTy = nullptr; + const llvm::Init *m_any = nullptr; bool m_attrsComplete = false; llvm::DenseMap> m_traits; - llvm::DenseMap> m_predicates; + llvm::DenseMap> m_predicates; llvm::DenseMap> m_attrs; llvm::DenseMap> m_opClasses; llvm::DenseMap> m_dialects; diff --git a/include/llvm-dialects/TableGen/Evaluator.h b/include/llvm-dialects/TableGen/Evaluator.h index 73a585e..0e94b8a 100644 --- a/include/llvm-dialects/TableGen/Evaluator.h +++ b/include/llvm-dialects/TableGen/Evaluator.h @@ -138,7 +138,7 @@ class Evaluator { bool checkApplyCapture(bool writeErrs, const Apply *apply); bool checkLogicOr(bool writeErrs, const LogicOr *logicOr); void checkAssignment(bool writeErrs, Variable *variable, std::string value, - llvm::Init *constraint); + const llvm::Init *constraint); }; } // namespace llvm_dialects diff --git a/include/llvm-dialects/TableGen/NamedValue.h b/include/llvm-dialects/TableGen/NamedValue.h index 34df040..e93693a 100644 --- a/include/llvm-dialects/TableGen/NamedValue.h +++ b/include/llvm-dialects/TableGen/NamedValue.h @@ -40,7 +40,7 @@ struct NamedValue { std::string name; /// The implied constraint on the value. - llvm::Init *constraint = nullptr; + const llvm::Init *constraint = nullptr; enum class Parser { ApplyArguments, @@ -52,7 +52,7 @@ struct NamedValue { static std::optional> parseList(llvm::raw_ostream &errs, GenDialectsContext &context, - llvm::DagInit *init, unsigned begin, Parser mode); + const llvm::DagInit *init, unsigned begin, Parser mode); std::string toString() const; }; diff --git a/include/llvm-dialects/TableGen/Predicates.h b/include/llvm-dialects/TableGen/Predicates.h index 5ea962c..1814c14 100644 --- a/include/llvm-dialects/TableGen/Predicates.h +++ b/include/llvm-dialects/TableGen/Predicates.h @@ -41,13 +41,13 @@ class Predicate { static std::unique_ptr parse(llvm::raw_ostream &errs, GenDialectsContext &context, - llvm::Init *theInit); + const llvm::Init *theInit); virtual bool init(llvm::raw_ostream &errs, GenDialectsContext &genContext, - llvm::Init *theInit); + const llvm::Init *theInit); Kind getKind() const { return m_kind; } - llvm::Init *getInit() const { return m_init; } + const llvm::Init *getInit() const { return m_init; } llvm::ArrayRef arguments() const { return m_arguments; } bool canDerive(unsigned argumentIndex) const { assert(argumentIndex < m_canDerive.size()); @@ -59,7 +59,7 @@ class Predicate { Predicate(Kind kind) : m_kind(kind) {} const Kind m_kind; - llvm::Init *m_init = nullptr; + const llvm::Init *m_init = nullptr; std::vector m_arguments; /// Whether the constraint can be fully checked given only the "self" @@ -82,7 +82,7 @@ class TgPredicate : public Predicate { } bool init(llvm::raw_ostream &errs, GenDialectsContext &genContext, - llvm::Init *theInit) override final; + const llvm::Init *theInit) override final; const ConstraintSystem &getSystem() const { return m_system; } llvm::ArrayRef variables() const { return m_variables; } @@ -122,7 +122,7 @@ class CppPredicate : public BaseCppPredicate { CppPredicate() : BaseCppPredicate(Kind::CppPredicate) {} bool init(llvm::raw_ostream &errs, GenDialectsContext &genContext, - llvm::Init *theInit) override final; + const llvm::Init *theInit) override final; }; class Constant : public BaseCppPredicate { @@ -130,7 +130,7 @@ class Constant : public BaseCppPredicate { Constant() : BaseCppPredicate(Kind::Constant) {} bool init(llvm::raw_ostream &errs, GenDialectsContext &genContext, - llvm::Init *theInit) override final; + const llvm::Init *theInit) override final; }; } // namespace llvm_dialects diff --git a/lib/TableGen/Constraints.cpp b/lib/TableGen/Constraints.cpp index acd77c5..bebfe1f 100644 --- a/lib/TableGen/Constraints.cpp +++ b/lib/TableGen/Constraints.cpp @@ -81,7 +81,7 @@ void ConstraintSystem::dump() const { print(dbgs(), " "); } -bool ConstraintSystem::addConstraint(raw_ostream &errs, Init *init, +bool ConstraintSystem::addConstraint(raw_ostream &errs, const Init *init, Variable *self) { if (!addConstraintImpl(errs, init, self)) { errs << ".. in " << init->getAsString() << '\n'; @@ -90,7 +90,7 @@ bool ConstraintSystem::addConstraint(raw_ostream &errs, Init *init, return true; } -bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, Init *init, +bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, const Init *init, Variable *self) { if (auto *dag = dyn_cast(init)) { RecordTy *op = dag->getOperatorAsDef({}); @@ -115,7 +115,7 @@ bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, Init *init, if (!isValidOperand(i, op->getName())) return false; - Init *operand = dag->getArg(i); + const Init *operand = dag->getArg(i); if (!addConstraint(errs, operand, self)) return false; } @@ -138,7 +138,7 @@ bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, Init *init, if (!isValidOperand(i, op->getName())) return false; - Init *operand = dag->getArg(i); + const Init *operand = dag->getArg(i); ConstraintSystem branchSystem(m_context, m_scope); if (!branchSystem.addConstraint(errs, operand, self)) return false; @@ -165,12 +165,7 @@ bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, Init *init, result->m_self = self; auto *dag = dyn_cast(init); - Init *predicateInit; - if (dag) { - predicateInit = dag->getOperator(); - } else { - predicateInit = init; - } + const Init *predicateInit = dag ? dag->getOperator() : init; result->m_predicate = m_context.getPredicate(predicateInit, errs); if (!result->m_predicate) diff --git a/lib/TableGen/DialectType.cpp b/lib/TableGen/DialectType.cpp index eee6f00..00a785d 100644 --- a/lib/TableGen/DialectType.cpp +++ b/lib/TableGen/DialectType.cpp @@ -26,7 +26,7 @@ using namespace llvm; using namespace llvm_dialects; bool DialectType::init(raw_ostream &errs, GenDialectsContext &context, - Init *theInit) { + const Init *theInit) { if (!BaseCppPredicate::init(errs, context, theInit)) return false; diff --git a/lib/TableGen/Dialects.cpp b/lib/TableGen/Dialects.cpp index 49129f4..a8fb0a5 100644 --- a/lib/TableGen/Dialects.cpp +++ b/lib/TableGen/Dialects.cpp @@ -88,14 +88,16 @@ Trait *GenDialectsContext::getTrait(RecordTy *traitRec) { return result.get(); } -Predicate *GenDialectsContext::getPredicate(Init *init, raw_ostream &errs) { +Predicate *GenDialectsContext::getPredicate(const Init *init, + raw_ostream &errs) { Predicate *op = getPredicateImpl(init, errs); if (!op) errs << "... while looking up predicate: " << init->getAsString() << '\n'; return op; } -Predicate *GenDialectsContext::getPredicateImpl(Init *init, raw_ostream &errs) { +Predicate *GenDialectsContext::getPredicateImpl(const Init *init, + raw_ostream &errs) { auto it = m_predicates.find(init); if (it != m_predicates.end()) { if (!it->second) diff --git a/lib/TableGen/Evaluator.cpp b/lib/TableGen/Evaluator.cpp index 773234b..2a49676 100644 --- a/lib/TableGen/Evaluator.cpp +++ b/lib/TableGen/Evaluator.cpp @@ -667,7 +667,7 @@ bool Evaluator::checkLogicOr(bool writeErrs, const LogicOr *logicOr) { } void Evaluator::checkAssignment(bool writeErrs, Variable *variable, - std::string value, Init *constraint) { + std::string value, const Init *constraint) { assert(variable); assert(!value.empty()); diff --git a/lib/TableGen/NamedValue.cpp b/lib/TableGen/NamedValue.cpp index c308e5e..673414a 100644 --- a/lib/TableGen/NamedValue.cpp +++ b/lib/TableGen/NamedValue.cpp @@ -26,7 +26,7 @@ using namespace llvm_dialects; std::optional> NamedValue::parseList(raw_ostream &errs, GenDialectsContext &context, - DagInit *init, unsigned begin, Parser mode) { + const DagInit *init, unsigned begin, Parser mode) { std::vector values; bool isOperation = mode == Parser::OperationArguments || mode == Parser::OperationResults; @@ -46,7 +46,7 @@ NamedValue::parseList(raw_ostream &errs, GenDialectsContext &context, return {}; } - Init *valueInit = init->getArg(i); + const Init *valueInit = init->getArg(i); if (mode != Parser::ApplyArguments && isa(valueInit)) { errs << "Type/constraint missing for $" << value.name << " in: " << init->getAsString() << '\n'; diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index d9c5ded..dcfd06b 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -35,7 +35,7 @@ static std::optional> parseArguments(raw_ostream &errs, GenDialectsContext &context, RecordTy *rec) { RecordTy *superClassRec = rec->getValueAsDef("superclass"); OpClass *superclass = context.getOpClass(superClassRec); - DagInit *argsInit = rec->getValueAsDag("arguments"); + const DagInit *argsInit = rec->getValueAsDag("arguments"); if (argsInit->getOperatorAsDef({})->getName() != "ins") { errs << "argument list operator must be 'ins'\n"; @@ -368,7 +368,7 @@ bool Operation::parse(raw_ostream &errs, GenDialectsContext *context, op->m_system.merge(std::move(singletonSystem)); } - DagInit *results = record->getValueAsDag("results"); + const DagInit *results = record->getValueAsDag("results"); if (results->getOperatorAsDef({})->getName() != "outs") { errs << "result list operator must be 'outs'\n"; return false; @@ -400,8 +400,8 @@ bool Operation::parse(raw_ostream &errs, GenDialectsContext *context, op->m_defaultBuilderHasExplicitResultType = record->getValueAsBit("defaultBuilderHasExplicitResultType"); - ListInit *verifier = record->getValueAsListInit("verifier"); - for (Init *constraint : *verifier) { + const ListInit *verifier = record->getValueAsListInit("verifier"); + for (const Init *constraint : *verifier) { if (!op->m_system.addConstraint(errs, constraint, nullptr)) return false; } diff --git a/lib/TableGen/Predicates.cpp b/lib/TableGen/Predicates.cpp index 4544ed7..37196de 100644 --- a/lib/TableGen/Predicates.cpp +++ b/lib/TableGen/Predicates.cpp @@ -29,7 +29,7 @@ using namespace llvm_dialects; std::unique_ptr Predicate::parse(raw_ostream &errs, GenDialectsContext &context, - Init *theInit) { + const Init *theInit) { std::unique_ptr result; if (isa(theInit)) { result = std::make_unique(); @@ -69,7 +69,7 @@ std::unique_ptr Predicate::parse(raw_ostream &errs, } bool Predicate::init(raw_ostream &errs, GenDialectsContext &genContext, - Init *theInit) { + const Init *theInit) { m_init = theInit; if (auto *defInit = dyn_cast(theInit)) { @@ -104,7 +104,7 @@ bool Predicate::init(raw_ostream &errs, GenDialectsContext &genContext, } bool TgPredicate::init(raw_ostream &errs, GenDialectsContext &genContext, - Init *theInit) { + const Init *theInit) { if (!Predicate::init(errs, genContext, theInit)) return false; @@ -113,7 +113,7 @@ bool TgPredicate::init(raw_ostream &errs, GenDialectsContext &genContext, for (const auto &argument : arguments()) m_variables.push_back(m_scope.getVariable(argument.name)); - DagInit *expression = record->getValueAsDag("expression"); + const DagInit *expression = record->getValueAsDag("expression"); if (!m_system.addConstraint(errs, expression, nullptr)) return false; @@ -151,7 +151,7 @@ bool TgPredicate::init(raw_ostream &errs, GenDialectsContext &genContext, } bool CppPredicate::init(raw_ostream &errs, GenDialectsContext &genContext, - Init *theInit) { + const Init *theInit) { if (!BaseCppPredicate::init(errs, genContext, theInit)) return false; @@ -187,7 +187,7 @@ bool CppPredicate::init(raw_ostream &errs, GenDialectsContext &genContext, } bool Constant::init(raw_ostream &errs, GenDialectsContext &context, - Init *theInit) { + const Init *theInit) { if (!BaseCppPredicate::init(errs, context, theInit)) return false;