Skip to content

Commit 26861b8

Browse files
committed
[NFC][TableGen] Code cleanup in Record.h/cpp
1 parent 8e9227a commit 26861b8

File tree

2 files changed

+153
-224
lines changed

2 files changed

+153
-224
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 27 additions & 29 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;
@@ -1457,7 +1450,7 @@ class DagInit final
14571450
ArrayRef<const StringInit *> NameRange);
14581451
static const DagInit *
14591452
get(const Init *V, const StringInit *VN,
1460-
ArrayRef<std::pair<const Init *, const StringInit *>> Args);
1453+
ArrayRef<std::pair<const Init *, const StringInit *>> ArgAndNames);
14611454

14621455
void Profile(FoldingSetNodeID &ID) const;
14631456

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

1491+
// Return a range of std::pair.
1492+
auto getArgAndNames() const {
1493+
auto Zip = llvm::zip_equal(getArgs(), getArgNames());
1494+
using EltTy = decltype(*adl_begin(Zip));
1495+
return llvm::map_range(Zip, [](const EltTy &E) {
1496+
return std::make_pair(std::get<0>(E), std::get<1>(E));
1497+
});
1498+
}
1499+
14981500
const Init *resolveReferences(Resolver &R) const override;
14991501

15001502
bool isConcrete() const override;
@@ -1798,12 +1800,11 @@ class Record {
17981800
}
17991801

18001802
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);
1804-
return;
1805-
}
1806-
llvm_unreachable("Cannot remove an entry that does not exist!");
1803+
auto It = llvm::find_if(
1804+
Values, [Name](const RecordVal &V) { return V.getNameInit() == Name; });
1805+
if (It == Values.end())
1806+
llvm_unreachable("Cannot remove an entry that does not exist!");
1807+
Values.erase(It);
18071808
}
18081809

18091810
void removeValue(StringRef Name) {
@@ -2123,10 +2124,7 @@ struct LessRecordRegister {
21232124

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

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

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

0 commit comments

Comments
 (0)