Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,19 @@ struct AvailableValueStore {
liveness.getNumSubElements()),
numBits(liveness.getNumSubElements()) {}

std::pair<AvailableValues *, bool> get(SILBasicBlock *block) {
std::pair<AvailableValues, bool> get(SILBasicBlock *block) {
auto iter = blockToValues.try_emplace(block, AvailableValues());

if (!iter.second) {
return {&iter.first->second, false};
return {iter.first->second, false};
}

ASSERT(dataStore.size() >= (nextOffset + numBits) && "underallocated!");

iter.first->second.values =
MutableArrayRef<SILValue>(&dataStore[nextOffset], numBits);
nextOffset += numBits;
return {&iter.first->second, true};
return {iter.first->second, true};
}
};

Expand Down Expand Up @@ -239,7 +241,7 @@ struct borrowtodestructure::Implementation {

void cleanup();

AvailableValues &computeAvailableValues(SILBasicBlock *block);
AvailableValues computeAvailableValues(SILBasicBlock *block);

/// Returns mark_unresolved_non_copyable_value if we are processing borrows or
/// the enum argument if we are processing switch_enum.
Expand Down Expand Up @@ -691,23 +693,24 @@ static void dumpSmallestTypeAvailable(
/// ensures that we match at the source level the assumption by users that they
/// can use entire valid parts as late as possible. If we were to do it earlier
/// we would emit errors too early.
AvailableValues &Implementation::computeAvailableValues(SILBasicBlock *block) {
AvailableValues Implementation::computeAvailableValues(SILBasicBlock *block) {
LLVM_DEBUG(llvm::dbgs() << " Computing Available Values For bb"
<< block->getDebugID() << '\n');

// First grab our block. If we already have state for the block, just return
// its available values. We already computed the available values and
// potentially updated it with new destructured values for our block.
ASSERT(blockToAvailableValues.has_value());
auto pair = blockToAvailableValues->get(block);
if (!pair.second) {
LLVM_DEBUG(llvm::dbgs()
<< " Already have values! Returning them!\n");
LLVM_DEBUG(pair.first->print(llvm::dbgs(), " "));
return *pair.first;
LLVM_DEBUG(pair.first.print(llvm::dbgs(), " "));
return pair.first;
}

LLVM_DEBUG(llvm::dbgs() << " No values computed! Initializing!\n");
auto &newValues = *pair.first;
AvailableValues newValues = pair.first;

// Otherwise, we need to initialize our available values with predecessor
// information.
Expand Down Expand Up @@ -814,7 +817,7 @@ AvailableValues &Implementation::computeAvailableValues(SILBasicBlock *block) {
<< " Recursively loading its available values to "
"compute initial smallest type available for block bb"
<< block->getDebugID() << '\n');
auto &predAvailableValues = computeAvailableValues(bb);
auto predAvailableValues = computeAvailableValues(bb);
LLVM_DEBUG(
llvm::dbgs()
<< " Computing initial smallest type available for block bb"
Expand All @@ -841,7 +844,7 @@ AvailableValues &Implementation::computeAvailableValues(SILBasicBlock *block) {
<< bb->getDebugID() << '\n');
LLVM_DEBUG(llvm::dbgs()
<< " Recursively loading its available values!\n");
auto &predAvailableValues = computeAvailableValues(bb);
auto predAvailableValues = computeAvailableValues(bb);
for (unsigned i : range(predAvailableValues.size())) {
if (!smallestTypeAvailable[i].has_value())
continue;
Expand Down Expand Up @@ -881,7 +884,7 @@ AvailableValues &Implementation::computeAvailableValues(SILBasicBlock *block) {
for (auto *predBlock : predsSkippingBackEdges) {
SWIFT_DEFER { typeSpanToValue.clear(); };

auto &predAvailableValues = computeAvailableValues(predBlock);
auto predAvailableValues = computeAvailableValues(predBlock);

// First go through our available values and initialize our interval map. We
// should never fail to insert. We want to insert /all/ available values so
Expand Down Expand Up @@ -997,7 +1000,7 @@ AvailableValues &Implementation::computeAvailableValues(SILBasicBlock *block) {
// phis.
SILValue sameValue;
for (auto *predBlock : predsSkippingBackEdges) {
auto &predAvailableValues = computeAvailableValues(predBlock);
auto predAvailableValues = computeAvailableValues(predBlock);
if (!sameValue) {
sameValue = predAvailableValues[i];
} else if (sameValue != predAvailableValues[i]) {
Expand All @@ -1018,7 +1021,7 @@ AvailableValues &Implementation::computeAvailableValues(SILBasicBlock *block) {
}

for (auto *predBlock : predsSkippingBackEdges) {
auto &predAvailableValues = computeAvailableValues(predBlock);
auto predAvailableValues = computeAvailableValues(predBlock);
addNewEdgeValueToBranch(predBlock->getTerminator(), block,
predAvailableValues[i], deleter);
}
Expand Down Expand Up @@ -1181,7 +1184,7 @@ void Implementation::rewriteUses(InstructionDeleter *deleter) {
// block.
LLVM_DEBUG(llvm::dbgs()
<< " Found needed bits! Propagating available values!\n");
auto &availableValues = computeAvailableValues(block);
auto availableValues = computeAvailableValues(block);
LLVM_DEBUG(llvm::dbgs() << " Computed available values for block bb"
<< block->getDebugID() << '\n';
availableValues.print(llvm::dbgs(), " "));
Expand Down