Skip to content

Commit 5210258

Browse files
committed
Add a function to allocate a box for out-line existential value buffer
1 parent 1c9f7f5 commit 5210258

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/IRGen/GenHeap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,16 @@ Address irgen::emitProjectBox(IRGenFunction &IGF,
16531653
boxType->getFieldType(IGF.IGM.getSILModule(), 0));
16541654
}
16551655

1656+
OwnedAddress
1657+
irgen::emitAllocateExistentialBox(IRGenFunction &IGF, SILType boxedType,
1658+
GenericEnvironment *env,
1659+
const llvm::Twine &name) {
1660+
// Get a box for the boxed value.
1661+
auto boxType = SILBoxType::get(boxedType.getSwiftRValueType());
1662+
auto &boxTI = IGF.getTypeInfoForLowered(boxType).as<BoxTypeInfo>();
1663+
return boxTI.allocate(IGF, boxedType, env, name);
1664+
}
1665+
16561666
#define DEFINE_VALUE_OP(ID) \
16571667
void IRGenFunction::emit##ID(llvm::Value *value, Atomicity atomicity) { \
16581668
if (doesNotRequireRefCounting(value)) return; \

lib/IRGen/GenHeap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ void emitDeallocateBox(IRGenFunction &IGF, llvm::Value *box,
132132
Address emitProjectBox(IRGenFunction &IGF, llvm::Value *box,
133133
CanSILBoxType boxType);
134134

135+
/// Allocate a boxed value based on the boxed type.
136+
OwnedAddress emitAllocateExistentialBox(IRGenFunction &IGF,
137+
SILType boxedType,
138+
GenericEnvironment *env,
139+
const llvm::Twine &name);
140+
135141
} // end namespace irgen
136142
} // end namespace swift
137143

0 commit comments

Comments
 (0)