Skip to content

Commit 269c5e8

Browse files
committed
[silcodemotion] Now that we have sunk the context into each block state, we do not need to pass in the context to any routines on the block state.
rdar://36032876
1 parent 77441fc commit 269c5e8

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

lib/SILOptimizer/Transforms/SILCodeMotion.cpp

+23-16
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,18 @@ class BBEnumTagDataflowState
176176
/// first predecessor BB.
177177
///
178178
/// 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);
181180

182181
/// Top level merging function for predecessors.
183-
void mergePredecessorStates(EnumCaseDataflowContext &BBToStateMap);
182+
void mergePredecessorStates();
184183

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;
188191
};
189192

190193
/// Map all blocks to BBEnumTagDataflowState in RPO order.
@@ -216,6 +219,12 @@ class EnumCaseDataflowContext {
216219

217220
} // end anonymous namespace
218221

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+
219228
void BBEnumTagDataflowState::handlePredSwitchEnum(SwitchEnumInst *S) {
220229

221230
// Find the tag associated with our BB and set the state of the
@@ -299,10 +308,9 @@ void BBEnumTagDataflowState::handlePredCondSelectEnum(CondBranchInst *CondBr) {
299308
}
300309
}
301310

302-
bool BBEnumTagDataflowState::initWithFirstPred(
303-
EnumCaseDataflowContext &BBToStateMap, SILBasicBlock *FirstPredBB) {
311+
bool BBEnumTagDataflowState::initWithFirstPred(SILBasicBlock *FirstPredBB) {
304312
// Try to look up the state for the first pred BB.
305-
BBEnumTagDataflowState *FirstPredState = BBToStateMap.getBBState(FirstPredBB);
313+
BBEnumTagDataflowState *FirstPredState = getContext().getBBState(FirstPredBB);
306314

307315
// If we fail, we found an unreachable block, bail.
308316
if (FirstPredState == nullptr) {
@@ -330,7 +338,7 @@ bool BBEnumTagDataflowState::initWithFirstPred(
330338
}
331339

332340
void BBEnumTagDataflowState::mergeSinglePredTermInfoIntoState(
333-
EnumCaseDataflowContext &BBToStateMap, SILBasicBlock *Pred) {
341+
SILBasicBlock *Pred) {
334342
// Grab the terminator of our one predecessor and if it is a switch enum, mix
335343
// it into this state.
336344
TermInst *PredTerm = Pred->getTerminator();
@@ -346,8 +354,7 @@ void BBEnumTagDataflowState::mergeSinglePredTermInfoIntoState(
346354
handlePredCondSelectEnum(CondBr);
347355
}
348356

349-
void BBEnumTagDataflowState::mergePredecessorStates(
350-
EnumCaseDataflowContext &BBToStateMap) {
357+
void BBEnumTagDataflowState::mergePredecessorStates() {
351358

352359
// If we have no predecessors, there is nothing to do so return early...
353360
if (getBB()->pred_empty()) {
@@ -367,7 +374,7 @@ void BBEnumTagDataflowState::mergePredecessorStates(
367374

368375
// Attempt to initialize our state with our first predecessor's state by just
369376
// copying. We will be doing an intersection with all of the other BB.
370-
if (!initWithFirstPred(BBToStateMap, FirstPred))
377+
if (!initWithFirstPred(FirstPred))
371378
return;
372379

373380
// If we only have one predecessor see if we can gain any information and or
@@ -378,7 +385,7 @@ void BBEnumTagDataflowState::mergePredecessorStates(
378385
// the value that an enum can take in our block. This is a common case that
379386
// comes up.
380387
if (PI == PE) {
381-
mergeSinglePredTermInfoIntoState(BBToStateMap, FirstPred);
388+
mergeSinglePredTermInfoIntoState(FirstPred);
382389
return;
383390
}
384391

@@ -405,7 +412,7 @@ void BBEnumTagDataflowState::mergePredecessorStates(
405412
// Grab the predecessors state...
406413
SILBasicBlock *PredBB = *PI;
407414

408-
BBEnumTagDataflowState *PredBBState = BBToStateMap.getBBState(PredBB);
415+
BBEnumTagDataflowState *PredBBState = getContext().getBBState(PredBB);
409416
if (PredBBState == nullptr) {
410417
DEBUG(llvm::dbgs() << " Found an unreachable block!\n");
411418
return;
@@ -1619,7 +1626,7 @@ static bool processFunction(SILFunction *F, AliasAnalysis *AA,
16191626
// predecessors to avoid memory invalidation issues due to copying in the
16201627
// dense map.
16211628
DEBUG(llvm::dbgs() << " Merging predecessors!\n");
1622-
State.mergePredecessorStates(BBToStateMap);
1629+
State.mergePredecessorStates();
16231630

16241631
// If our predecessors cover any of our enum values, attempt to hoist
16251632
// releases up the CFG onto enum payloads or sink retains out of switch

0 commit comments

Comments
 (0)