[llvm] [TableGen] Only store direct superclasses in Record (PR #123072)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 09:41:31 PST 2025


================
@@ -1718,15 +1719,23 @@ class Record {
   ArrayRef<AssertionInfo> getAssertions() const { return Assertions; }
   ArrayRef<DumpInfo> getDumps() const { return Dumps; }
 
-  ArrayRef<std::pair<const Record *, SMRange>> getSuperClasses() const {
-    return SuperClasses;
+  void getSuperClasses(
----------------
s-barannikov wrote:

> Append-to-vector-argument is widely used in LLVM

There must be a reason for this, e.g. avoiding costly re-allocations (for passing by reference) or the method is supposed to be called repeatedly (for not clearing the vector on entry). This is not the case.

> it helps to keep the implementation of getSuperClasses itself efficient, by not allocating a new vector for every recursive call.

Convenience of implementation should not be the deciding factor when choosing a method prototype.
The implementation could use a private method / static function that accepts vector by reference to avoid allocating a new vector for every recursive call.


https://github.com/llvm/llvm-project/pull/123072


More information about the llvm-commits mailing list