add a SILType::isTrivial helper function.

Swift SVN r10610
This commit is contained in:
Chris Lattner
2013-11-20 22:53:49 +00:00
parent 5ad19d55b9
commit 07ce5306f3
5 changed files with 24 additions and 22 deletions

View File

@@ -248,6 +248,9 @@ public:
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.
bool hasReferenceSemantics() const {
return getSwiftRValueType().hasReferenceSemantics();

View File

@@ -108,7 +108,7 @@ static bool isReturnedOwned(IRGenModule &IGM, SILResultInfo result) {
case ResultConvention::Owned: return true;
case ResultConvention::Autoreleased: return false;
case ResultConvention::Unowned:
return IGM.SILMod->getTypeLowering(result.getSILType()).isTrivial();
return result.getSILType().isTrivial(*IGM.SILMod);
}
llvm_unreachable("bad result convention");
}

View File

@@ -285,3 +285,8 @@ SILType SILType::getBuiltinFloatType(BuiltinFloatType::FPKind Kind,
}
return getPrimitiveObjectType(CanType(ty));
}
bool SILType::isTrivial(SILModule &M) const {
return M.getTypeLowering(*this).isTrivial();
}

View File

@@ -122,12 +122,11 @@ ManagedValue SILGenFunction::emitManagedBufferWithCleanup(SILValue v) {
ManagedValue SILGenFunction::emitManagedBufferWithCleanup(SILValue v,
const TypeLowering &lowering) {
assert(lowering.getLoweredType().getAddressType() == v.getType());
if (lowering.isTrivial()) {
if (lowering.isTrivial())
return ManagedValue::forUnmanaged(v);
} else {
Cleanups.pushCleanup<CleanupMaterializedValue>(v);
return ManagedValue(v, getTopCleanup());
}
Cleanups.pushCleanup<CleanupMaterializedValue>(v);
return ManagedValue(v, getTopCleanup());
}
static void destroyRValue(SILGenFunction &SGF, CleanupLocation loc,
@@ -609,12 +608,11 @@ ManagedValue SILGenFunction::manageBufferForExprResult(SILValue buffer,
}
// Add a cleanup for the temporary we allocated.
if (bufferTL.isTrivial()) {
if (bufferTL.isTrivial())
return ManagedValue::forUnmanaged(buffer);
} else {
Cleanups.pushCleanup<CleanupMaterializedValue>(buffer);
return ManagedValue(buffer, getTopCleanup());
}
Cleanups.pushCleanup<CleanupMaterializedValue>(buffer);
return ManagedValue(buffer, getTopCleanup());
}
Materialize SILGenFunction::emitMaterialize(SILLocation loc, ManagedValue v) {

View File

@@ -46,15 +46,13 @@ static void LowerAssignInstruction(SILBuilder &B, AssignInst *Inst,
auto &M = Inst->getModule();
SILValue Src = Inst->getSrc();
auto &destTL = M.getTypeLowering(Inst->getDest().getType());
// If this is an initialization, or the storage type is trivial, we
// can just replace the assignment with a store.
// 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
// 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());
} else {
// 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),
// 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.
SILValue IncomingVal = B.createLoad(Inst->getLoc(), Inst->getDest());
B.createStore(Inst->getLoc(), Src, Inst->getDest());
destTL.emitDestroyValue(B, Inst->getLoc(), IncomingVal);
B.emitDestroyValueOperation(Inst->getLoc(), IncomingVal);
}
Inst->eraseFromParent();
@@ -820,7 +819,7 @@ bool ElementPromotion::doIt() {
// memory object will destruct the memory. If the memory (or some element
// thereof) is not initialized on some path, the bad things happen. Process
// releases to adjust for this.
if (!TheMemory->getModule().getTypeLowering(MemoryType).isTrivial()) {
if (!MemoryType.isTrivial(TheMemory->getModule())) {
for (unsigned i = 0; i != Releases.size(); ++i) {
if (processNonTrivialRelease(Releases[i])) {
Releases[i] = Releases.back();
@@ -1663,10 +1662,7 @@ bool ElementPromotion::promoteDestroyAddr(DestroyAddrInst *DAI) {
DEBUG(llvm::errs() << " *** Promoting destroy_addr: " << *DAI << "\n");
DEBUG(llvm::errs() << " To value: " << *NewVal.getDef() << "\n");
auto &TL = DAI->getModule().getTypeLowering(MemoryType);
SILBuilder B(DAI);
TL.emitDestroyValue(B, DAI->getLoc(), NewVal);
SILBuilder(DAI).emitDestroyValueOperation(DAI->getLoc(), NewVal);
DAI->eraseFromParent();
return true;
}
@@ -2203,7 +2199,7 @@ void ElementPromotion::tryToRemoveDeadAllocation() {
// If the memory object has non-trivial type, then removing the deallocation
// 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) {
if (isa<DeallocStackInst>(R) || isa<DeallocBoxInst>(R))
continue;