SILGen: Emit implicit constructors.

Teach SILGen how to emit the implicit elementwise constructor for structs and the implicit default constructor for classes, and eliminate the now dead IRGen code for them. Add a StructInst SIL instruction to represent constructing a loadable struct value from elements, analogous to TupleInst for tuples.

Swift SVN r4778
This commit is contained in:
Joe Groff
2013-04-17 20:51:26 +00:00
parent dc1fe2f8e2
commit b9bb84c58e
14 changed files with 255 additions and 189 deletions

View File

@@ -291,11 +291,8 @@ APFloat FloatLiteralInst::getValue() const {
return getExpr()->getValue();
}
StringLiteralInst::StringLiteralInst(StringLiteralExpr *E)
: SILInstruction(ValueKind::StringLiteralInst, E,
// The string literal tuple type is always a valid SIL type.
SILType::getPreLoweredType(E->getType()->getCanonicalType(),
/*address=*/false, /*loadable=*/true)) {
StringLiteralInst::StringLiteralInst(StringLiteralExpr *E, SILType ty)
: SILInstruction(ValueKind::StringLiteralInst, E, ty) {
}
StringLiteralExpr *StringLiteralInst::getExpr() const {
@@ -402,6 +399,18 @@ SuperToArchetypeInst::SuperToArchetypeInst(SILLocation Loc,
Operands(this, SrcBase, DestArchetypeAddress) {
}
StructInst *StructInst::createImpl(SILLocation Loc, SILType Ty,
ArrayRef<SILValue> Elements, SILFunction &F) {
void *Buffer = F.allocate(sizeof(StructInst) +
decltype(Operands)::getExtraSize(Elements.size()),
alignof(StructInst));
return ::new(Buffer) StructInst(Loc, Ty, Elements);
}
StructInst::StructInst(SILLocation Loc, SILType Ty, ArrayRef<SILValue> Elems)
: SILInstruction(ValueKind::StructInst, Loc, Ty), Operands(this, Elems) {
}
TupleInst *TupleInst::createImpl(SILLocation Loc, SILType Ty,
ArrayRef<SILValue> Elements, SILFunction &F) {
void *Buffer = F.allocate(sizeof(TupleInst) +