Skip to content

SIL: Remove AllocBoxInst::getElementType(). #6042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,9 @@ class AllocBoxInst final
Operands[i].~Operand();
}
}

SILType getElementType() const {
return SILType::getPrimitiveObjectType(
getType().castTo<SILBoxType>()->getBoxedType());

CanSILBoxType getBoxType() const {
return getType().castTo<SILBoxType>();
}

/// Return the underlying variable declaration associated with this
Expand Down
9 changes: 7 additions & 2 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3646,7 +3646,9 @@ void IRGenSILFunction::visitDeallocBoxInst(swift::DeallocBoxInst *i) {
}

void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
const TypeInfo &type = getTypeInfo(i->getElementType());
assert(i->getBoxType()->getLayout()->getFields().size() == 1
&& "multi field boxes not implemented yet");
const TypeInfo &type = getTypeInfo(i->getBoxType()->getFieldType(0));

// Derive name from SIL location.
VarDecl *Decl = i->getDecl();
Expand Down Expand Up @@ -3676,7 +3678,10 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
if (Name == IGM.Context.Id_self.str())
return;

DebugTypeInfo DbgTy(Decl, i->getElementType().getSwiftType(), type, false);
assert(i->getBoxType()->getLayout()->getFields().size() == 1
&& "box for a local variable should only have one field");
DebugTypeInfo DbgTy(Decl, i->getBoxType()->getFieldType(0).getSwiftType(),
type, false);
IGM.DebugInfo->emitVariableDeclaration(
Builder,
emitShadowCopy(boxWithAddr.getAddress(), i->getDebugScope(), Name, 0),
Expand Down
19 changes: 10 additions & 9 deletions lib/SIL/Projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,16 @@ void Projection::getFirstLevelProjections(SILType Ty, SILModule &Mod,
}

if (auto Box = Ty.getAs<SILBoxType>()) {
Projection P(ProjectionKind::Box, (unsigned)0);
DEBUG(ProjectionPath X(Ty);
assert(X.getMostDerivedType(Mod) == Ty);
X.append(P);
assert(X.getMostDerivedType(Mod) == SILType::getPrimitiveAddressType(
Box->getBoxedType()));
X.verify(Mod););
(void) Box;
Out.push_back(P);
for (unsigned field : indices(Box->getLayout()->getFields())) {
Projection P(ProjectionKind::Box, field);
DEBUG(ProjectionPath X(Ty);
assert(X.getMostDerivedType(Mod) == Ty);
X.append(P);
assert(X.getMostDerivedType(Mod) == Box->getFieldType(field));
X.verify(Mod););
(void)Box;
Out.push_back(P);
}
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {

require(AI->getType().isObject(),
"result of alloc_box must be an object");
verifyOpenedArchetype(AI, AI->getElementType().getSwiftRValueType());
for (unsigned field : indices(AI->getBoxType()->getLayout()->getFields()))
verifyOpenedArchetype(AI, AI->getBoxType()->getFieldLoweredType(field));
}

void checkDeallocBoxInst(DeallocBoxInst *DI) {
Expand Down
20 changes: 12 additions & 8 deletions lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ static unsigned getElementCountRec(CanType T,
DIMemoryObjectInfo::DIMemoryObjectInfo(SILInstruction *MI) {
MemoryInst = MI;
// Compute the type of the memory object.
if (auto *ABI = dyn_cast<AllocBoxInst>(MemoryInst))
MemorySILType = ABI->getElementType();
else if (auto *ASI = dyn_cast<AllocStackInst>(MemoryInst))
if (auto *ABI = dyn_cast<AllocBoxInst>(MemoryInst)) {
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1
&& "analyzing multi-field boxes not implemented");
MemorySILType = ABI->getBoxType()->getFieldType(0);
} else if (auto *ASI = dyn_cast<AllocStackInst>(MemoryInst)) {
MemorySILType = ASI->getElementType();
else {
} else {
auto *MUI = cast<MarkUninitializedInst>(MemoryInst);
MemorySILType = MUI->getType().getObjectType();

Expand Down Expand Up @@ -562,13 +564,15 @@ void ElementUseCollector::collectContainerUses(AllocBoxInst *ABI) {
if (isa<StrongReleaseInst>(User))
continue;

if (isa<ProjectBoxInst>(User)) {
collectUses(User, 0);
if (auto project = dyn_cast<ProjectBoxInst>(User)) {
collectUses(User, project->getFieldIndex());
continue;
}

// Other uses of the container are considered escapes of the value.
addElementUses(0, ABI->getElementType(), User, DIUseKind::Escape);
// Other uses of the container are considered escapes of the values.
for (unsigned field : indices(ABI->getBoxType()->getLayout()->getFields()))
addElementUses(field, ABI->getBoxType()->getFieldType(field),
User, DIUseKind::Escape);
}
}

Expand Down
8 changes: 5 additions & 3 deletions lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ AllocOptimize::AllocOptimize(SILInstruction *TheMemory,
Releases(Releases) {

// Compute the type of the memory object.
if (auto *ABI = dyn_cast<AllocBoxInst>(TheMemory))
MemoryType = ABI->getElementType();
else {
if (auto *ABI = dyn_cast<AllocBoxInst>(TheMemory)) {
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1
&& "optimizing multi-field boxes not implemented");
MemoryType = ABI->getBoxType()->getFieldType(0);
} else {
assert(isa<AllocStackInst>(TheMemory));
MemoryType = cast<AllocStackInst>(TheMemory)->getElementType();
}
Expand Down
10 changes: 8 additions & 2 deletions lib/SILOptimizer/Transforms/AllocBoxToStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI,
auto &Entry = ABI->getFunction()->front();
SILBuilder BuildAlloc(&Entry, Entry.begin());
BuildAlloc.setCurrentDebugScope(ABI->getDebugScope());
auto *ASI = BuildAlloc.createAllocStack(ABI->getLoc(), ABI->getElementType(),
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1
&& "rewriting multi-field box not implemented");
auto *ASI = BuildAlloc.createAllocStack(ABI->getLoc(),
ABI->getBoxType()->getFieldType(0),
ABI->getVarInfo());

// Replace all uses of the address of the box's contained value with
Expand All @@ -429,7 +432,10 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI,
break;
}

auto &Lowering = ABI->getModule().getTypeLowering(ABI->getElementType());
assert(ABI->getBoxType()->getLayout()->getFields().size() == 1
&& "promoting multi-field box not implemented");
auto &Lowering = ABI->getModule()
.getTypeLowering(ABI->getBoxType()->getFieldType(0));
auto Loc = CleanupLocation::get(ABI->getLoc());

// For non-trivial types, insert destroys for each final release-like
Expand Down
6 changes: 3 additions & 3 deletions test/DebugInfo/byref-capture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ func makeIncrementor(_ inc : Int64) -> () -> Int64
// CHECK-SAME: metadata ![[SUM_CAPTURE:[0-9]+]],
// CHECK-SAME: metadata ![[EMPTY:.*]])
// CHECK: ![[EMPTY]] = !DIExpression()
// CHECK: ![[SUM_CAPTURE]] = !DILocalVariable(name: "sum", arg: 1,
// CHECK-SAME: line: [[@LINE-8]], type: ![[INOUTTY:[0-9]+]]
// CHECK: ![[INOUTTY]] = !DICompositeType({{.*}}identifier: "_TtRVs5Int64"
// CHECK: ![[INOUTTY:[0-9]+]] = !DICompositeType({{.*}}identifier: "_TtRVs5Int64"
// ^ inout type.
// CHECK: ![[SUM_CAPTURE]] = !DILocalVariable(name: "sum", arg: 1,
// CHECK-SAME: line: [[@LINE-10]], type: ![[INOUTTY]]
sum += inc
return sum
}
Expand Down