IRGen: Strip out dead code for untyped boxes.

Swift SVN r29761
This commit is contained in:
Joe Groff
2015-06-27 17:50:13 +00:00
parent 8106a11dac
commit 8a04d67408
11 changed files with 5 additions and 148 deletions

View File

@@ -76,12 +76,6 @@ public:
const llvm::Twine &name) const override;
void deallocateStack(IRGenFunction &IGF, Address addr, SILType T) const override;
OwnedAddress allocateBox(IRGenFunction &IGF, SILType T,
const llvm::Twine &name) const override;
void deallocateBox(IRGenFunction &IGF, llvm::Value *boxOwner,
SILType T) const override;
// We can give these reasonable default implementations.
void initializeWithTake(IRGenFunction &IGF, Address destAddr,

View File

@@ -71,47 +71,3 @@ void FixedTypeInfo::deallocateStack(IRGenFunction &IGF, Address addr,
SILType T) const {
// TODO: lifetime intrinsics?
}
/// Allocate an object with fixed layout.
OwnedAddress FixedTypeInfo::allocateBox(IRGenFunction &IGF, SILType T,
const Twine &name) const {
// If the type is known to be empty, don't actually allocate anything.
if (isKnownEmpty())
return OwnedAddress(getUndefAddress(), IGF.IGM.RefCountedNull);
// Lay out the type as a heap object.
HeapLayout layout(IGF.IGM, LayoutStrategy::Optimal, T, this);
assert(!layout.isKnownEmpty() && "non-empty type had empty layout?");
auto &elt = layout.getElement(0);
// Allocate a new object.
// TODO: lifetime intrinsics?
llvm::Value *allocation = IGF.emitUnmanagedAlloc(layout, name + ".alloc");
// FIXME: provide non-fixed offsets
NonFixedOffsets offsets = None;
// Cast and GEP down to the element.
Address rawAddr = layout.emitCastTo(IGF, allocation);
rawAddr = elt.project(IGF, rawAddr, offsets, name);
OwnedAddress addr(rawAddr, allocation);
return addr;
}
// Deallocate a fixed-layout box that is uninitialized.
void FixedTypeInfo::deallocateBox(IRGenFunction &IGF, llvm::Value *boxOwner,
SILType T) const {
// If the type is known to be empty, a box isn't actually allocated.
if (isKnownEmpty())
return;
// Lay out the type as a heap object.
HeapLayout layout(IGF.IGM, LayoutStrategy::Optimal, T, this);
assert(!layout.isKnownEmpty() && "non-empty type had empty layout?");
auto size = layout.emitSize(IGF.IGM);
auto alignMask = layout.emitAlignMask(IGF.IGM);
emitDeallocateHeapObject(IGF, boxOwner, size, alignMask);
}

View File

@@ -111,22 +111,6 @@ llvm::Value *IRGenFunction::emitAllocObjectCall(llvm::Value *metadata,
{ metadata, size, alignMask }, name);
}
void IRGenFunction::emitAllocBoxCall(llvm::Value *typeMetadata,
llvm::Value *&box,
llvm::Value *&valueAddress) {
auto attrs = llvm::AttributeSet::get(IGM.LLVMContext,
llvm::AttributeSet::FunctionIndex,
llvm::Attribute::NoUnwind);
llvm::CallInst *call =
Builder.CreateCall(IGM.getAllocBoxFn(), typeMetadata);
call->setCallingConv(IGM.RuntimeCC);
call->setAttributes(attrs);
box = Builder.CreateExtractValue(call, 0);
valueAddress = Builder.CreateExtractValue(call, 1);
}
void IRGenFunction::emitAllocBox2Call(llvm::Value *typeMetadata,
llvm::Value *&box,
llvm::Value *&valueAddress) {
@@ -143,18 +127,6 @@ void IRGenFunction::emitAllocBox2Call(llvm::Value *typeMetadata,
valueAddress = Builder.CreateExtractValue(call, 1);
}
void IRGenFunction::emitDeallocBoxCall(llvm::Value *box,
llvm::Value *typeMetadata) {
auto attrs = llvm::AttributeSet::get(IGM.LLVMContext,
llvm::AttributeSet::FunctionIndex,
llvm::Attribute::NoUnwind);
llvm::CallInst *call =
Builder.CreateCall(IGM.getDeallocBoxFn(), {box, typeMetadata});
call->setCallingConv(IGM.RuntimeCC);
call->setAttributes(attrs);
}
void IRGenFunction::emitDeallocBox2Call(llvm::Value *box,
llvm::Value *typeMetadata) {
auto attrs = llvm::AttributeSet::get(IGM.LLVMContext,

View File

@@ -188,14 +188,10 @@ public:
void emitDeallocRawCall(llvm::Value *pointer, llvm::Value *size,
llvm::Value *alignMask);
void emitAllocBoxCall(llvm::Value *typeMetadata,
llvm::Value *&box,
llvm::Value *&valueAddress);
void emitAllocBox2Call(llvm::Value *typeMetadata,
llvm::Value *&box,
llvm::Value *&valueAddress);
void emitDeallocBoxCall(llvm::Value *box, llvm::Value *typeMetadata);
void emitDeallocBox2Call(llvm::Value *box, llvm::Value *typeMetadata);
llvm::Value *emitProjectBox2Call(llvm::Value *box, llvm::Value *typeMetadata);

View File

@@ -3391,10 +3391,8 @@ void IRGenSILFunction::visitDeallocBoxInst(swift::DeallocBoxInst *i) {
Explosion owner = getLoweredExplosion(i->getOperand());
llvm::Value *ownerPtr = owner.claimNext();
if (auto boxTy = i->getOperand().getType().getAs<SILBoxType>())
emitDeallocateBox(*this, ownerPtr, boxTy);
else
type.deallocateBox(*this, ownerPtr, i->getElementType());
auto boxTy = i->getOperand().getType().castTo<SILBoxType>();
emitDeallocateBox(*this, ownerPtr, boxTy);
}
void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
@@ -3412,15 +3410,9 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
# endif
OwnedAddress addr;
// TODO: Use the "new" emitAllocateBox call until untyped boxes can be
// phased out.
if (auto boxTy = i->getContainerResult().getType().getAs<SILBoxType>())
addr = emitAllocateBox(*this, boxTy, DbgName);
else
addr = type.allocateBox(*this,
i->getElementType(),
DbgName);
auto boxTy = i->getContainerResult().getType().castTo<SILBoxType>();
addr = emitAllocateBox(*this, boxTy, DbgName);
Explosion box;
box.add(addr.getOwner());
setLoweredExplosion(SILValue(i, 0), box);

View File

@@ -31,7 +31,6 @@ namespace irgen {
///
/// Subclasses must implement the following operations:
/// allocateStack
/// allocateBox
/// assignWithCopy
/// initializeWithCopy
/// destroy

View File

@@ -57,23 +57,6 @@ public:
// This is useful for metaprogramming.
static bool isFixed() { return false; }
OwnedAddress allocateBox(IRGenFunction &IGF,
SILType T,
const llvm::Twine &name) const override {
// Allocate a new object using the allocBox runtime call.
llvm::Value *metadata = IGF.emitTypeMetadataRefForLayout(T);
llvm::Value *box, *address;
IGF.emitAllocBoxCall(metadata, box, address);
return OwnedAddress(getAsBitCastAddress(IGF, address), box);
}
void deallocateBox(IRGenFunction &IGF, llvm::Value *boxOwner,
SILType T) const override {
// Deallocate the box using the deallocBox runtime call.
llvm::Value *metadata = IGF.emitTypeMetadataRefForLayout(T);
IGF.emitDeallocBoxCall(boxOwner, metadata);
}
ContainedAddress allocateStack(IRGenFunction &IGF,
SILType T,
const llvm::Twine &name) const override {

View File

@@ -38,17 +38,6 @@
#define FUNCTION(Id, Name, CC, ReturnTys, ArgTys, Attrs) FUNCTION_ID(Id)
#endif
// struct { RefCounted *box; void *value; } swift_allocBox(Metadata *type);
FUNCTION(AllocBox, swift_allocBox, RuntimeCC,
RETURNS(RefCountedPtrTy, OpaquePtrTy),
ARGS(TypeMetadataPtrTy),
ATTRS(NoUnwind))
FUNCTION(DeallocBox, swift_deallocBox, RuntimeCC,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
ATTRS(NoUnwind))
FUNCTION(AllocBox2, swift_allocBox2, RuntimeCC,
RETURNS(RefCountedPtrTy, OpaquePtrTy),
ARGS(TypeMetadataPtrTy),

View File

@@ -247,15 +247,6 @@ public:
virtual void deallocateStack(IRGenFunction &IGF, Address addr,
SILType T) const = 0;
/// Allocate a box of this type on the heap.
virtual OwnedAddress allocateBox(IRGenFunction &IGF, SILType T,
const llvm::Twine &name) const = 0;
/// Deallocate an uninitialized box of this type on the heap.
virtual void deallocateBox(IRGenFunction &IGF,
llvm::Value *boxOwner,
SILType T) const = 0;
/// Copy a value out of an object and into another, destroying the
/// old value in the destination.
virtual void assignWithCopy(IRGenFunction &IGF, Address dest,

View File

@@ -102,17 +102,6 @@ void UnimplementedTypeInfo::deallocateStack(IRGenFunction &IGF, Address addr,
}
OwnedAddress UnimplementedTypeInfo::allocateBox(IRGenFunction &IGF, SILType T,
const llvm::Twine &name) const {
return OwnedAddress(getUndefOpaqueAddress(getStorageType()),
llvm::UndefValue::get(IGF.IGM.RefCountedPtrTy));
}
void UnimplementedTypeInfo::deallocateBox(IRGenFunction &IGF,
llvm::Value *boxOwner, SILType T)
const {
}
void UnimplementedTypeInfo::assignWithCopy(IRGenFunction &IGF, Address dest,
Address src, SILType T) const {

View File

@@ -46,10 +46,6 @@ public:
const llvm::Twine &name) const override;
void deallocateStack(IRGenFunction &IGF, Address addr,
SILType T) const override;
OwnedAddress allocateBox(IRGenFunction &IGF, SILType T,
const llvm::Twine &name) const override;
void deallocateBox(IRGenFunction &IGF, llvm::Value *boxOwner,
SILType T) const override;
void assignWithCopy(IRGenFunction &IGF, Address dest,
Address src, SILType T) const override;
void assignWithTake(IRGenFunction &IGF, Address dest,