[llvm] [SandboxIR] Clean up tracking code with the help of tryTrack() (PR #102406)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 10:31:30 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));
----------------
aeubanks wrote:
I'm not a fan of the implicit `Tracker` argument at the end, it's very not obvious. I'd make the caller pass it in. (It looks like most tracker objects don't actually need it aside from debugging purposes)
https://github.com/llvm/llvm-project/pull/102406
More information about the llvm-commits
mailing list