@@ -93,16 +93,26 @@ Scheduler::GraphBuilder::GraphBuilder() {
93
93
}
94
94
95
95
static bool markNodeAsVisited (Command *Cmd, std::vector<Command *> &Visited) {
96
- if (Cmd->MVisited )
96
+ if (Cmd->MMarks . MVisited )
97
97
return false ;
98
- Cmd->MVisited = true ;
98
+ Cmd->MMarks . MVisited = true ;
99
99
Visited.push_back (Cmd);
100
100
return true ;
101
101
}
102
102
103
103
static void unmarkVisitedNodes (std::vector<Command *> &Visited) {
104
104
for (Command *Cmd : Visited)
105
- Cmd->MVisited = false ;
105
+ Cmd->MMarks .MVisited = false ;
106
+ }
107
+
108
+ static void handleVisitedNodes (std::vector<Command *> &Visited) {
109
+ for (Command *Cmd : Visited) {
110
+ if (Cmd->MMarks .MToBeDeleted ) {
111
+ Cmd->getEvent ()->setCommand (nullptr );
112
+ delete Cmd;
113
+ } else
114
+ Cmd->MMarks .MVisited = false ;
115
+ }
106
116
}
107
117
108
118
static void printDotRecursive (std::fstream &Stream,
@@ -825,7 +835,6 @@ void Scheduler::GraphBuilder::cleanupCommandsForRecord(MemObjRecord *Record) {
825
835
826
836
std::queue<Command *> ToVisit;
827
837
std::vector<Command *> Visited;
828
- std::vector<Command *> CmdsToDelete;
829
838
// First, mark all allocas for deletion and their direct users for traversal
830
839
// Dependencies of the users will be cleaned up during the traversal
831
840
for (Command *AllocaCmd : AllocaCommands) {
@@ -839,7 +848,7 @@ void Scheduler::GraphBuilder::cleanupCommandsForRecord(MemObjRecord *Record) {
839
848
else
840
849
markNodeAsVisited (UserCmd, Visited);
841
850
842
- CmdsToDelete. push_back ( AllocaCmd) ;
851
+ AllocaCmd-> MMarks . MToBeDeleted = true ;
843
852
// These commands will be deleted later, clear users now to avoid
844
853
// updating them during edge removal
845
854
AllocaCmd->MUsers .clear ();
@@ -851,7 +860,7 @@ void Scheduler::GraphBuilder::cleanupCommandsForRecord(MemObjRecord *Record) {
851
860
AllocaCommandBase *LinkedCmd = AllocaCmd->MLinkedAllocaCmd ;
852
861
853
862
if (LinkedCmd) {
854
- assert (LinkedCmd->MVisited );
863
+ assert (LinkedCmd->MMarks . MVisited );
855
864
856
865
for (DepDesc &Dep : AllocaCmd->MDeps )
857
866
if (Dep.MDepCommand )
@@ -896,17 +905,12 @@ void Scheduler::GraphBuilder::cleanupCommandsForRecord(MemObjRecord *Record) {
896
905
// If all dependencies have been removed this way, mark the command for
897
906
// deletion
898
907
if (Cmd->MDeps .empty ()) {
899
- CmdsToDelete. push_back ( Cmd) ;
908
+ Cmd-> MMarks . MToBeDeleted = true ;
900
909
Cmd->MUsers .clear ();
901
910
}
902
911
}
903
912
904
- unmarkVisitedNodes (Visited);
905
-
906
- for (Command *Cmd : CmdsToDelete) {
907
- Cmd->getEvent ()->setCommand (nullptr );
908
- delete Cmd;
909
- }
913
+ handleVisitedNodes (Visited);
910
914
}
911
915
912
916
void Scheduler::GraphBuilder::cleanupFinishedCommands (Command *FinishedCmd) {
@@ -948,12 +952,10 @@ void Scheduler::GraphBuilder::cleanupFinishedCommands(Command *FinishedCmd) {
948
952
Command *DepCmd = Dep.MDepCommand ;
949
953
DepCmd->MUsers .erase (Cmd);
950
954
}
951
- Cmd->getEvent ()->setCommand (nullptr );
952
955
953
- Visited.pop_back ();
954
- delete Cmd;
956
+ Cmd->MMarks .MToBeDeleted = true ;
955
957
}
956
- unmarkVisitedNodes (Visited);
958
+ handleVisitedNodes (Visited);
957
959
}
958
960
959
961
void Scheduler::GraphBuilder::removeRecordForMemObj (SYCLMemObjI *MemObject) {
0 commit comments