Skip to content

Commit 2669541

Browse files
committed
[move-function] Eliminate unnecessary state from ClosureOperandState.
We can always derive isUpwardsUse, isUpwardsConsume from the result downward scan result within the struct.
1 parent 68627db commit 2669541

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

lib/SILOptimizer/Mandatory/MoveKillsCopyableAddressesChecker.cpp

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -251,26 +251,56 @@ struct ClosureOperandState {
251251
/// points.
252252
DebugValueInst *singleDebugValue = nullptr;
253253

254-
/// If set to true, this closure invocation propagates a use upwards that will
255-
/// result in an error.
256-
bool isUpwardsUse = false;
257-
258-
/// If set to true, then the var in the callee is reinited and or destroyed
259-
/// with a destroy_addr. We can convert the inout_aliasable to an out
260-
/// parameter.
261-
bool isUpwardsConsume = false;
262-
263-
/// We do not propagate inits towards function exits, we just use them to stop
264-
/// propagating uses or consumes. This is because we only care about analyzing
265-
/// the address while the parameter value has not be reinited over. We can
266-
/// rely on SILGen when working with vars (the only way this can happen).
267-
bool isUpwardsInit = false;
254+
bool isUpwardsUse() const {
255+
return result == DownwardScanResult::ClosureUse;
256+
}
257+
258+
bool isUpwardsConsume() const {
259+
return result == DownwardScanResult::ClosureConsume;
260+
}
268261
};
269262

270263
} // namespace
271264

265+
static void convertMemoryReinitToInitForm(SILInstruction *memInst) {
266+
switch (memInst->getKind()) {
267+
default:
268+
llvm_unreachable("unsupported?!");
269+
270+
case SILInstructionKind::CopyAddrInst: {
271+
auto *cai = cast<CopyAddrInst>(memInst);
272+
cai->setIsInitializationOfDest(IsInitialization_t::IsInitialization);
273+
return;
274+
}
275+
case SILInstructionKind::StoreInst: {
276+
auto *si = cast<StoreInst>(memInst);
277+
si->setOwnershipQualifier(StoreOwnershipQualifier::Init);
278+
return;
279+
}
280+
}
281+
}
282+
283+
static bool memInstMustReinitialize(Operand *memOper) {
284+
SILValue address = memOper->get();
285+
auto *memInst = memOper->getUser();
286+
switch (memInst->getKind()) {
287+
default:
288+
return false;
289+
290+
case SILInstructionKind::CopyAddrInst: {
291+
auto *CAI = cast<CopyAddrInst>(memInst);
292+
return CAI->getDest() == address && !CAI->isInitializationOfDest();
293+
}
294+
case SILInstructionKind::StoreInst: {
295+
auto *si = cast<StoreInst>(memInst);
296+
return si->getDest() == address &&
297+
si->getOwnershipQualifier() == StoreOwnershipQualifier::Assign;
298+
}
299+
}
300+
}
301+
272302
//===----------------------------------------------------------------------===//
273-
// Use Gathering
303+
// Use State
274304
//===----------------------------------------------------------------------===//
275305

276306
namespace {
@@ -704,7 +734,6 @@ bool ClosureArgDataflowState::handleSingleBlockCase(
704734
return false;
705735

706736
state.pairedConsumingInsts.push_back(dvi);
707-
state.isUpwardsConsume = true;
708737
state.result = DownwardScanResult::ClosureConsume;
709738
return true;
710739
}
@@ -718,7 +747,6 @@ bool ClosureArgDataflowState::handleSingleBlockCase(
718747
return false;
719748

720749
state.pairedConsumingInsts.push_back(&inst);
721-
state.isUpwardsConsume = true;
722750
state.result = DownwardScanResult::ClosureConsume;
723751
return true;
724752
}
@@ -728,7 +756,6 @@ bool ClosureArgDataflowState::handleSingleBlockCase(
728756
LLVM_DEBUG(llvm::dbgs()
729757
<< "ClosureArgDataflow: Found liveness use: " << inst);
730758
state.pairedUseInsts.push_back(&inst);
731-
state.isUpwardsUse = true;
732759
state.result = DownwardScanResult::ClosureUse;
733760
return true;
734761
}
@@ -923,7 +950,6 @@ bool ClosureArgDataflowState::process(
923950
state.pairedUseInsts.push_back(ptr);
924951
}
925952
}
926-
state.isUpwardsUse = true;
927953
state.result = DownwardScanResult::ClosureUse;
928954
return true;
929955
}
@@ -960,7 +986,6 @@ bool ClosureArgDataflowState::process(
960986
return false;
961987
postDominatingConsumingUsers.insert(ptr);
962988
}
963-
state.isUpwardsConsume = true;
964989
state.result = DownwardScanResult::ClosureConsume;
965990
return true;
966991
}

0 commit comments

Comments
 (0)