Skip to content

Commit

Permalink
Merge pull request swiftlang#22574 from gottesmm/pr-0374b60d0d4fdf594…
Browse files Browse the repository at this point in the history
…6a9a1c9cb616fbfd6407e51
  • Loading branch information
swift-ci committed Feb 13, 2019
2 parents cac8363 + 0cdc2d6 commit a19e09f
Show file tree
Hide file tree
Showing 6 changed files with 1,333 additions and 113 deletions.
28 changes: 28 additions & 0 deletions include/swift/SIL/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,34 @@ tupleextract_ty<LTy> m_TupleExtractInst(const LTy &Left, unsigned Index) {
return tupleextract_ty<LTy>(Left, Index);
}

/// Match either a tuple_extract that the index field from a tuple or the
/// indexth destructure_tuple result.
template <typename LTy> struct tupleextractoperation_ty {
LTy L;
unsigned index;
tupleextractoperation_ty(const LTy &Left, unsigned i) : L(Left), index(i) {}

template <typename ITy> bool match(ITy *V) {
if (auto *TEI = dyn_cast<TupleExtractInst>(V)) {
return TEI->getFieldNo() == index &&
L.match((ValueBase *)TEI->getOperand());
}

if (auto *DTR = dyn_cast<DestructureTupleResult>(V)) {
return DTR->getIndex() == index &&
L.match((ValueBase *)DTR->getParent()->getOperand());
}

return false;
}
};

template <typename LTy>
tupleextractoperation_ty<LTy> m_TupleExtractOperation(const LTy &Left,
unsigned Index) {
return tupleextractoperation_ty<LTy>(Left, Index);
}

//===----------------------------------------------------------------------===//
// Function/Builtin/Intrinsic Application Matchers
//===----------------------------------------------------------------------===//
Expand Down
2 changes: 2 additions & 0 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ class SILInstruction
SILInstructionResultArray getResults() const { return getResultsImpl(); }
unsigned getNumResults() const { return getResults().size(); }

SILValue getResult(unsigned index) const { return getResults()[index]; }

/// Return the types of the results produced by this instruction.
SILInstructionResultArray::type_range getResultTypes() const {
return getResultsImpl().getTypes();
Expand Down
4 changes: 4 additions & 0 deletions include/swift/SILOptimizer/Utils/ConstantFolding.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class ConstantFolder {
/// Initialize the worklist with all instructions of the function \p F.
void initializeWorklist(SILFunction &F);

/// When asserts are enabled, dumps the worklist for diagnostic
/// purposes. Without asserts this is a no-op.
void dumpWorklist() const;

/// Initialize the worklist with a single instruction \p I.
void addToWorklist(SILInstruction *I) {
WorkList.insert(I);
Expand Down
16 changes: 8 additions & 8 deletions lib/SILOptimizer/Utils/CastOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,12 +1429,12 @@ static bool optimizeStaticallyKnownProtocolConformance(
}
case ExistentialRepresentation::Class: {
auto Value =
B.createLoad(Loc, Src, swift::LoadOwnershipQualifier::Unqualified);
B.emitLoadValueOperation(Loc, Src, LoadOwnershipQualifier::Take);
auto Existential =
B.createInitExistentialRef(Loc, Dest->getType().getObjectType(),
SourceType, Value, Conformances);
B.createStore(Loc, Existential, Dest,
swift::StoreOwnershipQualifier::Unqualified);
B.emitStoreValueOperation(Loc, Existential, Dest,
StoreOwnershipQualifier::Init);
break;
}
case ExistentialRepresentation::Boxed: {
Expand All @@ -1445,8 +1445,8 @@ static bool optimizeStaticallyKnownProtocolConformance(
// This needs to be a copy_addr (for now) because we must handle
// address-only types.
B.createCopyAddr(Loc, Src, Projection, IsTake, IsInitialization);
B.createStore(Loc, AllocBox, Dest,
swift::StoreOwnershipQualifier::Unqualified);
B.emitStoreValueOperation(Loc, AllocBox, Dest,
StoreOwnershipQualifier::Init);
break;
}
};
Expand Down Expand Up @@ -1489,12 +1489,12 @@ SILInstruction *CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(
if (!resultTL.isAddressOnly()) {
auto undef = SILValue(
SILUndef::get(DestType.getObjectType(), Builder.getModule()));
Builder.createStore(Loc, undef, Dest,
StoreOwnershipQualifier::Unqualified);
Builder.emitStoreValueOperation(Loc, undef, Dest,
StoreOwnershipQualifier::Init);
}
auto *TrapI = Builder.createBuiltinTrap(Loc);
EraseInstAction(Inst);
Builder.setInsertionPoint(std::next(SILBasicBlock::iterator(TrapI)));
Builder.setInsertionPoint(std::next(TrapI->getIterator()));
auto *UnreachableInst =
Builder.createUnreachable(ArtificialUnreachableLocation());

Expand Down
Loading

0 comments on commit a19e09f

Please sign in to comment.