mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SIL] Added strong_copy_weak_value.
The new instruction unwraps an `@sil_weak` box and produces an owned value. It is only legal in opaque values mode and is transformed by `AddressLowering` to `load_weak`.
This commit is contained in:
@@ -1061,20 +1061,28 @@ public:
|
||||
getSILDebugLocation(Loc), ArgumentsSpecification, getModule()));
|
||||
}
|
||||
|
||||
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
Load##Name##Inst *createLoad##Name(SILLocation Loc, \
|
||||
SILValue src, \
|
||||
IsTake_t isTake) { \
|
||||
return insert(new (getModule()) \
|
||||
Load##Name##Inst(getSILDebugLocation(Loc), src, isTake)); \
|
||||
} \
|
||||
Store##Name##Inst *createStore##Name(SILLocation Loc, \
|
||||
SILValue value, \
|
||||
SILValue dest, \
|
||||
IsInitialization_t isInit) { \
|
||||
return insert(new (getModule()) \
|
||||
Store##Name##Inst(getSILDebugLocation(Loc), value, dest, isInit)); \
|
||||
#define COPYABLE_STORAGE_HELPER(Name) \
|
||||
StrongCopy##Name##ValueInst *createStrongCopy##Name##Value( \
|
||||
SILLocation Loc, SILValue operand) { \
|
||||
auto type = getFunction().getLoweredType( \
|
||||
operand->getType().getASTType().getReferenceStorageReferent()); \
|
||||
return insert(new (getModule()) StrongCopy##Name##ValueInst( \
|
||||
getSILDebugLocation(Loc), operand, type)); \
|
||||
}
|
||||
|
||||
#define LOADABLE_STORAGE_HELPER(Name) \
|
||||
Load##Name##Inst *createLoad##Name(SILLocation Loc, SILValue src, \
|
||||
IsTake_t isTake) { \
|
||||
return insert(new (getModule()) Load##Name##Inst(getSILDebugLocation(Loc), \
|
||||
src, isTake)); \
|
||||
} \
|
||||
Store##Name##Inst *createStore##Name(SILLocation Loc, SILValue value, \
|
||||
SILValue dest, \
|
||||
IsInitialization_t isInit) { \
|
||||
return insert(new (getModule()) Store##Name##Inst( \
|
||||
getSILDebugLocation(Loc), value, dest, isInit)); \
|
||||
}
|
||||
|
||||
#define LOADABLE_REF_STORAGE_HELPER(Name) \
|
||||
Name##ToRefInst *create##Name##ToRef(SILLocation Loc, SILValue op, \
|
||||
SILType ty) { \
|
||||
@@ -1085,41 +1093,45 @@ public:
|
||||
SILType ty) { \
|
||||
return insert(new (getModule()) \
|
||||
RefTo##Name##Inst(getSILDebugLocation(Loc), op, ty)); \
|
||||
} \
|
||||
StrongCopy##Name##ValueInst *createStrongCopy##Name##Value( \
|
||||
SILLocation Loc, SILValue operand) { \
|
||||
auto type = getFunction().getLoweredType( \
|
||||
operand->getType().getASTType().getReferenceStorageReferent()); \
|
||||
return insert(new (getModule()) StrongCopy##Name##ValueInst( \
|
||||
getSILDebugLocation(Loc), operand, type)); \
|
||||
}
|
||||
|
||||
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name) \
|
||||
StrongRetain##Name##Inst *createStrongRetain##Name(SILLocation Loc, \
|
||||
SILValue Operand, \
|
||||
Atomicity atomicity) { \
|
||||
return insert(new (getModule()) \
|
||||
StrongRetain##Name##Inst(getSILDebugLocation(Loc), Operand, atomicity)); \
|
||||
} \
|
||||
Name##RetainInst *create##Name##Retain(SILLocation Loc, SILValue Operand, \
|
||||
Atomicity atomicity) { \
|
||||
return insert(new (getModule()) \
|
||||
Name##RetainInst(getSILDebugLocation(Loc), Operand, atomicity)); \
|
||||
} \
|
||||
Name##ReleaseInst *create##Name##Release(SILLocation Loc, \
|
||||
SILValue Operand, \
|
||||
Atomicity atomicity) { \
|
||||
return insert(new (getModule()) \
|
||||
Name##ReleaseInst(getSILDebugLocation(Loc), Operand, atomicity)); \
|
||||
#define RETAINABLE_STORAGE_HELPER(Name) \
|
||||
StrongRetain##Name##Inst *createStrongRetain##Name( \
|
||||
SILLocation Loc, SILValue Operand, Atomicity atomicity) { \
|
||||
return insert(new (getModule()) StrongRetain##Name##Inst( \
|
||||
getSILDebugLocation(Loc), Operand, atomicity)); \
|
||||
} \
|
||||
Name##RetainInst *create##Name##Retain(SILLocation Loc, SILValue Operand, \
|
||||
Atomicity atomicity) { \
|
||||
return insert(new (getModule()) Name##RetainInst(getSILDebugLocation(Loc), \
|
||||
Operand, atomicity)); \
|
||||
} \
|
||||
Name##ReleaseInst *create##Name##Release(SILLocation Loc, SILValue Operand, \
|
||||
Atomicity atomicity) { \
|
||||
return insert(new (getModule()) Name##ReleaseInst( \
|
||||
getSILDebugLocation(Loc), Operand, atomicity)); \
|
||||
}
|
||||
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, "...") \
|
||||
ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, "...")
|
||||
#define UNCHECKED_REF_STORAGE(Name, ...) \
|
||||
|
||||
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name) \
|
||||
RETAINABLE_STORAGE_HELPER(Name)
|
||||
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name) \
|
||||
LOADABLE_STORAGE_HELPER(Name) \
|
||||
RETAINABLE_STORAGE_HELPER(Name)
|
||||
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name) \
|
||||
LOADABLE_STORAGE_HELPER(Name)
|
||||
#define UNCHECKED_REF_STORAGE(Name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name)
|
||||
#include "swift/AST/ReferenceStorage.def"
|
||||
#undef LOADABLE_STORAGE_HELPER
|
||||
#undef LOADABLE_REF_STORAGE_HELPER
|
||||
#undef COPYABLE_STORAGE_HELPER
|
||||
#undef RETAINABLE_STORAGE_HELPER
|
||||
|
||||
CopyAddrInst *createCopyAddr(SILLocation Loc, SILValue srcAddr,
|
||||
SILValue destAddr, IsTake_t isTake,
|
||||
|
||||
@@ -1407,7 +1407,17 @@ SILCloner<ImplClass>::visitDebugStepInst(DebugStepInst *Inst) {
|
||||
recordClonedInstruction(Inst, getBuilder().createDebugStep(Inst->getLoc()));
|
||||
}
|
||||
|
||||
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
#define COPYABLE_STORAGE_HELPER(Name, name) \
|
||||
template <typename ImplClass> \
|
||||
void SILCloner<ImplClass>::visitStrongCopy##Name##ValueInst( \
|
||||
StrongCopy##Name##ValueInst *Inst) { \
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope())); \
|
||||
recordClonedInstruction(Inst, getBuilder().createStrongCopy##Name##Value( \
|
||||
getOpLocation(Inst->getLoc()), \
|
||||
getOpValue(Inst->getOperand()))); \
|
||||
}
|
||||
|
||||
#define LOADABLE_STORAGE_HELPER(Name, name) \
|
||||
template <typename ImplClass> \
|
||||
void SILCloner<ImplClass>::visitLoad##Name##Inst(Load##Name##Inst *Inst) { \
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope())); \
|
||||
@@ -1441,17 +1451,8 @@ SILCloner<ImplClass>::visitDebugStepInst(DebugStepInst *Inst) {
|
||||
Inst, getBuilder().create##Name##ToRef(getOpLocation(Inst->getLoc()), \
|
||||
getOpValue(Inst->getOperand()), \
|
||||
getOpType(Inst->getType()))); \
|
||||
} \
|
||||
template <typename ImplClass> \
|
||||
void SILCloner<ImplClass>::visitStrongCopy##Name##ValueInst( \
|
||||
StrongCopy##Name##ValueInst *Inst) { \
|
||||
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope())); \
|
||||
recordClonedInstruction(Inst, getBuilder().createStrongCopy##Name##Value( \
|
||||
getOpLocation(Inst->getLoc()), \
|
||||
getOpValue(Inst->getOperand()))); \
|
||||
}
|
||||
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name, name) \
|
||||
#define RETAINABLE_STORAGE_HELPER(Name, name) \
|
||||
template <typename ImplClass> \
|
||||
void SILCloner<ImplClass>::visitStrongRetain##Name##Inst( \
|
||||
StrongRetain##Name##Inst *Inst) { \
|
||||
@@ -1478,13 +1479,26 @@ SILCloner<ImplClass>::visitDebugStepInst(DebugStepInst *Inst) {
|
||||
getOpValue(Inst->getOperand()), \
|
||||
Inst->getAtomicity())); \
|
||||
}
|
||||
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, name, "...") \
|
||||
ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, name, "...")
|
||||
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
|
||||
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name, name) \
|
||||
LOADABLE_STORAGE_HELPER(Name, name)
|
||||
#define ALWAYS_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name, name) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name, name) \
|
||||
RETAINABLE_STORAGE_HELPER(Name, name)
|
||||
#define SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name, name) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name, name) \
|
||||
LOADABLE_STORAGE_HELPER(Name, name) \
|
||||
RETAINABLE_STORAGE_HELPER(Name, name)
|
||||
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
|
||||
COPYABLE_STORAGE_HELPER(Name, name) \
|
||||
LOADABLE_REF_STORAGE_HELPER(Name, name)
|
||||
#include "swift/AST/ReferenceStorage.def"
|
||||
#undef LOADABLE_STORAGE_HELPER
|
||||
#undef LOADABLE_REF_STORAGE_HELPER
|
||||
#undef COPYABLE_STORAGE_HELPER
|
||||
#undef RETAINABLE_STORAGE_HELPER
|
||||
|
||||
template<typename ImplClass>
|
||||
void
|
||||
|
||||
@@ -8098,6 +8098,17 @@ class ExplicitCopyValueInst
|
||||
: UnaryInstructionBase(DebugLoc, operand, operand->getType()) {}
|
||||
};
|
||||
|
||||
#define NEVER_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
class StrongCopy##Name##ValueInst \
|
||||
: public UnaryInstructionBase< \
|
||||
SILInstructionKind::StrongCopy##Name##ValueInst, \
|
||||
SingleValueInstruction> { \
|
||||
friend class SILBuilder; \
|
||||
StrongCopy##Name##ValueInst(SILDebugLocation DebugLoc, SILValue operand, \
|
||||
SILType type) \
|
||||
: UnaryInstructionBase(DebugLoc, operand, \
|
||||
type.getReferenceStorageReferentType()) {} \
|
||||
};
|
||||
#define UNCHECKED_REF_STORAGE(Name, ...) \
|
||||
class StrongCopy##Name##ValueInst \
|
||||
: public UnaryInstructionBase< \
|
||||
@@ -8108,7 +8119,6 @@ class ExplicitCopyValueInst
|
||||
SILType type) \
|
||||
: UnaryInstructionBase(DebugLoc, operand, type) {} \
|
||||
};
|
||||
|
||||
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, ...) \
|
||||
class StrongCopy##Name##ValueInst \
|
||||
: public UnaryInstructionBase< \
|
||||
|
||||
@@ -453,10 +453,7 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
|
||||
// alone by OSSA optimizations.
|
||||
SINGLE_VALUE_INST(ExplicitCopyValueInst, explicit_copy_value,
|
||||
SingleValueInstruction, None, DoesNotRelease)
|
||||
#define UNCHECKED_REF_STORAGE(Name, name, ...) \
|
||||
SINGLE_VALUE_INST(StrongCopy##Name##ValueInst, strong_copy_##name##_value, \
|
||||
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
|
||||
#define ALWAYS_OR_SOMETIMES_LOADABLE_CHECKED_REF_STORAGE(Name, name, ...) \
|
||||
#define REF_STORAGE(Name, name, ...) \
|
||||
SINGLE_VALUE_INST(StrongCopy##Name##ValueInst, strong_copy_##name##_value, \
|
||||
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
|
||||
#include "swift/AST/ReferenceStorage.def"
|
||||
|
||||
Reference in New Issue
Block a user