@@ -144,40 +144,44 @@ void OptimizeHopToExecutor::allocateBlockStates() {
144144// / Solve the dataflow in forward direction.
145145void OptimizeHopToExecutor::solveDataflowForward () {
146146 bool changed = false ;
147+ bool firstRound = true ;
147148 do {
148149 changed = false ;
149150 for (BlockState &state : blockStates) {
150151 int newEntry = state.entry ;
151152 for (SILBasicBlock *pred : state.block ->getPredecessorBlocks ()) {
152153 newEntry = BlockState::merge (newEntry, block2State[pred]->exit );
153154 }
154- if (newEntry != state.entry || state. exit == BlockState::NotSet ) {
155+ if (newEntry != state.entry || firstRound ) {
155156 changed = true ;
156157 state.entry = newEntry;
157158 if (state.intra == BlockState::NotSet)
158159 state.exit = state.entry ;
159160 }
160161 }
162+ firstRound = false ;
161163 } while (changed);
162164}
163165
164166// / Solve the dataflow in backward direction.
165167void OptimizeHopToExecutor::solveDataflowBackward () {
166168 bool changed = false ;
169+ bool firstRound = true ;
167170 do {
168171 changed = false ;
169172 for (BlockState &state : llvm::reverse (blockStates)) {
170173 int newExit = state.exit ;
171174 for (SILBasicBlock *succ : state.block ->getSuccessorBlocks ()) {
172175 newExit = BlockState::merge (newExit, block2State[succ]->entry );
173176 }
174- if (newExit != state.exit || state. entry == BlockState::NotSet ) {
177+ if (newExit != state.exit || firstRound ) {
175178 changed = true ;
176179 state.exit = newExit;
177180 if (state.intra == BlockState::NotSet)
178181 state.entry = state.exit ;
179182 }
180183 }
184+ firstRound = false ;
181185 } while (changed);
182186}
183187
@@ -255,7 +259,7 @@ bool OptimizeHopToExecutor::removeDeadHopToExecutors() {
255259 // might require a dedicated executor, don't remove a preceeding
256260 // hop_to_executor instruction.
257261 for (BlockState &state : blockStates) {
258- state.exit = (state.block ->getTerminator ()-> isFunctionExiting () ?
262+ state.exit = (state.block ->getSuccessors (). empty () ?
259263 BlockState::NoExecutorNeeded : BlockState::NotSet);
260264 state.intra = BlockState::NotSet;
261265 for (SILInstruction &inst : llvm::reverse (*state.block )) {
0 commit comments