@@ -48,11 +48,6 @@ template <class T> class NullablePtr;
48
48
// / that in a loop this property should predict well since you have a single
49
49
// / branch that is going to go the same way everytime.
50
50
class 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
-
56
51
// / A function that is called to notify that a new function was created.
57
52
// /
58
53
// / Default implementation is a no-op, but we still mark madeChange.
@@ -66,8 +61,37 @@ class InstModCallbacks {
66
61
// / iterators.
67
62
std::function<void (Operand *use, SILValue newValue)> setUseValueFunc;
68
63
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
+
69
78
// / 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.
71
95
std::function<void (SILInstruction *instThatWillBeDeleted)>
72
96
notifyWillBeDeletedFunc;
73
97
@@ -80,18 +104,18 @@ class InstModCallbacks {
80
104
81
105
InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc,
82
106
decltype (createdNewInstFunc) createdNewInstFunc)
83
- : deleteInstFunc(deleteInstFunc ), createdNewInstFunc(createdNewInstFunc ) {
107
+ : createdNewInstFunc(createdNewInstFunc ), deleteInstFunc(deleteInstFunc ) {
84
108
}
85
109
86
110
InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc,
87
111
decltype (setUseValueFunc) setUseValueFunc)
88
- : deleteInstFunc(deleteInstFunc ), setUseValueFunc(setUseValueFunc ) {}
112
+ : setUseValueFunc(setUseValueFunc ), deleteInstFunc(deleteInstFunc ) {}
89
113
90
114
InstModCallbacks (decltype (deleteInstFunc) deleteInstFunc,
91
115
decltype (createdNewInstFunc) createdNewInstFunc,
92
116
decltype (setUseValueFunc) setUseValueFunc)
93
- : deleteInstFunc(deleteInstFunc), createdNewInstFunc(createdNewInstFunc),
94
- setUseValueFunc (setUseValueFunc) {}
117
+ : createdNewInstFunc(createdNewInstFunc),
118
+ setUseValueFunc (setUseValueFunc), deleteInstFunc(deleteInstFunc) {}
95
119
96
120
InstModCallbacks () = default;
97
121
~InstModCallbacks () = default ;
0 commit comments