[llvm] [CodeLayout][NFC] Using MergedVector to avoid extra vector allocations (PR #68724)

Rahman Lavaee via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 11 11:08:08 PDT 2023


================
@@ -516,34 +518,62 @@ struct MergedChain {
   NodeIter End3;
 };
 
+/// A wrapper around two concatenated vectors (chains) of jumps.
+struct MergedJumpsT {
+  using JumpIter = std::vector<JumpT *>::const_iterator;
+
+  MergedJumpsT(JumpIter Begin, JumpIter End) : Begin1(Begin), End1(End) {}
+
+  template <typename F> void forEach(const F &Func) const {
+    for (auto It = Begin1; It != End1; It++)
+      Func(*It);
+    for (auto It = Begin2; It != End2; It++)
+      Func(*It);
+  }
+
+  bool empty() const { return Begin1 == End1; }
+
+  void append(JumpIter Begin, JumpIter End) {
+    assert(Begin2 == End2 && "cannot extend MergedJumpsT");
+    Begin2 = Begin;
+    End2 = End;
+  }
+
+private:
+  JumpIter Begin1;
----------------
rlavaee wrote:

Are `Begin1` and `End1` always going to be the beginning and ending of a single vector? If yes, can we simplify this further by storing pointers to two vectors:
`std::array<std::vector<JumpT *>, 2> Jumps;`

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


More information about the llvm-commits mailing list