Skip to content

Commit 9281947

Browse files
authored
[NFC][TableGen] Code cleanup in CodeGenRegister (llvm#137994)
- Use range for loops. - Wrap complex LLVM_DEBUG() macros in {} to have clang-format format the contents similar to regular code. - Extract repeated code snippets for debug dumping into helper lambda. - Add `BitsInit::getBits()` to get all contained bits.
1 parent 7aa6737 commit 9281947

File tree

3 files changed

+249
-291
lines changed

3 files changed

+249
-291
lines changed

llvm/include/llvm/TableGen/Record.h

+11-12
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,11 @@ class BitsInit final : public TypedInit,
632632

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

635-
const Init *getBit(unsigned Bit) const override {
636-
assert(Bit < NumBits && "Bit index out of range!");
637-
return getTrailingObjects<const Init *>()[Bit];
635+
ArrayRef<const Init *> getBits() const {
636+
return ArrayRef(getTrailingObjects<const Init *>(), NumBits);
638637
}
638+
639+
const Init *getBit(unsigned Bit) const override { return getBits()[Bit]; }
639640
};
640641

641642
/// '7' - Represent an initialization by a literal integer value.
@@ -781,10 +782,12 @@ class ListInit final : public TypedInit,
781782

782783
void Profile(FoldingSetNodeID &ID) const;
783784

784-
const Init *getElement(unsigned i) const {
785-
assert(i < NumValues && "List element index out of range!");
786-
return getTrailingObjects<const Init *>()[i];
785+
ArrayRef<const Init *> getValues() const {
786+
return ArrayRef(getTrailingObjects<const Init *>(), NumValues);
787787
}
788+
789+
const Init *getElement(unsigned Index) const { return getValues()[Index]; }
790+
788791
const RecTy *getElementType() const {
789792
return cast<ListRecTy>(getType())->getElementType();
790793
}
@@ -804,12 +807,8 @@ class ListInit final : public TypedInit,
804807
bool isConcrete() const override;
805808
std::string getAsString() const override;
806809

807-
ArrayRef<const Init *> getValues() const {
808-
return ArrayRef(getTrailingObjects<const Init *>(), NumValues);
809-
}
810-
811-
const_iterator begin() const { return getTrailingObjects<const Init *>(); }
812-
const_iterator end () const { return begin() + NumValues; }
810+
const_iterator begin() const { return getValues().begin(); }
811+
const_iterator end() const { return getValues().end(); }
813812

814813
size_t size () const { return NumValues; }
815814
bool empty() const { return NumValues == 0; }

0 commit comments

Comments
 (0)