Skip to content

Commit 60f4d97

Browse files
committed
[NFC][TableGen] Code cleanup in Record.h/cpp
1 parent 70cf616 commit 60f4d97

File tree

2 files changed

+134
-204
lines changed

2 files changed

+134
-204
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/DenseSet.h"
2020
#include "llvm/ADT/FoldingSet.h"
2121
#include "llvm/ADT/PointerIntPair.h"
22+
#include "llvm/ADT/STLExtras.h"
2223
#include "llvm/ADT/SmallVector.h"
2324
#include "llvm/ADT/StringExtras.h"
2425
#include "llvm/ADT/StringRef.h"
@@ -244,7 +245,7 @@ class RecordRecTy final : public RecTy,
244245
RecordRecTy &operator=(const RecordRecTy &) = delete;
245246

246247
// Do not use sized deallocation due to trailing objects.
247-
void operator delete(void *p) { ::operator delete(p); }
248+
void operator delete(void *Ptr) { ::operator delete(Ptr); }
248249

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

600601
// Do not use sized deallocation due to trailing objects.
601-
void operator delete(void *p) { ::operator delete(p); }
602+
void operator delete(void *Ptr) { ::operator delete(Ptr); }
602603

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

618-
bool isComplete() const override {
619-
for (unsigned i = 0; i != getNumBits(); ++i)
620-
if (!getBit(i)->isComplete()) return false;
621-
return true;
622-
}
623-
624-
bool allInComplete() const {
625-
for (unsigned i = 0; i != getNumBits(); ++i)
626-
if (getBit(i)->isComplete()) return false;
627-
return true;
628-
}
629-
619+
bool isComplete() const override;
620+
bool allInComplete() const;
630621
bool isConcrete() const override;
631622
std::string getAsString() const override;
632623

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

775766
// Do not use sized deallocation due to trailing objects.
776-
void operator delete(void *p) { ::operator delete(p); }
767+
void operator delete(void *Ptr) { ::operator delete(Ptr); }
777768

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

789-
const Init *getElement(unsigned Index) const { return getValues()[Index]; }
780+
const Init *getElement(unsigned Idx) const { return getValues()[Idx]; }
790781

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

795-
const Record *getElementAsRecord(unsigned i) const;
786+
const Record *getElementAsRecord(unsigned Idx) const;
796787

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

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

1054+
auto getCondAndVals() const { return zip_equal(getConds(), getVals()); }
1055+
10631056
const Init *Fold(const Record *CurRec) const;
10641057

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

13511344
// Do not use sized deallocation due to trailing objects.
1352-
void operator delete(void *p) { ::operator delete(p); }
1345+
void operator delete(void *Ptr) { ::operator delete(Ptr); }
13531346

13541347
static bool classof(const Init *I) {
13551348
return I->getKind() == IK_VarDefInit;
@@ -1495,6 +1488,8 @@ class DagInit final
14951488
return ArrayRef(getTrailingObjects<const StringInit *>(), NumArgs);
14961489
}
14971490

1491+
auto getArgAndNames() const { return zip_equal(getArgs(), getArgNames()); }
1492+
14981493
const Init *resolveReferences(Resolver &R) const override;
14991494

15001495
bool isConcrete() const override;
@@ -1798,9 +1793,9 @@ class Record {
17981793
}
17991794

18001795
void removeValue(const Init *Name) {
1801-
for (unsigned i = 0, e = Values.size(); i != e; ++i)
1802-
if (Values[i].getNameInit() == Name) {
1803-
Values.erase(Values.begin()+i);
1796+
for (auto [Idx, Value] : enumerate(Values))
1797+
if (Value.getNameInit() == Name) {
1798+
Values.erase(Values.begin() + Idx);
18041799
return;
18051800
}
18061801
llvm_unreachable("Cannot remove an entry that does not exist!");
@@ -2123,10 +2118,7 @@ struct LessRecordRegister {
21232118

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

2126-
std::pair<bool, StringRef> getPart(size_t i) {
2127-
assert (i < Parts.size() && "Invalid idx!");
2128-
return Parts[i];
2129-
}
2121+
std::pair<bool, StringRef> getPart(size_t Idx) { return Parts[Idx]; }
21302122
};
21312123

21322124
bool operator()(const Record *Rec1, const Record *Rec2) const {

0 commit comments

Comments
 (0)