Skip to content
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

Reflect upstream const changes #105

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions include/llvm-dialects/TableGen/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
#pragma once

#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Record.h"

#if !defined(LLVM_MAIN_REVISION) || LLVM_MAIN_REVISION >= 513628
using RecordKeeperTy = const llvm::RecordKeeper;
using RecordTy = const llvm::Record;
#else
using RecordKeeperTy = llvm::RecordKeeper;
using RecordTy = llvm::Record;
#endif

namespace llvm_dialects {

Expand Down
8 changes: 4 additions & 4 deletions include/llvm-dialects/TableGen/Constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include "llvm-dialects/TableGen/Common.h"
#include "llvm-dialects/TableGen/NamedValue.h"

#include "llvm/ADT/ArrayRef.h"
Expand Down Expand Up @@ -220,9 +221,8 @@ class Attr : public MetaType {
return type->getKind() == Kind::Attr;
}

static std::unique_ptr<Attr> parse(llvm::raw_ostream &errs,
GenDialectsContext &context,
llvm::Record *record);
static std::unique_ptr<Attr>
parse(llvm::raw_ostream &errs, GenDialectsContext &context, RecordTy *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;
RecordTy *m_record = nullptr;
std::string m_cppType;
llvm::Init *m_llvmType = nullptr;
std::string m_toLlvmValue;
Expand Down
5 changes: 3 additions & 2 deletions include/llvm-dialects/TableGen/DialectType.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include "llvm-dialects/TableGen/Common.h"
#include "llvm-dialects/TableGen/Predicates.h"

#include "llvm-dialects/TableGen/SymbolTable.h"
Expand All @@ -40,7 +41,7 @@ class DialectType : public BaseCppPredicate {
return arguments().drop_front(1);
}

llvm::Record *getDialectRec() const { return m_dialectRec; }
RecordTy *getDialectRec() const { return m_dialectRec; }
llvm::StringRef getName() const { return m_name; }
llvm::StringRef getMnemonic() const { return m_mnemonic; }
bool defaultGetterHasExplicitContextArgument() const {
Expand All @@ -58,7 +59,7 @@ class DialectType : public BaseCppPredicate {
std::string name;
};

llvm::Record *m_dialectRec = nullptr;
RecordTy *m_dialectRec = nullptr;
std::string m_name;
std::string m_mnemonic;
bool m_defaultGetterHasExplicitContextArgument = false;
Expand Down
21 changes: 11 additions & 10 deletions include/llvm-dialects/TableGen/Dialects.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <memory>

#include "llvm-dialects/TableGen/Common.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
Expand All @@ -42,7 +43,7 @@ class Trait;

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

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

Trait *getTrait(llvm::Record *traitRec);
Trait *getTrait(RecordTy *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);
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; }
Expand All @@ -92,11 +93,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<RecordTy *, 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<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;
};

} // namespace llvm_dialects
5 changes: 3 additions & 2 deletions include/llvm-dialects/TableGen/GenDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#pragma once

#include "llvm-dialects/TableGen/Common.h"
#include "llvm/Support/raw_ostream.h"

namespace llvm {
Expand All @@ -24,7 +25,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, RecordKeeperTy &records);
void genDialectDefs(llvm::raw_ostream &out, RecordKeeperTy &records);

} // namespace llvm_dialects
9 changes: 4 additions & 5 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);
RecordTy *record);

