[llvm] [SandboxIR] Clean up tracking code with the help of tryTrack() (PR #102406)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 12:05:55 PDT 2024


================
@@ -383,7 +383,23 @@ class Tracker {
   Context &getContext() const { return Ctx; }
   /// Record \p Change and take ownership. This is the main function used to
   /// track Sandbox IR changes.
-  void track(std::unique_ptr<IRChangeBase> &&Change);
+  void track(std::unique_ptr<IRChangeBase> &&Change) {
+    assert(State == TrackerState::Record && "The tracker should be tracking!");
+    Changes.push_back(std::move(Change));
+
+#ifndef NDEBUG
+    InMiddleOfCreatingChange = false;
+#endif
+  }
+  /// A convenience wrapper for `track()` that constructs and tracks the Change
+  /// object if tracking is enabled. \Returns true if tracking is enabled.
+  template <typename ChangeT, typename... ArgsT>
+  bool emplaceIfTracking(ArgsT... ChangeArgs) {
+    if (!isTracking())
+      return false;
+    track(std::make_unique<ChangeT>(ChangeArgs..., *this));
----------------
vporpo wrote:

@aeubanks I removed the `Parent` member variable from `IRChangeBase`. Instead I am passing it to `revert(Tracker &)` because it was used by `EraseFromParent::revert()`.

How do you like this version?

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


More information about the llvm-commits mailing list