Skip to content

Commit 0fce705

Browse files
authored
Merge pull request #24906 from gottesmm/pr-086b5df86583874c4bef884b5a495e2a1d16845c
Teach ConstExpr how to look through begin_borrow, copy_value and to i…
2 parents d05a748 + 86a7ce6 commit 0fce705

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/SILOptimizer/Utils/ConstExpr.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,11 @@ SymbolicValue ConstExprFunctionState::computeConstantValue(SILValue value) {
406406
if (auto *bai = dyn_cast<BeginAccessInst>(value))
407407
return getConstantValue(bai->getOperand());
408408

409+
// Look through copy_value and begin_borrow since the interpreter doesn't
410+
// model these memory management instructions.
411+
if (isa<CopyValueInst>(value) || isa<BeginBorrowInst>(value))
412+
return getConstantValue(cast<SingleValueInstruction>(value)->getOperand(0));
413+
409414
LLVM_DEBUG(llvm::dbgs() << "ConstExpr Unknown simple: " << *value << "\n");
410415

411416
// Otherwise, we don't know how to handle this.
@@ -1292,7 +1297,8 @@ ConstExprFunctionState::evaluateFlowSensitive(SILInstruction *inst) {
12921297
// skip them.
12931298
isa<DestroyAddrInst>(inst) || isa<RetainValueInst>(inst) ||
12941299
isa<ReleaseValueInst>(inst) || isa<StrongRetainInst>(inst) ||
1295-
isa<StrongReleaseInst>(inst))
1300+
isa<StrongReleaseInst>(inst) || isa<DestroyValueInst>(inst) ||
1301+
isa<EndBorrowInst>(inst))
12961302
return None;
12971303

12981304
// If this is a special flow-sensitive instruction like a stack allocation,
@@ -1302,6 +1308,15 @@ ConstExprFunctionState::evaluateFlowSensitive(SILInstruction *inst) {
13021308
return None;
13031309
}
13041310

1311+
// Make sure that our copy_value, begin_borrow form constants. Otherwise,
1312+
// return why.
1313+
if (isa<CopyValueInst>(inst) || isa<BeginBorrowInst>(inst)) {
1314+
auto result = getConstantValue(inst->getOperand(0));
1315+
if (!result.isConstant())
1316+
return result;
1317+
return None;
1318+
}
1319+
13051320
// If this is a deallocation of a memory object that we are tracking, then
13061321
// don't do anything. The memory is allocated in a BumpPtrAllocator so there
13071322
// is no useful way to free it.

0 commit comments

Comments
 (0)