Skip to content

[NFC][TableGen] Code cleanup in Record.h/cpp #138876

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
merged 1 commit into from
May 14, 2025
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
56 changes: 27 additions & 29 deletions llvm/include/llvm/TableGen/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
Expand Down Expand Up @@ -244,7 +245,7 @@ class RecordRecTy final : public RecTy,
RecordRecTy &operator=(const RecordRecTy &) = delete;

// Do not use sized deallocation due to trailing objects.
void operator delete(void *p) { ::operator delete(p); }
void operator delete(void *Ptr) { ::operator delete(Ptr); }

static bool classof(const RecTy *RT) {
return RT->getRecTyKind() == RecordRecTyKind;
Expand Down Expand Up @@ -598,7 +599,7 @@ class BitsInit final : public TypedInit,
BitsInit &operator=(const BitsInit &) = delete;

// Do not use sized deallocation due to trailing objects.
void operator delete(void *p) { ::operator delete(p); }
void operator delete(void *Ptr) { ::operator delete(Ptr); }

static bool classof(const Init *I) {
return I->getKind() == IK_BitsInit;
Expand All @@ -615,18 +616,8 @@ class BitsInit final : public TypedInit,
convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
std::optional<int64_t> convertInitializerToInt() const;

bool isComplete() const override {
for (unsigned i = 0; i != getNumBits(); ++i)
if (!getBit(i)->isComplete()) return false;
return true;
}

bool allInComplete() const {
for (unsigned i = 0; i != getNumBits(); ++i)
if (getBit(i)->isComplete()) return false;
return true;
}

bool isComplete() const override;
bool allInComplete() const;
bool isConcrete() const override;
std::string getAsString() const override;

Expand Down Expand Up @@ -773,7 +764,7 @@ class ListInit final : public TypedInit,
ListInit &operator=(const ListInit &) = delete;

// Do not use sized deallocation due to trailing objects.
void operator delete(void *p) { ::operator delete(p); }
void operator delete(void *Ptr) { ::operator delete(Ptr); }

static bool classof(const Init *I) {
return I->getKind() == IK_ListInit;
Expand All @@ -786,13 +777,13 @@ class ListInit final : public TypedInit,
return ArrayRef(getTrailingObjects<const Init *>(), NumValues);
}

const Init *getElement(unsigned Index) const { return getValues()[Index]; }
const Init *getElement(unsigned Idx) const { return getValues()[Idx]; }

const RecTy *getElementType() const {
return cast<ListRecTy>(getType())->getElementType();
}

const Record *getElementAsRecord(unsigned i) const;
const Record *getElementAsRecord(unsigned Idx) const;

const Init *convertInitializerTo(const RecTy *Ty) const override;

Expand Down Expand Up @@ -1060,6 +1051,8 @@ class CondOpInit final : public TypedInit,
return ArrayRef(getTrailingObjects<const Init *>() + NumConds, NumConds);
}

auto getCondAndVals() const { return zip_equal(getConds(), getVals()); }

const Init *Fold(const Record *CurRec) const;

const Init *resolveReferences(Resolver &R) const override;
Expand Down Expand Up @@ -1349,7 +1342,7 @@ class VarDefInit final
VarDefInit &operator=(const VarDefInit &) = delete;

// Do not use sized deallocation due to trailing objects.
void operator delete(void *p) { ::operator delete(p); }
void operator delete(void *Ptr) { ::operator delete(Ptr); }

static bool classof(const Init *I) {
return I->getKind() == IK_VarDefInit;
Expand Down Expand Up @@ -1457,7 +1450,7 @@ class DagInit final
ArrayRef<const StringInit *> NameRange);
static const DagInit *
get(const Init *V, const StringInit *VN,
ArrayRef<std::pair<const Init *, const StringInit *>> Args);
ArrayRef<std::pair<const Init *, const StringInit *>> ArgAndNames);

void Profile(FoldingSetNodeID &ID) const;

Expand Down Expand Up @@ -1495,6 +1488,15 @@ class DagInit final
return ArrayRef(getTrailingObjects<const StringInit *>(), NumArgs);
}

// Return a range of std::pair.
auto getArgAndNames() const {
auto Zip = llvm::zip_equal(getArgs(), getArgNames());
using EltTy = decltype(*adl_begin(Zip));
return llvm::map_range(Zip, [](const EltTy &E) {
return std::make_pair(std::get<0>(E), std::get<1>(E));
});
}

const Init *resolveReferences(Resolver &R) const override;

bool isConcrete() const override;
Expand Down Expand Up @@ -1798,12 +1800,11 @@ class Record {
}

void removeValue(const Init *Name) {
for (unsigned i = 0, e = Values.size(); i != e; ++i)
if (Values[i].getNameInit() == Name) {
Values.erase(Values.begin()+i);
return;
}
llvm_unreachable("Cannot remove an entry that does not exist!");
auto It = llvm::find_if(
Values, [Name](const RecordVal &V) { return V.getNameInit() == Name; });
if (It == Values.end())
llvm_unreachable("Cannot remove an entry that does not exist!");
Values.erase(It);
}

void removeValue(StringRef Name) {
Expand Down Expand Up @@ -2123,10 +2124,7 @@ struct LessRecordRegister {

size_t size() { return Parts.size(); }

std::pair<bool, StringRef> getPart(size_t i) {
assert (i < Parts.size() && "Invalid idx!");
return Parts[i];
}
std::pair<bool, StringRef> getPart(size_t Idx) { return Parts[Idx]; }
};

bool operator()(const Record *Rec1, const Record *Rec2) const {
Expand Down
Loading