mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
add a SILType::isTrivial helper function.
Swift SVN r10610
This commit is contained in:
@@ -248,6 +248,9 @@ public:
|
|||||||
return isAddressOnly(getSwiftRValueType(), M);
|
return isAddressOnly(getSwiftRValueType(), M);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True if the type, or the referenced type of an address type, is trivial.
|
||||||
|
bool isTrivial(SILModule &M) const;
|
||||||
|
|
||||||
/// Returns true if the referenced type has reference semantics.
|
/// Returns true if the referenced type has reference semantics.
|
||||||
bool hasReferenceSemantics() const {
|
bool hasReferenceSemantics() const {
|
||||||
return getSwiftRValueType().hasReferenceSemantics();
|
return getSwiftRValueType().hasReferenceSemantics();
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ static bool isReturnedOwned(IRGenModule &IGM, SILResultInfo result) {
|
|||||||
case ResultConvention::Owned: return true;
|
case ResultConvention::Owned: return true;
|
||||||
case ResultConvention::Autoreleased: return false;
|
case ResultConvention::Autoreleased: return false;
|
||||||
case ResultConvention::Unowned:
|
case ResultConvention::Unowned:
|
||||||
return IGM.SILMod->getTypeLowering(result.getSILType()).isTrivial();
|
return result.getSILType().isTrivial(*IGM.SILMod);
|
||||||
}
|
}
|
||||||
llvm_unreachable("bad result convention");
|
llvm_unreachable("bad result convention");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,3 +285,8 @@ SILType SILType::getBuiltinFloatType(BuiltinFloatType::FPKind Kind,
|
|||||||
}
|
}
|
||||||
return getPrimitiveObjectType(CanType(ty));
|
return getPrimitiveObjectType(CanType(ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SILType::isTrivial(SILModule &M) const {
|
||||||
|
return M.getTypeLowering(*this).isTrivial();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -122,13 +122,12 @@ ManagedValue SILGenFunction::emitManagedBufferWithCleanup(SILValue v) {
|
|||||||
ManagedValue SILGenFunction::emitManagedBufferWithCleanup(SILValue v,
|
ManagedValue SILGenFunction::emitManagedBufferWithCleanup(SILValue v,
|
||||||
const TypeLowering &lowering) {
|
const TypeLowering &lowering) {
|
||||||
assert(lowering.getLoweredType().getAddressType() == v.getType());
|
assert(lowering.getLoweredType().getAddressType() == v.getType());
|
||||||
if (lowering.isTrivial()) {
|
if (lowering.isTrivial())
|
||||||
return ManagedValue::forUnmanaged(v);
|
return ManagedValue::forUnmanaged(v);
|
||||||
} else {
|
|
||||||
Cleanups.pushCleanup<CleanupMaterializedValue>(v);
|
Cleanups.pushCleanup<CleanupMaterializedValue>(v);
|
||||||
return ManagedValue(v, getTopCleanup());
|
return ManagedValue(v, getTopCleanup());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void destroyRValue(SILGenFunction &SGF, CleanupLocation loc,
|
static void destroyRValue(SILGenFunction &SGF, CleanupLocation loc,
|
||||||
SILValue value, const TypeLowering &valueTL) {
|
SILValue value, const TypeLowering &valueTL) {
|
||||||
@@ -609,13 +608,12 @@ ManagedValue SILGenFunction::manageBufferForExprResult(SILValue buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a cleanup for the temporary we allocated.
|
// Add a cleanup for the temporary we allocated.
|
||||||
if (bufferTL.isTrivial()) {
|
if (bufferTL.isTrivial())
|
||||||
return ManagedValue::forUnmanaged(buffer);
|
return ManagedValue::forUnmanaged(buffer);
|
||||||
} else {
|
|
||||||
Cleanups.pushCleanup<CleanupMaterializedValue>(buffer);
|
Cleanups.pushCleanup<CleanupMaterializedValue>(buffer);
|
||||||
return ManagedValue(buffer, getTopCleanup());
|
return ManagedValue(buffer, getTopCleanup());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Materialize SILGenFunction::emitMaterialize(SILLocation loc, ManagedValue v) {
|
Materialize SILGenFunction::emitMaterialize(SILLocation loc, ManagedValue v) {
|
||||||
assert(!v.isLValue() && "materializing an lvalue?!");
|
assert(!v.isLValue() && "materializing an lvalue?!");
|
||||||
|
|||||||
@@ -46,15 +46,13 @@ static void LowerAssignInstruction(SILBuilder &B, AssignInst *Inst,
|
|||||||
auto &M = Inst->getModule();
|
auto &M = Inst->getModule();
|
||||||
SILValue Src = Inst->getSrc();
|
SILValue Src = Inst->getSrc();
|
||||||
|
|
||||||
auto &destTL = M.getTypeLowering(Inst->getDest().getType());
|
|
||||||
|
|
||||||
// If this is an initialization, or the storage type is trivial, we
|
// If this is an initialization, or the storage type is trivial, we
|
||||||
// can just replace the assignment with a store.
|
// can just replace the assignment with a store.
|
||||||
|
|
||||||
// Otherwise, if it has trivial type, we can always just replace the
|
// Otherwise, if it has trivial type, we can always just replace the
|
||||||
// assignment with a store. If it has non-trivial type and is an
|
// assignment with a store. If it has non-trivial type and is an
|
||||||
// initialization, we can also replace it with a store.
|
// initialization, we can also replace it with a store.
|
||||||
if (isInitialization || destTL.isTrivial()) {
|
if (isInitialization || Inst->getDest().getType().isTrivial(M)) {
|
||||||
B.createStore(Inst->getLoc(), Src, Inst->getDest());
|
B.createStore(Inst->getLoc(), Src, Inst->getDest());
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, we need to replace the assignment with the full
|
// Otherwise, we need to replace the assignment with the full
|
||||||
@@ -62,11 +60,12 @@ static void LowerAssignInstruction(SILBuilder &B, AssignInst *Inst,
|
|||||||
// considered to be retained (by the semantics of the storage type),
|
// considered to be retained (by the semantics of the storage type),
|
||||||
// and we're transfering that ownership count into the destination.
|
// and we're transfering that ownership count into the destination.
|
||||||
|
|
||||||
// This is basically destTL.emitStoreOfCopy, except that if we have
|
// This is basically TypeLowering::emitStoreOfCopy, except that if we have
|
||||||
// a known incoming value, we can avoid the load.
|
// a known incoming value, we can avoid the load.
|
||||||
SILValue IncomingVal = B.createLoad(Inst->getLoc(), Inst->getDest());
|
SILValue IncomingVal = B.createLoad(Inst->getLoc(), Inst->getDest());
|
||||||
B.createStore(Inst->getLoc(), Src, Inst->getDest());
|
B.createStore(Inst->getLoc(), Src, Inst->getDest());
|
||||||
destTL.emitDestroyValue(B, Inst->getLoc(), IncomingVal);
|
|
||||||
|
B.emitDestroyValueOperation(Inst->getLoc(), IncomingVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
Inst->eraseFromParent();
|
Inst->eraseFromParent();
|
||||||
@@ -820,7 +819,7 @@ bool ElementPromotion::doIt() {
|
|||||||
// memory object will destruct the memory. If the memory (or some element
|
// memory object will destruct the memory. If the memory (or some element
|
||||||
// thereof) is not initialized on some path, the bad things happen. Process
|
// thereof) is not initialized on some path, the bad things happen. Process
|
||||||
// releases to adjust for this.
|
// releases to adjust for this.
|
||||||
if (!TheMemory->getModule().getTypeLowering(MemoryType).isTrivial()) {
|
if (!MemoryType.isTrivial(TheMemory->getModule())) {
|
||||||
for (unsigned i = 0; i != Releases.size(); ++i) {
|
for (unsigned i = 0; i != Releases.size(); ++i) {
|
||||||
if (processNonTrivialRelease(Releases[i])) {
|
if (processNonTrivialRelease(Releases[i])) {
|
||||||
Releases[i] = Releases.back();
|
Releases[i] = Releases.back();
|
||||||
@@ -1663,10 +1662,7 @@ bool ElementPromotion::promoteDestroyAddr(DestroyAddrInst *DAI) {
|
|||||||
DEBUG(llvm::errs() << " *** Promoting destroy_addr: " << *DAI << "\n");
|
DEBUG(llvm::errs() << " *** Promoting destroy_addr: " << *DAI << "\n");
|
||||||
DEBUG(llvm::errs() << " To value: " << *NewVal.getDef() << "\n");
|
DEBUG(llvm::errs() << " To value: " << *NewVal.getDef() << "\n");
|
||||||
|
|
||||||
auto &TL = DAI->getModule().getTypeLowering(MemoryType);
|
SILBuilder(DAI).emitDestroyValueOperation(DAI->getLoc(), NewVal);
|
||||||
SILBuilder B(DAI);
|
|
||||||
TL.emitDestroyValue(B, DAI->getLoc(), NewVal);
|
|
||||||
|
|
||||||
DAI->eraseFromParent();
|
DAI->eraseFromParent();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2203,7 +2199,7 @@ void ElementPromotion::tryToRemoveDeadAllocation() {
|
|||||||
|
|
||||||
// If the memory object has non-trivial type, then removing the deallocation
|
// If the memory object has non-trivial type, then removing the deallocation
|
||||||
// will drop any releases. Check that there is nothing preventing removal.
|
// will drop any releases. Check that there is nothing preventing removal.
|
||||||
if (!TheMemory->getModule().getTypeLowering(MemoryType).isTrivial()) {
|
if (!MemoryType.isTrivial(TheMemory->getModule())) {
|
||||||
for (auto *R : Releases) {
|
for (auto *R : Releases) {
|
||||||
if (isa<DeallocStackInst>(R) || isa<DeallocBoxInst>(R))
|
if (isa<DeallocStackInst>(R) || isa<DeallocBoxInst>(R))
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user