@@ -176,15 +176,18 @@ class BBEnumTagDataflowState
176
176
// / first predecessor BB.
177
177
// /
178
178
// / We will be performing an intersection in a later step of the merging.
179
- bool initWithFirstPred (EnumCaseDataflowContext &BBToStateMap,
180
- SILBasicBlock *FirstPredBB);
179
+ bool initWithFirstPred (SILBasicBlock *FirstPredBB);
181
180
182
181
// / Top level merging function for predecessors.
183
- void mergePredecessorStates (EnumCaseDataflowContext &BBToStateMap );
182
+ void mergePredecessorStates ();
184
183
185
- // /
186
- void mergeSinglePredTermInfoIntoState (EnumCaseDataflowContext &BBToStateMap,
187
- SILBasicBlock *Pred);
184
+ // / If we have a single predecessor, see if the predecessor's terminator was a
185
+ // / switch_enum or a (cond_br + select_enum). If so, track in this block the
186
+ // / enum state of the operand.
187
+ void mergeSinglePredTermInfoIntoState (SILBasicBlock *Pred);
188
+
189
+ private:
190
+ EnumCaseDataflowContext &getContext () const ;
188
191
};
189
192
190
193
// / Map all blocks to BBEnumTagDataflowState in RPO order.
@@ -216,6 +219,12 @@ class EnumCaseDataflowContext {
216
219
217
220
} // end anonymous namespace
218
221
222
+ EnumCaseDataflowContext &BBEnumTagDataflowState::getContext () const {
223
+ // Context and BB are initialized together, so we only need to check one.
224
+ assert (BB.isNonNull () && " Uninitialized state?!" );
225
+ return *Context;
226
+ }
227
+
219
228
void BBEnumTagDataflowState::handlePredSwitchEnum (SwitchEnumInst *S) {
220
229
221
230
// Find the tag associated with our BB and set the state of the
@@ -299,10 +308,9 @@ void BBEnumTagDataflowState::handlePredCondSelectEnum(CondBranchInst *CondBr) {
299
308
}
300
309
}
301
310
302
- bool BBEnumTagDataflowState::initWithFirstPred (
303
- EnumCaseDataflowContext &BBToStateMap, SILBasicBlock *FirstPredBB) {
311
+ bool BBEnumTagDataflowState::initWithFirstPred (SILBasicBlock *FirstPredBB) {
304
312
// Try to look up the state for the first pred BB.
305
- BBEnumTagDataflowState *FirstPredState = BBToStateMap .getBBState (FirstPredBB);
313
+ BBEnumTagDataflowState *FirstPredState = getContext () .getBBState (FirstPredBB);
306
314
307
315
// If we fail, we found an unreachable block, bail.
308
316
if (FirstPredState == nullptr ) {
@@ -330,7 +338,7 @@ bool BBEnumTagDataflowState::initWithFirstPred(
330
338
}
331
339
332
340
void BBEnumTagDataflowState::mergeSinglePredTermInfoIntoState (
333
- EnumCaseDataflowContext &BBToStateMap, SILBasicBlock *Pred) {
341
+ SILBasicBlock *Pred) {
334
342
// Grab the terminator of our one predecessor and if it is a switch enum, mix
335
343
// it into this state.
336
344
TermInst *PredTerm = Pred->getTerminator ();
@@ -346,8 +354,7 @@ void BBEnumTagDataflowState::mergeSinglePredTermInfoIntoState(
346
354
handlePredCondSelectEnum (CondBr);
347
355
}
348
356
349
- void BBEnumTagDataflowState::mergePredecessorStates (
350
- EnumCaseDataflowContext &BBToStateMap) {
357
+ void BBEnumTagDataflowState::mergePredecessorStates () {
351
358
352
359
// If we have no predecessors, there is nothing to do so return early...
353
360
if (getBB ()->pred_empty ()) {
@@ -367,7 +374,7 @@ void BBEnumTagDataflowState::mergePredecessorStates(
367
374
368
375
// Attempt to initialize our state with our first predecessor's state by just
369
376
// copying. We will be doing an intersection with all of the other BB.
370
- if (!initWithFirstPred (BBToStateMap, FirstPred))
377
+ if (!initWithFirstPred (FirstPred))
371
378
return ;
372
379
373
380
// If we only have one predecessor see if we can gain any information and or
@@ -378,7 +385,7 @@ void BBEnumTagDataflowState::mergePredecessorStates(
378
385
// the value that an enum can take in our block. This is a common case that
379
386
// comes up.
380
387
if (PI == PE) {
381
- mergeSinglePredTermInfoIntoState (BBToStateMap, FirstPred);
388
+ mergeSinglePredTermInfoIntoState (FirstPred);
382
389
return ;
383
390
}
384
391
@@ -405,7 +412,7 @@ void BBEnumTagDataflowState::mergePredecessorStates(
405
412
// Grab the predecessors state...
406
413
SILBasicBlock *PredBB = *PI;
407
414
408
- BBEnumTagDataflowState *PredBBState = BBToStateMap .getBBState (PredBB);
415
+ BBEnumTagDataflowState *PredBBState = getContext () .getBBState (PredBB);
409
416
if (PredBBState == nullptr ) {
410
417
DEBUG (llvm::dbgs () << " Found an unreachable block!\n " );
411
418
return ;
@@ -1619,7 +1626,7 @@ static bool processFunction(SILFunction *F, AliasAnalysis *AA,
1619
1626
// predecessors to avoid memory invalidation issues due to copying in the
1620
1627
// dense map.
1621
1628
DEBUG (llvm::dbgs () << " Merging predecessors!\n " );
1622
- State.mergePredecessorStates (BBToStateMap );
1629
+ State.mergePredecessorStates ();
1623
1630
1624
1631
// If our predecessors cover any of our enum values, attempt to hoist
1625
1632
// releases up the CFG onto enum payloads or sink retains out of switch
0 commit comments