Skip to content

Commit 4792d68

Browse files
authored
Merge pull request #2204 from swiftwasm/main
[pull] swiftwasm from main
2 parents 315fb7a + f677d19 commit 4792d68

File tree

21 files changed

+238
-46
lines changed

21 files changed

+238
-46
lines changed

include/swift/AST/DeclContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,6 @@ class IterableDeclContext {
873873
/// available.
874874
Optional<std::string> getBodyFingerprint() const;
875875

876-
bool areTokensHashedForThisBodyInsteadOfInterfaceHash() const;
877-
878876
private:
879877
/// Add a member to the list for iteration purposes, but do not notify the
880878
/// subclass that we have done so.

include/swift/SIL/Dominance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ class PostDominanceInfo : public PostDominatorTreeBase {
149149
PostDominanceInfo(SILFunction *F);
150150

151151
bool properlyDominates(SILInstruction *A, SILInstruction *B);
152+
bool properlyDominates(SILValue A, SILInstruction *B);
152153

153154
void verify() const;
154155

include/swift/SIL/SILNodes.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
592592

593593
// Accessing memory
594594
SINGLE_VALUE_INST(LoadInst, load,
595-
SingleValueInstruction, MayRead, DoesNotRelease)
595+
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
596596
SINGLE_VALUE_INST(LoadBorrowInst, load_borrow,
597597
SingleValueInstruction, MayRead, DoesNotRelease)
598598
SINGLE_VALUE_INST(BeginBorrowInst, begin_borrow,
@@ -852,7 +852,7 @@ NON_VALUE_INST(BeginUnpairedAccessInst, begin_unpaired_access,
852852
NON_VALUE_INST(EndUnpairedAccessInst, end_unpaired_access,
853853
SILInstruction, MayHaveSideEffects, DoesNotRelease)
854854
NON_VALUE_INST(StoreInst, store,
855-
SILInstruction, MayWrite, DoesNotRelease)
855+
SILInstruction, MayHaveSideEffects, MayRelease)
856856
NON_VALUE_INST(AssignInst, assign,
857857
SILInstruction, MayWrite, DoesNotRelease)
858858
NON_VALUE_INST(AssignByWrapperInst, assign_by_wrapper,

lib/AST/DeclContext.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,16 +1022,6 @@ Optional<std::string> IterableDeclContext::getBodyFingerprint() const {
10221022
.fingerprint;
10231023
}
10241024

1025-
bool IterableDeclContext::areTokensHashedForThisBodyInsteadOfInterfaceHash()
1026-
const {
1027-
// Do not keep separate hashes for extension bodies because the dependencies
1028-
// can miss the addition of a member in an extension because there is nothing
1029-
// corresponding to the fingerprinted nominal dependency node.
1030-
if (isa<ExtensionDecl>(this))
1031-
return false;
1032-
return true;
1033-
}
1034-
10351025
/// Return the DeclContext to compare when checking private access in
10361026
/// Swift 4 mode. The context returned is the type declaration if the context
10371027
/// and the type declaration are in the same file, otherwise it is the types

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,12 +4765,9 @@ Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag,
47654765

47664766
// If we're hashing the type body separately, record the curly braces but
47674767
// nothing inside for the interface hash.
4768-
Optional<llvm::SaveAndRestore<Optional<llvm::MD5>>> MemberHashingScope;
4769-
if (IDC->areTokensHashedForThisBodyInsteadOfInterfaceHash()) {
4770-
recordTokenHash("{");
4771-
recordTokenHash("}");
4772-
MemberHashingScope.emplace(CurrentTokenHash, llvm::MD5());
4773-
}
4768+
llvm::SaveAndRestore<Optional<llvm::MD5>> MemberHashingScope{CurrentTokenHash, llvm::MD5()};
4769+
recordTokenHash("{");
4770+
recordTokenHash("}");
47744771

47754772
std::vector<Decl *> decls;
47764773
ParserStatus Status;
@@ -4802,8 +4799,7 @@ Parser::parseDeclList(SourceLoc LBLoc, SourceLoc &RBLoc, Diag<> ErrorDiag,
48024799
hadError = true;
48034800

48044801
llvm::MD5::MD5Result result;
4805-
auto declListHash = MemberHashingScope ? *CurrentTokenHash : llvm::MD5();
4806-
declListHash.final(result);
4802+
CurrentTokenHash->final(result);
48074803
llvm::SmallString<32> tokenHashString;
48084804
llvm::MD5::stringifyResult(result, tokenHashString);
48094805
return std::make_pair(decls, tokenHashString.str().str());

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,19 @@ OwnershipConstraintClassifier::visitBuiltinInst(BuiltinInst *bi) {
913913
Optional<OwnershipConstraint> Operand::getOwnershipConstraint() const {
914914
if (isTypeDependent())
915915
return None;
916+
917+
// If we do not have ownership enabled, just return any. This ensures that we
918+
// do not have any consuming uses and everything from an ownership perspective
919+
// is just a liveness use short-circuiting many of the optimizations.
920+
//
921+
// We do not ever call this function when an instruction isn't in a block.
922+
assert(getUser()->getParent() &&
923+
"Can not lookup ownership constraint unless inserted into block");
924+
if (auto *block = getUser()->getParent())
925+
if (auto *func = block->getParent())
926+
if (!func->hasOwnership())
927+
return {{OwnershipKind::Any, UseLifetimeConstraint::NonLifetimeEnding}};
928+
916929
OwnershipConstraintClassifier classifier(getUser()->getModule(), *this);
917930
return classifier.visit(const_cast<SILInstruction *>(getUser()));
918931
}

lib/SIL/IR/SILInstruction.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,36 @@ SILInstruction::MemoryBehavior SILInstruction::getMemoryBehavior() const {
10291029
MemoryBehavior::MayHaveSideEffects;
10301030
}
10311031

1032+
if (auto *li = dyn_cast<LoadInst>(this)) {
1033+
switch (li->getOwnershipQualifier()) {
1034+
case LoadOwnershipQualifier::Unqualified:
1035+
case LoadOwnershipQualifier::Trivial:
1036+
return MemoryBehavior::MayRead;
1037+
case LoadOwnershipQualifier::Take:
1038+
// Take deinitializes the underlying memory. Until we separate notions of
1039+
// memory writing from deinitialization (since a take doesn't actually
1040+
// write to the memory), lets be conservative and treat it as may read
1041+
// write.
1042+
return MemoryBehavior::MayReadWrite;
1043+
case LoadOwnershipQualifier::Copy:
1044+
return MemoryBehavior::MayHaveSideEffects;
1045+
}
1046+
llvm_unreachable("Covered switch isn't covered?!");
1047+
}
1048+
1049+
if (auto *si = dyn_cast<StoreInst>(this)) {
1050+
switch (si->getOwnershipQualifier()) {
1051+
case StoreOwnershipQualifier::Unqualified:
1052+
case StoreOwnershipQualifier::Trivial:
1053+
case StoreOwnershipQualifier::Init:
1054+
return MemoryBehavior::MayWrite;
1055+
case StoreOwnershipQualifier::Assign:
1056+
// For the release.
1057+
return MemoryBehavior::MayHaveSideEffects;
1058+
}
1059+
llvm_unreachable("Covered switch isn't covered?!");
1060+
}
1061+
10321062
switch (getKind()) {
10331063
#define FULL_INST(CLASS, TEXTUALNAME, PARENT, MEMBEHAVIOR, RELEASINGBEHAVIOR) \
10341064
case SILInstructionKind::CLASS: \
@@ -1138,6 +1168,18 @@ bool SILInstruction::mayRelease() const {
11381168
}
11391169
return true;
11401170
}
1171+
case SILInstructionKind::StoreInst:
1172+
switch (cast<StoreInst>(this)->getOwnershipQualifier()) {
1173+
case StoreOwnershipQualifier::Unqualified:
1174+
case StoreOwnershipQualifier::Init:
1175+
case StoreOwnershipQualifier::Trivial:
1176+
return false;
1177+
case StoreOwnershipQualifier::Assign:
1178+
// Assign destroys the old value that was in the memory location before we
1179+
// write the new value into the location.
1180+
return true;
1181+
}
1182+
llvm_unreachable("Covered switch isn't covered?!");
11411183
}
11421184
}
11431185

lib/SIL/IR/SILUndef.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using namespace swift;
1717

1818
static ValueOwnershipKind getOwnershipKindForUndef(SILType type, const SILFunction &f) {
19+
if (!f.hasOwnership())
20+
return OwnershipKind::None;
1921
if (type.isAddress() || type.isTrivial(f))
2022
return OwnershipKind::None;
2123
return OwnershipKind::Owned;

lib/SIL/IR/ValueOwnership.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,19 @@ ValueOwnershipKindClassifier::visitBuiltinInst(BuiltinInst *BI) {
583583
//===----------------------------------------------------------------------===//
584584

585585
ValueOwnershipKind SILValue::getOwnershipKind() const {
586+
// If we do not have an undef, we should always be able to get to our function
587+
// here. If we do not have ownership enabled, just return none for everything
588+
// to short circuit ownership optimizations. If we have an undef we may still
589+
// get some results that are slightly wonky but hopefully when we lower
590+
// ownership we remove that.
591+
//
592+
// We assume that any time we are in SILBuilder and call this without having a
593+
// value in a block yet, ossa is enabled.
594+
if (auto *block = Value->getParentBlock())
595+
if (auto *f = block->getParent())
596+
if (!f->hasOwnership())
597+
return OwnershipKind::None;
598+
586599
ValueOwnershipKindClassifier Classifier;
587600
auto result = Classifier.visit(const_cast<ValueBase *>(Value));
588601
assert(result && "Returned ownership kind invalid on values");

lib/SIL/Utils/Dominance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ properlyDominates(SILInstruction *I1, SILInstruction *I2) {
114114
return true;
115115
}
116116

117+
bool PostDominanceInfo::properlyDominates(SILValue A, SILInstruction *B) {
118+
if (auto *Inst = A->getDefiningInstruction()) {
119+
return properlyDominates(Inst, B);
120+
}
121+
if (auto *Arg = dyn_cast<SILArgument>(A)) {
122+
return dominates(Arg->getParent(), B->getParent());
123+
}
124+
return false;
125+
}
126+
117127
void PostDominanceInfo::verify() const {
118128
// Recompute.
119129
//

0 commit comments

Comments
 (0)