Skip to content

Commit a19e09f

Browse files
authored
Merge pull request #22574 from gottesmm/pr-0374b60d0d4fdf5946a9a1c9cb616fbfd6407e51
2 parents cac8363 + 0cdc2d6 commit a19e09f

File tree

6 files changed

+1333
-113
lines changed

6 files changed

+1333
-113
lines changed

include/swift/SIL/PatternMatch.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,34 @@ tupleextract_ty<LTy> m_TupleExtractInst(const LTy &Left, unsigned Index) {
467467
return tupleextract_ty<LTy>(Left, Index);
468468
}
469469

470+
/// Match either a tuple_extract that the index field from a tuple or the
471+
/// indexth destructure_tuple result.
472+
template <typename LTy> struct tupleextractoperation_ty {
473+
LTy L;
474+
unsigned index;
475+
tupleextractoperation_ty(const LTy &Left, unsigned i) : L(Left), index(i) {}
476+
477+
template <typename ITy> bool match(ITy *V) {
478+
if (auto *TEI = dyn_cast<TupleExtractInst>(V)) {
479+
return TEI->getFieldNo() == index &&
480+
L.match((ValueBase *)TEI->getOperand());
481+
}
482+
483+
if (auto *DTR = dyn_cast<DestructureTupleResult>(V)) {
484+
return DTR->getIndex() == index &&
485+
L.match((ValueBase *)DTR->getParent()->getOperand());
486+
}
487+
488+
return false;
489+
}
490+
};
491+
492+
template <typename LTy>
493+
tupleextractoperation_ty<LTy> m_TupleExtractOperation(const LTy &Left,
494+
unsigned Index) {
495+
return tupleextractoperation_ty<LTy>(Left, Index);
496+
}
497+
470498
//===----------------------------------------------------------------------===//
471499
// Function/Builtin/Intrinsic Application Matchers
472500
//===----------------------------------------------------------------------===//

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ class SILInstruction
517517
SILInstructionResultArray getResults() const { return getResultsImpl(); }
518518
unsigned getNumResults() const { return getResults().size(); }
519519

520+
SILValue getResult(unsigned index) const { return getResults()[index]; }
521+
520522
/// Return the types of the results produced by this instruction.
521523
SILInstructionResultArray::type_range getResultTypes() const {
522524
return getResultsImpl().getTypes();

include/swift/SILOptimizer/Utils/ConstantFolding.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class ConstantFolder {
9292
/// Initialize the worklist with all instructions of the function \p F.
9393
void initializeWorklist(SILFunction &F);
9494

95+
/// When asserts are enabled, dumps the worklist for diagnostic
96+
/// purposes. Without asserts this is a no-op.
97+
void dumpWorklist() const;
98+
9599
/// Initialize the worklist with a single instruction \p I.
96100
void addToWorklist(SILInstruction *I) {
97101
WorkList.insert(I);

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,12 +1429,12 @@ static bool optimizeStaticallyKnownProtocolConformance(
14291429
}
14301430
case ExistentialRepresentation::Class: {
14311431
auto Value =
1432-
B.createLoad(Loc, Src, swift::LoadOwnershipQualifier::Unqualified);
1432+
B.emitLoadValueOperation(Loc, Src, LoadOwnershipQualifier::Take);
14331433
auto Existential =
14341434
B.createInitExistentialRef(Loc, Dest->getType().getObjectType(),
14351435
SourceType, Value, Conformances);
1436-
B.createStore(Loc, Existential, Dest,
1437-
swift::StoreOwnershipQualifier::Unqualified);
1436+
B.emitStoreValueOperation(Loc, Existential, Dest,
1437+
StoreOwnershipQualifier::Init);
14381438
break;
14391439
}
14401440
case ExistentialRepresentation::Boxed: {
@@ -1445,8 +1445,8 @@ static bool optimizeStaticallyKnownProtocolConformance(
14451445
// This needs to be a copy_addr (for now) because we must handle
14461446
// address-only types.
14471447
B.createCopyAddr(Loc, Src, Projection, IsTake, IsInitialization);
1448-
B.createStore(Loc, AllocBox, Dest,
1449-
swift::StoreOwnershipQualifier::Unqualified);
1448+
B.emitStoreValueOperation(Loc, AllocBox, Dest,
1449+
StoreOwnershipQualifier::Init);
14501450
break;
14511451
}
14521452
};
@@ -1489,12 +1489,12 @@ SILInstruction *CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(
14891489
if (!resultTL.isAddressOnly()) {
14901490
auto undef = SILValue(
14911491
SILUndef::get(DestType.getObjectType(), Builder.getModule()));
1492-
Builder.createStore(Loc, undef, Dest,
1493-
StoreOwnershipQualifier::Unqualified);
1492+
Builder.emitStoreValueOperation(Loc, undef, Dest,
1493+
StoreOwnershipQualifier::Init);
14941494
}
14951495
auto *TrapI = Builder.createBuiltinTrap(Loc);
14961496
EraseInstAction(Inst);
1497-
Builder.setInsertionPoint(std::next(SILBasicBlock::iterator(TrapI)));
1497+
Builder.setInsertionPoint(std::next(TrapI->getIterator()));
14981498
auto *UnreachableInst =
14991499
Builder.createUnreachable(ArtificialUnreachableLocation());
15001500

0 commit comments

Comments
 (0)