[llvm-branch-commits] [PromoteMem2Reg] Optimize memory usage in PromoteMem2Reg (PR #142474)
Florian Mayer via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jun 2 14:29:43 PDT 2025
================
@@ -281,18 +281,44 @@ struct AllocaInfo {
}
};
+template <typename T> class VectorWithUndo {
+ SmallVector<T, 8> Vals;
+ SmallVector<std::pair<size_t, T>, 8> Undo;
+
+public:
+ void undo(size_t S) {
+ while (S < Undo.size()) {
+ Vals[Undo.back().first] = Undo.back().second;
+ Undo.pop_back();
+ }
+ }
+
+ void assign(size_t Sz, const T &Val) { Vals.assign(Sz, Val); }
+
+ size_t size() const { return Undo.size(); }
+
+ const T &operator[](size_t Idx) const { return Vals[Idx]; }
+
+ void set(size_t Idx, const T &Val) {
+ if (Vals[Idx] == Val)
+ return;
+ Undo.emplace_back(Idx, Vals[Idx]);
+ Vals[Idx] = Val;
+ }
+
+ void init(size_t Idx, const T &Val) { Vals[Idx] = Val; }
----------------
fmayer wrote:
would it make sense to add asserts that this is not called after `set` or `undo`?
https://github.com/llvm/llvm-project/pull/142474
More information about the llvm-branch-commits
mailing list