mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -294,7 +294,7 @@ public:
|
||||
case ProjectionKind::Enum:
|
||||
return BaseType.getEnumElementType(getEnumElementDecl(BaseType), M);
|
||||
case ProjectionKind::Box:
|
||||
return BaseType.castTo<SILBoxType>()->getFieldType(getIndex());
|
||||
return BaseType.castTo<SILBoxType>()->getFieldType(M, getIndex());
|
||||
case ProjectionKind::Tuple:
|
||||
return BaseType.getTupleElementType(getIndex());
|
||||
case ProjectionKind::Upcast:
|
||||
|
||||
@@ -488,6 +488,11 @@ public:
|
||||
LoadBorrowInst(getSILDebugLocation(Loc), LV));
|
||||
}
|
||||
|
||||
BeginBorrowInst *createBeginBorrow(SILLocation Loc, SILValue LV) {
|
||||
return insert(new (F.getModule())
|
||||
BeginBorrowInst(getSILDebugLocation(Loc), LV));
|
||||
}
|
||||
|
||||
StoreInst *createStore(SILLocation Loc, SILValue Src, SILValue DestAddr,
|
||||
StoreOwnershipQualifier Qualifier) {
|
||||
assert((Qualifier != StoreOwnershipQualifier::Unqualified) ||
|
||||
@@ -520,6 +525,12 @@ public:
|
||||
AssignInst(getSILDebugLocation(Loc), Src, DestAddr));
|
||||
}
|
||||
|
||||
StoreBorrowInst *createStoreBorrow(SILLocation Loc, SILValue Src,
|
||||
SILValue DestAddr) {
|
||||
return insert(new (F.getModule())
|
||||
StoreBorrowInst(getSILDebugLocation(Loc), Src, DestAddr));
|
||||
}
|
||||
|
||||
MarkUninitializedInst *
|
||||
createMarkUninitialized(SILLocation Loc, SILValue src,
|
||||
MarkUninitializedInst::Kind k) {
|
||||
@@ -1270,7 +1281,7 @@ public:
|
||||
ProjectBoxInst *createProjectBox(SILLocation Loc, SILValue boxOperand,
|
||||
unsigned index) {
|
||||
auto boxTy = boxOperand->getType().castTo<SILBoxType>();
|
||||
auto fieldTy = boxTy->getFieldType(index);
|
||||
auto fieldTy = boxTy->getFieldType(getModule(), index);
|
||||
|
||||
return insert(new (F.getModule()) ProjectBoxInst(
|
||||
getSILDebugLocation(Loc), boxOperand, index, fieldTy));
|
||||
|
||||
@@ -673,6 +673,14 @@ void SILCloner<ImplClass>::visitLoadBorrowInst(LoadBorrowInst *Inst) {
|
||||
getOpValue(Inst->getOperand())));
|
||||
}
|
||||
|
||||
template <typename ImplClass>
|
||||
void SILCloner<ImplClass>::visitBeginBorrowInst(BeginBorrowInst *Inst) {
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
|
||||
doPostProcess(Inst,
|
||||
getBuilder().createBeginBorrow(getOpLocation(Inst->getLoc()),
|
||||
getOpValue(Inst->getOperand())));
|
||||
}
|
||||
|
||||
template <typename ImplClass>
|
||||
void SILCloner<ImplClass>::visitStoreInst(StoreInst *Inst) {
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
|
||||
@@ -682,6 +690,15 @@ void SILCloner<ImplClass>::visitStoreInst(StoreInst *Inst) {
|
||||
Inst->getOwnershipQualifier()));
|
||||
}
|
||||
|
||||
template <typename ImplClass>
|
||||
void SILCloner<ImplClass>::visitStoreBorrowInst(StoreBorrowInst *Inst) {
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
|
||||
doPostProcess(Inst,
|
||||
getBuilder().createStoreBorrow(getOpLocation(Inst->getLoc()),
|
||||
getOpValue(Inst->getSrc()),
|
||||
getOpValue(Inst->getDest())));
|
||||
}
|
||||
|
||||
template <typename ImplClass>
|
||||
void SILCloner<ImplClass>::visitEndBorrowInst(EndBorrowInst *Inst) {
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
|
||||
|
||||
@@ -1747,6 +1747,46 @@ class LoadBorrowInst : public UnaryInstructionBase<ValueKind::LoadBorrowInst> {
|
||||
LValue->getType().getObjectType()) {}
|
||||
};
|
||||
|
||||
/// Represents the begin scope of a borrowed value. Must be paired with an
|
||||
/// end_borrow instruction in its use-def list.
|
||||
class BeginBorrowInst
|
||||
: public UnaryInstructionBase<ValueKind::BeginBorrowInst> {
|
||||
friend class SILBuilder;
|
||||
|
||||
BeginBorrowInst(SILDebugLocation DebugLoc, SILValue LValue)
|
||||
: UnaryInstructionBase(DebugLoc, LValue,
|
||||
LValue->getType().getObjectType()) {}
|
||||
};
|
||||
|
||||
/// Represents a store of a borrowed value into an address. Returns the borrowed
|
||||
/// address. Must be paired with a end_borrow in its use-def list.
|
||||
class StoreBorrowInst : public SILInstruction {
|
||||
friend class SILBuilder;
|
||||
|
||||
public:
|
||||
enum {
|
||||
/// The source of the value being borrowed.
|
||||
Src,
|
||||
/// The destination of the borrowed value.
|
||||
Dest
|
||||
};
|
||||
|
||||
private:
|
||||
FixedOperandList<2> Operands;
|
||||
StoreBorrowInst(SILDebugLocation DebugLoc, SILValue Src, SILValue Dest);
|
||||
|
||||
public:
|
||||
SILValue getSrc() const { return Operands[Src].get(); }
|
||||
SILValue getDest() const { return Operands[Dest].get(); }
|
||||
|
||||
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
|
||||
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
|
||||
|
||||
static bool classof(const ValueBase *V) {
|
||||
return V->getKind() == ValueKind::StoreBorrowInst;
|
||||
}
|
||||
};
|
||||
|
||||
/// Represents the end of a borrow scope for a value or address from another
|
||||
/// value or address.
|
||||
///
|
||||
|
||||
@@ -95,10 +95,12 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
|
||||
// Accessing memory
|
||||
INST(LoadInst, SILInstruction, load, MayRead, DoesNotRelease)
|
||||
INST(LoadBorrowInst, SILInstruction, load_borrow, MayRead, DoesNotRelease)
|
||||
INST(BeginBorrowInst, SILInstruction, begin_borrow, MayHaveSideEffects, DoesNotRelease)
|
||||
INST(EndBorrowInst, SILInstruction, end_borrow, MayHaveSideEffects, DoesNotRelease)
|
||||
INST(LoadUnownedInst, SILInstruction, load_unowned, MayRead, DoesNotRelease)
|
||||
INST(LoadWeakInst, SILInstruction, load_weak, MayRead, DoesNotRelease)
|
||||
INST(StoreInst, SILInstruction, store, MayWrite, DoesNotRelease)
|
||||
INST(StoreBorrowInst, SILInstruction, store_borrow, MayWrite, DoesNotRelease)
|
||||
INST(AssignInst, SILInstruction, assign, MayWrite, DoesNotRelease)
|
||||
INST(MarkUninitializedInst, SILInstruction, mark_uninitialized, None, DoesNotRelease)
|
||||
INST(MarkUninitializedBehaviorInst, SILInstruction, mark_uninitialized_behavior, None, DoesNotRelease)
|
||||
@@ -182,7 +184,7 @@ ABSTRACT_VALUE(SILInstruction, ValueBase)
|
||||
// Metatypes
|
||||
INST(MetatypeInst, SILInstruction, metatype, None, DoesNotRelease)
|
||||
INST(ValueMetatypeInst, SILInstruction, value_metatype, None, DoesNotRelease)
|
||||
INST(ExistentialMetatypeInst, SILInstruction, existential_metatype, None, DoesNotRelease)
|
||||
INST(ExistentialMetatypeInst, SILInstruction, existential_metatype, MayRead, DoesNotRelease)
|
||||
INST(ObjCProtocolInst, SILInstruction, objc_protocol, None, DoesNotRelease)
|
||||
|
||||
// Aggregate Types
|
||||
|
||||
@@ -588,17 +588,25 @@ inline SILType SILBlockStorageType::getCaptureAddressType() const {
|
||||
return SILType::getPrimitiveAddressType(getCaptureType());
|
||||
}
|
||||
|
||||
inline SILType SILBoxType::getBoxedAddressType() const {
|
||||
return SILType::getPrimitiveAddressType(getBoxedType());
|
||||
}
|
||||
|
||||
/// The hash of a SILType is the hash of its opaque value.
|
||||
static inline llvm::hash_code hash_value(SILType V) {
|
||||
return llvm::hash_value(V.getOpaqueValue());
|
||||
}
|
||||
|
||||
inline SILType SILBoxType::getFieldType(unsigned index) const {
|
||||
return SILType::getPrimitiveAddressType(getFieldLoweredType(index));
|
||||
|
||||
inline CanType
|
||||
SILBoxType::getFieldLoweredType(SILModule &M, unsigned index) const {
|
||||
auto fieldTy = getLayout()->getFields()[index].getLoweredType();
|
||||
// Apply generic arguments if the layout is generic.
|
||||
if (!getGenericArgs().empty()) {
|
||||
auto substMap =
|
||||
getLayout()->getGenericSignature()->getSubstitutionMap(getGenericArgs());
|
||||
fieldTy = fieldTy.subst(substMap)->getCanonicalType();
|
||||
}
|
||||
return fieldTy;
|
||||
}
|
||||
|
||||
inline SILType SILBoxType::getFieldType(SILModule &M, unsigned index) const {
|
||||
return SILType::getPrimitiveAddressType(getFieldLoweredType(M, index));
|
||||
}
|
||||
|
||||
inline SILType SILField::getAddressType() const {
|
||||
|
||||
Reference in New Issue
Block a user