Skip to content

Commit

Permalink
Change all 'Init' pointers to const
Browse files Browse the repository at this point in the history
This change reflect upstream change:
llvm/llvm-project#112705
  • Loading branch information
mariusz-sikora-at-amd authored and Flakebi committed Oct 24, 2024
1 parent 052d8b8 commit 50e4ca3
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 53 deletions.
21 changes: 12 additions & 9 deletions include/llvm-dialects/TableGen/Constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ class ConstraintSystem {

llvm::ArrayRef<Variable *> 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);
Expand Down Expand Up @@ -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<Variable *> variables() const { return m_variables; }

Expand All @@ -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).
Expand Down Expand Up @@ -178,13 +179,15 @@ class LogicOr : public Constraint {
void print(llvm::raw_ostream &out, llvm::StringRef prefix) const override;

llvm::ArrayRef<ConstraintSystem> branches() const { return m_branches; }
llvm::ArrayRef<llvm::Init *> branchInits() const { return m_branchInits; }
llvm::ArrayRef<const llvm::Init *> branchInits() const {
return m_branchInits;
}

private:
std::vector<ConstraintSystem> m_branches;

/// Only for error messages.
std::vector<llvm::Init *> m_branchInits;
std::vector<const llvm::Init *> m_branchInits;
};

class MetaType {
Expand Down Expand Up @@ -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; }
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion include/llvm-dialects/TableGen/DialectType.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<NamedValue> typeArguments() const {
return arguments().drop_front(1);
Expand Down
15 changes: 8 additions & 7 deletions include/llvm-dialects/TableGen/Dialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,28 @@ class GenDialectsContext {
const llvm::DenseSet<llvm::StringRef> &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;
GenDialectsContext &operator=(const GenDialectsContext &rhs) = delete;
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<RecordTy *, std::unique_ptr<Trait>> m_traits;
llvm::DenseMap<llvm::Init *, std::unique_ptr<Predicate>> m_predicates;
llvm::DenseMap<const llvm::Init *, std::unique_ptr<Predicate>> m_predicates;
llvm::DenseMap<RecordTy *, std::unique_ptr<Attr>> m_attrs;
llvm::DenseMap<RecordTy *, std::unique_ptr<OpClass>> m_opClasses;
llvm::DenseMap<RecordTy *, std::unique_ptr<GenDialect>> m_dialects;
Expand Down
2 changes: 1 addition & 1 deletion include/llvm-dialects/TableGen/Evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions include/llvm-dialects/TableGen/NamedValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,7 +52,7 @@ struct NamedValue {

static std::optional<std::vector<NamedValue>>
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;
};
Expand Down
14 changes: 7 additions & 7 deletions include/llvm-dialects/TableGen/Predicates.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class Predicate {

static std::unique_ptr<Predicate> 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<NamedValue> arguments() const { return m_arguments; }
bool canDerive(unsigned argumentIndex) const {
assert(argumentIndex < m_canDerive.size());
Expand All @@ -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<NamedValue> m_arguments;

/// Whether the constraint can be fully checked given only the "self"
Expand All @@ -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<Variable *> variables() const { return m_variables; }
Expand Down Expand Up @@ -122,15 +122,15 @@ 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 {
public:
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
15 changes: 5 additions & 10 deletions lib/TableGen/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<DagInit>(init)) {
RecordTy *op = dag->getOperatorAsDef({});
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -165,12 +165,7 @@ bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, Init *init,
result->m_self = self;

auto *dag = dyn_cast<DagInit>(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)
Expand Down
2 changes: 1 addition & 1 deletion lib/TableGen/DialectType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions lib/TableGen/Dialects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/TableGen/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
4 changes: 2 additions & 2 deletions lib/TableGen/NamedValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace llvm_dialects;

std::optional<std::vector<NamedValue>>
NamedValue::parseList(raw_ostream &errs, GenDialectsContext &context,
DagInit *init, unsigned begin, Parser mode) {
const DagInit *init, unsigned begin, Parser mode) {
std::vector<NamedValue> values;
bool isOperation =
mode == Parser::OperationArguments || mode == Parser::OperationResults;
Expand All @@ -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<UnsetInit>(valueInit)) {
errs << "Type/constraint missing for $" << value.name
<< " in: " << init->getAsString() << '\n';
Expand Down
8 changes: 4 additions & 4 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static std::optional<std::vector<NamedValue>>
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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/TableGen/Predicates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace llvm_dialects;

std::unique_ptr<Predicate> Predicate::parse(raw_ostream &errs,
GenDialectsContext &context,
Init *theInit) {
const Init *theInit) {
std::unique_ptr<Predicate> result;
if (isa<IntInit>(theInit)) {
result = std::make_unique<Constant>();
Expand Down Expand Up @@ -69,7 +69,7 @@ std::unique_ptr<Predicate> 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<DefInit>(theInit)) {
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 50e4ca3

Please sign in to comment.