@@ -48,11 +48,6 @@ template <class T> class NullablePtr;
4848// / that in a loop this property should predict well since you have a single
4949// / branch that is going to go the same way everytime.
5050class InstModCallbacks {
51- // / A function that takes in an instruction and deletes the inst.
52- // /
53- // / Default implementation is instToDelete->eraseFromParent();
54- std::function<void (SILInstruction *instToDelete)> deleteInstFunc;
55-
5651 // / A function that is called to notify that a new function was created.
5752 // /
5853 // / Default implementation is a no-op, but we still mark madeChange.
@@ -66,37 +61,47 @@ class InstModCallbacks {
6661 // / iterators.
6762 std::function<void (Operand *use, SILValue newValue)> setUseValueFunc;
6863
64+ // / A function that takes in an instruction and deletes the inst.
65+ // /
66+ // / Default implementation is instToDelete->eraseFromParent();
67+ // /
68+ // / NOTE: The reason why we have deleteInstFunc and notifyWillBeDeletedFunc is
69+ // / InstModCallback supports 2 stage deletion where a callee passed
70+ // / InstModCallback is allowed to drop all references to the instruction
71+ // / before calling deleteInstFunc. In contrast, notifyWillBeDeletedFunc
72+ // / assumes that the IR is in a good form before being called so that the
73+ // / caller can via the callback gather state about the instruction that will
74+ // / be deleted. As an example, see InstructionDeleter::deleteInstruction() in
75+ // / InstOptUtils.cpp.
76+ std::function<void (SILInstruction *instToDelete)> deleteInstFunc;
77+
6978 // / If non-null, called before an instruction is deleted or has its references
70- // / dropped.
79+ // / dropped. If null, no-op.
80+ // /
81+ // / NOTE: The reason why we have deleteInstFunc and notifyWillBeDeletedFunc is
82+ // / InstModCallback supports 2 stage deletion where a callee passed
83+ // / InstModCallback is allowed to drop all references to the instruction
84+ // / before calling deleteInstFunc. In contrast, notifyWillBeDeletedFunc
85+ // / assumes that the IR is in a good form before being called so that the
86+ // / caller can via the callback gather state about the instruction that will
87+ // / be deleted. As an example, see InstructionDeleter::deleteInstruction() in
88+ // / InstOptUtils.cpp.
89+ // /
90+ // / NOTE: This is called in InstModCallback::deleteInst() if one does not use
91+ // / a default bool argument to disable the notification. In general that
92+ // / should only be done when one is writing custom handling and is performing
93+ // / the notification ones self. It is assumed that the notification will be
94+ // / called with a valid instruction.
7195 std::function<void (SILInstruction *instThatWillBeDeleted)>
7296 notifyWillBeDeletedFunc;
7397
7498 // / A boolean that tracks if any of our callbacks were ever called.
7599 bool wereAnyCallbacksInvoked = false ;
76100
77101public:
78- InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc)
79- : deleteInstFunc(deleteInstFunc) {}
80-
81- InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc,
82- decltype (createdNewInstFunc) createdNewInstFunc)
83- : deleteInstFunc(deleteInstFunc), createdNewInstFunc(createdNewInstFunc) {
84- }
85-
86- InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc,
87- decltype (setUseValueFunc) setUseValueFunc)
88- : deleteInstFunc(deleteInstFunc), setUseValueFunc(setUseValueFunc) {}
89-
90- InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc,
91- decltype (createdNewInstFunc) createdNewInstFunc,
92- decltype (setUseValueFunc) setUseValueFunc)
93- : deleteInstFunc(deleteInstFunc), createdNewInstFunc(createdNewInstFunc),
94- setUseValueFunc (setUseValueFunc) {}
95-
96102 InstModCallbacks () = default ;
97103 ~InstModCallbacks () = default ;
98104 InstModCallbacks (const InstModCallbacks &) = default ;
99- InstModCallbacks (InstModCallbacks &&) = default;
100105
101106 // / Return a copy of self with deleteInstFunc set to \p newDeleteInstFunc.
102107 InstModCallbacks onDelete (decltype (deleteInstFunc) newDeleteInstFunc) const {
0 commit comments