Skip to content

Commit

Permalink
Make Record * members const
Browse files Browse the repository at this point in the history
`TableGenFnMain` was changed to pass a `const RecordKeeper &`, so
reflect that change in ´llvm-dialects`
  • Loading branch information
Thomas Symalla committed Oct 2, 2024
1 parent bdfb113 commit 4990dd2
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 47 deletions.
4 changes: 2 additions & 2 deletions include/llvm-dialects/TableGen/Constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Attr : public MetaType {

static std::unique_ptr<Attr> parse(llvm::raw_ostream &errs,
GenDialectsContext &context,
llvm::Record *record);
const llvm::Record *record);

llvm::StringRef getName() const;
llvm::StringRef getCppType() const { return m_cppType; }
Expand All @@ -243,7 +243,7 @@ class Attr : public MetaType {
}

private:
llvm::Record *m_record = nullptr;
const llvm::Record *m_record = nullptr;
std::string m_cppType;
llvm::Init *m_llvmType = nullptr;
std::string m_toLlvmValue;
Expand Down
18 changes: 9 additions & 9 deletions include/llvm-dialects/TableGen/Dialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Trait;

class GenDialect {
public:
llvm::Record *record;
const llvm::Record *record;
std::string cppName;
std::string name;
std::string cppNamespace;
Expand All @@ -69,14 +69,14 @@ class GenDialectsContext {
GenDialectsContext();
~GenDialectsContext();

void init(llvm::RecordKeeper &records,
void init(const llvm::RecordKeeper &records,
const llvm::DenseSet<llvm::StringRef> &dialects);

Trait *getTrait(llvm::Record *traitRec);
Trait *getTrait(const llvm::Record *traitRec);
Predicate *getPredicate(llvm::Init *init, llvm::raw_ostream &errs);
Attr *getAttr(llvm::Record *record, llvm::raw_ostream &errs);
OpClass *getOpClass(llvm::Record *opClassRec);
GenDialect *getDialect(llvm::Record *dialectRec);
OpClass *getOpClass(const llvm::Record *opClassRec);
GenDialect *getDialect(const llvm::Record *dialectRec);

llvm::Init *getVoidTy() const { return m_voidTy; }
llvm::Init *getAny() const { return m_any; }
Expand All @@ -92,11 +92,11 @@ class GenDialectsContext {
llvm::Init *m_voidTy = nullptr;
llvm::Init *m_any = nullptr;
bool m_attrsComplete = false;
llvm::DenseMap<llvm::Record *, std::unique_ptr<Trait>> m_traits;
llvm::DenseMap<const llvm::Record *, std::unique_ptr<Trait>> m_traits;
llvm::DenseMap<llvm::Init *, std::unique_ptr<Predicate>> m_predicates;
llvm::DenseMap<llvm::Record *, std::unique_ptr<Attr>> m_attrs;
llvm::DenseMap<llvm::Record *, std::unique_ptr<OpClass>> m_opClasses;
llvm::DenseMap<llvm::Record *, std::unique_ptr<GenDialect>> m_dialects;
llvm::DenseMap<const llvm::Record *, std::unique_ptr<Attr>> m_attrs;
llvm::DenseMap<const llvm::Record *, std::unique_ptr<OpClass>> m_opClasses;
llvm::DenseMap<const llvm::Record *, std::unique_ptr<GenDialect>> m_dialects;
};

} // namespace llvm_dialects
4 changes: 2 additions & 2 deletions include/llvm-dialects/TableGen/GenDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RecordKeeper;

namespace llvm_dialects {

void genDialectDecls(llvm::raw_ostream& out, llvm::RecordKeeper& records);
void genDialectDefs(llvm::raw_ostream& out, llvm::RecordKeeper& records);
void genDialectDecls(llvm::raw_ostream &out, const llvm::RecordKeeper &records);
void genDialectDefs(llvm::raw_ostream &out, const llvm::RecordKeeper &records);

} // namespace llvm_dialects
6 changes: 3 additions & 3 deletions include/llvm-dialects/TableGen/Operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class OperationBase {

protected:
bool init(llvm::raw_ostream &errs, GenDialectsContext &context,
llvm::Record *record);
const llvm::Record *record);

/// Records if this Operation has a variadic argument
bool m_hasVariadicArgument = false;
Expand All @@ -93,7 +93,7 @@ class OpClass : public OperationBase {

static std::unique_ptr<OpClass> parse(llvm::raw_ostream &errs,
GenDialectsContext &context,
llvm::Record *record);
const llvm::Record *record);
};

class Operation : public OperationBase {
Expand All @@ -110,7 +110,7 @@ class Operation : public OperationBase {
~Operation();

static bool parse(llvm::raw_ostream &errs, GenDialectsContext *context,
GenDialect *dialect, llvm::Record *record);
GenDialect *dialect, const llvm::Record *record);

bool haveResultOverloads() const { return m_haveResultOverloads; }
bool haveArgumentOverloads() const { return m_haveArgumentOverloads; }
Expand Down
8 changes: 4 additions & 4 deletions include/llvm-dialects/TableGen/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ class Trait {
};

static std::unique_ptr<Trait> fromRecord(GenDialectsContext *context,
llvm::Record *record);
const llvm::Record *record);

virtual ~Trait() = default;

virtual void init(GenDialectsContext *context, llvm::Record *record);
virtual void init(GenDialectsContext *context, const llvm::Record *record);

Kind getKind() const { return m_kind; }
llvm::Record *getRecord() const { return m_record; }
const llvm::Record *getRecord() const { return m_record; }
llvm::StringRef getName() const;

protected:
Trait(Kind kind) : m_kind(kind) {}

private:
const Kind m_kind;
llvm::Record *m_record = nullptr;
const llvm::Record *m_record = nullptr;
};

class LlvmAttributeTrait : public Trait {
Expand Down
3 changes: 2 additions & 1 deletion lib/TableGen/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ StringRef MetaType::getName() const {
}

std::unique_ptr<Attr> Attr::parse(raw_ostream &errs,
GenDialectsContext &context, Record *record) {
GenDialectsContext &context,
const Record *record) {
if (!record->isSubClassOf("Attr")) {
errs << record->getName() << ": must be a subclass of Attr\n";
return {};
Expand Down
20 changes: 11 additions & 9 deletions lib/TableGen/Dialects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void GenDialect::finalize(raw_ostream &errs) {
GenDialectsContext::GenDialectsContext() = default;
GenDialectsContext::~GenDialectsContext() = default;

Trait *GenDialectsContext::getTrait(Record *traitRec) {
Trait *GenDialectsContext::getTrait(const Record *traitRec) {
if (!traitRec->isSubClassOf("Trait"))
report_fatal_error(Twine("Trying to use '") + traitRec->getName() +
"' as a trait, but it is not a subclass of 'Trait'");
Expand Down Expand Up @@ -126,7 +126,7 @@ Attr *GenDialectsContext::getAttr(llvm::Record *record,
return attr;
}

GenDialect *GenDialectsContext::getDialect(Record *dialectRec) {
GenDialect *GenDialectsContext::getDialect(const Record *dialectRec) {
if (!dialectRec->isSubClassOf("Dialect"))
report_fatal_error(Twine("Trying to use '") + dialectRec->getName() +
"' as a dialect, but it is not a subclass of 'Dialect'");
Expand All @@ -140,7 +140,7 @@ GenDialect *GenDialectsContext::getDialect(Record *dialectRec) {
return it->second.get();
}

OpClass *GenDialectsContext::getOpClass(Record *opClassRec) {
OpClass *GenDialectsContext::getOpClass(const Record *opClassRec) {
if (opClassRec->getName() == "NoSuperClass")
return nullptr;

Expand Down Expand Up @@ -172,17 +172,18 @@ OpClass *GenDialectsContext::getOpClass(Record *opClassRec) {
return opClass;
}

void GenDialectsContext::init(RecordKeeper &records,
void GenDialectsContext::init(const RecordKeeper &records,
const DenseSet<StringRef> &dialects) {
for (Record *record : records.getAllDerivedDefinitions("Attr")) {
for (const Record *record : records.getAllDerivedDefinitions("Attr")) {
auto owner = Attr::parse(llvm::errs(), *this, record);
if (!record)
report_fatal_error(Twine("Error parsing Attr ") + record->getName());

m_attrs.try_emplace(record, std::move(owner));
}

for (Record *record : records.getAllDerivedDefinitions("AttrLlvmType")) {
for (const Record *record :
records.getAllDerivedDefinitions("AttrLlvmType")) {
Attr *attr = getAttr(record->getValueAsDef("attr"), llvm::errs());
assert(attr);
attr->setLlvmType(record->getValueInit("llvmType"));
Expand All @@ -193,7 +194,7 @@ void GenDialectsContext::init(RecordKeeper &records,
m_any = records.getDef("any")->getDefInit();
assert(m_voidTy && m_any);

for (Record *dialectRec : records.getAllDerivedDefinitions("Dialect")) {
for (const Record *dialectRec : records.getAllDerivedDefinitions("Dialect")) {
auto name = dialectRec->getValueAsString("name");
if (!dialects.contains(name))
continue;
Expand All @@ -206,7 +207,8 @@ void GenDialectsContext::init(RecordKeeper &records,
m_dialects.insert(std::make_pair(dialectRec, std::move(dialect)));
}

for (Record *typeRec : records.getAllDerivedDefinitions("DialectType")) {
for (const Record *typeRec :
records.getAllDerivedDefinitions("DialectType")) {
auto *dialectType =
cast<DialectType>(getPredicate(typeRec->getDefInit(), llvm::errs()));
if (!dialectType) {
Expand All @@ -218,7 +220,7 @@ void GenDialectsContext::init(RecordKeeper &records,
dialectIt->second->types.push_back(dialectType);
}

for (Record *opRec : records.getAllDerivedDefinitions("Op")) {
for (const Record *opRec : records.getAllDerivedDefinitions("Op")) {
Record *dialectRec = opRec->getValueAsDef("dialect");
auto dialectIt = m_dialects.find(dialectRec);
if (dialectIt == m_dialects.end())
Expand Down
10 changes: 6 additions & 4 deletions lib/TableGen/GenDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cl::opt<std::string> g_dialect("dialect", cl::desc("the dialect to generate"), c
} // anonymous namespace

static std::pair<std::unique_ptr<GenDialectsContext>, GenDialect *>
getSelectedDialect(RecordKeeper &records) {
getSelectedDialect(const RecordKeeper &records) {
if (g_dialect.empty())
report_fatal_error(Twine("Must select a dialect using the --dialect option"));

Expand All @@ -51,7 +51,7 @@ getSelectedDialect(RecordKeeper &records) {

context->init(records, dialects);

for (Record* dialectRec : records.getAllDerivedDefinitions("Dialect")) {
for (const Record *dialectRec : records.getAllDerivedDefinitions("Dialect")) {
if (dialectRec->getValueAsString("name") == g_dialect) {
GenDialect *selectedDialect = context->getDialect(dialectRec);
return {std::move(context), selectedDialect};
Expand All @@ -61,7 +61,8 @@ getSelectedDialect(RecordKeeper &records) {
report_fatal_error(Twine("Could not find dialect. Check the '--dialect' option."));
}

void llvm_dialects::genDialectDecls(raw_ostream& out, RecordKeeper& records) {
void llvm_dialects::genDialectDecls(raw_ostream &out,
const RecordKeeper &records) {
auto [context, dialect] = getSelectedDialect(records);

emitHeader(out);
Expand Down Expand Up @@ -218,7 +219,8 @@ class Builder;
)";
}

void llvm_dialects::genDialectDefs(raw_ostream& out, RecordKeeper& records) {
void llvm_dialects::genDialectDefs(raw_ostream &out,
const RecordKeeper &records) {
auto [contextPtr, dialect] = getSelectedDialect(records);
auto &genDialectsContext = *contextPtr;

Expand Down
14 changes: 8 additions & 6 deletions lib/TableGen/Operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ static std::string evaluateAttrLlvmType(raw_ostream &errs, raw_ostream &out,
SymbolTable &symbols);

static std::optional<std::vector<NamedValue>>
parseArguments(raw_ostream &errs, GenDialectsContext &context, Record *rec) {
parseArguments(raw_ostream &errs, GenDialectsContext &context,
const Record *rec) {
Record *superClassRec = rec->getValueAsDef("superclass");
OpClass *superclass = context.getOpClass(superClassRec);
DagInit *argsInit = rec->getValueAsDag("arguments");
Expand Down Expand Up @@ -78,7 +79,7 @@ class AccessorBuilder final {
} // namespace

bool OperationBase::init(raw_ostream &errs, GenDialectsContext &context,
Record *record) {
const Record *record) {
m_dialect = context.getDialect(record->getValueAsDef("dialect"));
m_superclass = context.getOpClass(record->getValueAsDef("superclass"));

Expand Down Expand Up @@ -280,8 +281,9 @@ void OperationBase::emitArgumentAccessorDefinitions(llvm::raw_ostream &out,
}
}

std::unique_ptr<OpClass>
OpClass::parse(raw_ostream &errs, GenDialectsContext &context, Record *record) {
std::unique_ptr<OpClass> OpClass::parse(raw_ostream &errs,
GenDialectsContext &context,
const Record *record) {
auto opClass = std::make_unique<OpClass>();
opClass->name = record->getName();

Expand Down Expand Up @@ -329,7 +331,7 @@ Operation::Operation(GenDialectsContext &context) : m_system(context, m_scope) {
Operation::~Operation() = default;

bool Operation::parse(raw_ostream &errs, GenDialectsContext *context,
GenDialect *dialect, Record *record) {
GenDialect *dialect, const Record *record) {
auto op = std::make_unique<Operation>(*context);

if (!op->init(errs, *context, record))
Expand All @@ -342,7 +344,7 @@ bool Operation::parse(raw_ostream &errs, GenDialectsContext *context,

op->name = record->getName();
op->mnemonic = record->getValueAsString("mnemonic");
for (Record *traitRec : record->getValueAsListOfDefs("traits"))
for (const Record *traitRec : record->getValueAsListOfDefs("traits"))
op->traits.push_back(context->getTrait(traitRec));

EvaluationPlanner evaluation(op->m_system);
Expand Down
13 changes: 7 additions & 6 deletions lib/TableGen/Traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class LlvmEnumAttributeTrait : public LlvmAttributeTrait {
public:
LlvmEnumAttributeTrait() : LlvmAttributeTrait(Kind::LlvmEnumAttributeTrait) {}

void init(GenDialectsContext *context, llvm::Record *record) override;
void init(GenDialectsContext *context, const llvm::Record *record) override;

void addAttribute(llvm::raw_ostream &out, FmtContext &fmt) const override;

Expand All @@ -54,7 +54,7 @@ class LlvmMemoryAttributeTrait : public LlvmAttributeTrait {
LlvmMemoryAttributeTrait()
: LlvmAttributeTrait(Kind::LlvmMemoryAttributeTrait) {}

void init(GenDialectsContext *context, llvm::Record *record) override;
void init(GenDialectsContext *context, const llvm::Record *record) override;

void addAttribute(llvm::raw_ostream &out, FmtContext &fmt) const override;

Expand All @@ -80,7 +80,7 @@ bool llvm_dialects::noMemoryEffects() {
}

std::unique_ptr<Trait> Trait::fromRecord(GenDialectsContext *context,
llvm::Record *traitRec) {
const llvm::Record *traitRec) {
std::unique_ptr<Trait> result;
if (traitRec->isSubClassOf("LlvmEnumAttributeTrait")) {
result = std::make_unique<LlvmEnumAttributeTrait>();
Expand All @@ -93,13 +93,14 @@ std::unique_ptr<Trait> Trait::fromRecord(GenDialectsContext *context,
return result;
}

void Trait::init(GenDialectsContext *context, Record *record) {
void Trait::init(GenDialectsContext *context, const Record *record) {
m_record = record;
}

StringRef Trait::getName() const { return m_record->getName(); }

void LlvmEnumAttributeTrait::init(GenDialectsContext *context, Record *record) {
void LlvmEnumAttributeTrait::init(GenDialectsContext *context,
const Record *record) {
LlvmAttributeTrait::init(context, record);
m_llvmEnum = record->getValueAsString("llvmEnum");
}
Expand All @@ -111,7 +112,7 @@ void LlvmEnumAttributeTrait::addAttribute(raw_ostream &out,
}

void LlvmMemoryAttributeTrait::init(GenDialectsContext *context,
llvm::Record *record) {
const llvm::Record *record) {
LlvmAttributeTrait::init(context, record);

auto *effects = record->getValueAsListInit("effects");
Expand Down
2 changes: 1 addition & 1 deletion utils/llvm-dialects-tblgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cl::opt<Action> g_action(
"Generate dialect definitions (.cpp.inc)")
));

bool llvmDialectsTableGenMain(raw_ostream& out, RecordKeeper& records) {
bool llvmDialectsTableGenMain(raw_ostream &out, const RecordKeeper &records) {
switch (g_action) {
case Action::PrintRecords:
// Redundant with llvm-tblgen, but may be convenient for users.
Expand Down

0 comments on commit 4990dd2

Please sign in to comment.