/// Records if this Operation has a variadic argument
bool m_hasVariadicArgument = false;
Expand All @@ -91,9 +91,8 @@ class OpClass : public OperationBase {
std::vector<OpClass *> subclasses;
std::vector<Operation *> operations;

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

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

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

bool haveResultOverloads() const { return m_haveResultOverloads; }
bool haveArgumentOverloads() const { return m_haveArgumentOverloads; }
Expand Down
9 changes: 5 additions & 4 deletions include/llvm-dialects/TableGen/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <memory>
#include <string>

#include "llvm-dialects/TableGen/Common.h"
#include "llvm/ADT/StringRef.h"

namespace llvm {
Expand All @@ -42,22 +43,22 @@ class Trait {
};

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

virtual ~Trait() = default;

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

Kind getKind() const { return m_kind; }
llvm::Record *getRecord() const { return m_record; }
RecordTy *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;
RecordTy *m_record = nullptr;
};

class LlvmAttributeTrait : public Trait {
Expand Down
6 changes: 3 additions & 3 deletions lib/TableGen/Constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool ConstraintSystem::addConstraint(raw_ostream &errs, Init *init,
bool ConstraintSystem::addConstraintImpl(raw_ostream &errs, Init *init,
Variable *self) {
if (auto *dag = dyn_cast<DagInit>(init)) {
Record *op = dag->getOperatorAsDef({});
RecordTy *op = dag->getOperatorAsDef({});

auto isValidOperand = [&dag, &errs](size_t index,
StringRef opName) -> bool {
Expand Down Expand Up @@ -385,8 +385,8 @@ StringRef MetaType::getName() const {
return "value";
}

std::unique_ptr<Attr> Attr::parse(raw_ostream &errs,
GenDialectsContext &context, Record *record) {
std::unique_ptr<Attr>
Attr::parse(raw_ostream &errs, GenDialectsContext &context, RecordTy *record) {
if (!record->isSubClassOf("Attr")) {
errs << record->getName() << ": must be a subclass of Attr\n";
return {};
Expand Down
2 changes: 1 addition & 1 deletion lib/TableGen/DialectType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool DialectType::init(raw_ostream &errs, GenDialectsContext &context,
if (!BaseCppPredicate::init(errs, context, theInit))
return false;

Record *record = cast<DefInit>(theInit)->getDef();
RecordTy *record = cast<DefInit>(theInit)->getDef();

m_dialectRec = record->getValueAsDef("dialect");
if (!m_dialectRec->isSubClassOf("Dialect")) {
Expand Down
23 changes: 11 additions & 12 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(RecordTy *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 @@ -113,8 +113,7 @@ Predicate *GenDialectsContext::getPredicateImpl(Init *init, raw_ostream &errs) {
return op;
}

Attr *GenDialectsContext::getAttr(llvm::Record *record,
llvm::raw_ostream &errs) {
Attr *GenDialectsContext::getAttr(RecordTy *record, llvm::raw_ostream &errs) {
auto it = m_attrs.find(record);
if (it == m_attrs.end()) {
errs << " not an attribute: " << record->getName() << '\n';
Expand All @@ -126,7 +125,7 @@ Attr *GenDialectsContext::getAttr(llvm::Record *record,
return attr;
}

GenDialect *GenDialectsContext::getDialect(Record *dialectRec) {
GenDialect *GenDialectsContext::getDialect(RecordTy *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 +139,7 @@ GenDialect *GenDialectsContext::getDialect(Record *dialectRec) {
return it->second.get();
}

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

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

void GenDialectsContext::init(RecordKeeper &records,
void GenDialectsContext::init(RecordKeeperTy &records,
const DenseSet<StringRef> &dialects) {
for (Record *record : records.getAllDerivedDefinitions("Attr")) {
for (RecordTy *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 (RecordTy *record : records.getAllDerivedDefinitions("AttrLlvmType")) {
Attr *attr = getAttr(record->getValueAsDef("attr"), llvm::errs());
assert(attr);
attr->setLlvmType(record->getValueInit("llvmType"));
Expand All @@ -193,7 +192,7 @@ void GenDialectsContext::init(RecordKeeper &records,
m_any = records.getDef("any")->getDefInit();
assert(m_voidTy && m_any);

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

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

for (Record *opRec : records.getAllDerivedDefinitions("Op")) {
Record *dialectRec = opRec->getValueAsDef("dialect");
for (RecordTy *opRec : records.getAllDerivedDefinitions("Op")) {
RecordTy *dialectRec = opRec->getValueAsDef("dialect");
auto dialectIt = m_dialects.find(dialectRec);
if (dialectIt == m_dialects.end())
continue;
Expand Down
8 changes: 4 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(RecordKeeperTy &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 (RecordTy *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,7 @@ 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, RecordKeeperTy &records) {
auto [context, dialect] = getSelectedDialect(records);

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

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

Expand Down
2 changes: 1 addition & 1 deletion lib/TableGen/NamedValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ NamedValue::parseList(raw_ostream &errs, GenDialectsContext &context,
bool accepted = false;

if (auto *defInit = dyn_cast<DefInit>(valueInit)) {
Record *def = defInit->getDef();
RecordTy *def = defInit->getDef();

if (def->getName() == "type") {
if (mode == Parser::OperationResults ||
Expand Down
Loading
Loading