mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
IRGen: Use SILTypes in field projection functions.
Swift SVN r5154
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "swift/AST/PrettyStackTrace.h"
|
||||
#include "swift/AST/TypeMemberVisitor.h"
|
||||
#include "swift/AST/Types.h"
|
||||
#include "swift/SIL/SILType.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
@@ -383,6 +384,15 @@ static OwnedAddress emitAddressAtOffset(IRGenFunction &IGF,
|
||||
return OwnedAddress(addr, base);
|
||||
}
|
||||
|
||||
OwnedAddress irgen::projectPhysicalClassMemberAddress(IRGenFunction &IGF,
|
||||
llvm::Value *base,
|
||||
SILType baseType,
|
||||
VarDecl *field) {
|
||||
return projectPhysicalClassMemberAddress(IGF, base,
|
||||
baseType.getSwiftRValueType(),
|
||||
field);
|
||||
}
|
||||
|
||||
OwnedAddress irgen::projectPhysicalClassMemberAddress(IRGenFunction &IGF,
|
||||
llvm::Value *base,
|
||||
CanType baseType,
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace swift {
|
||||
class MemberRefExpr;
|
||||
class CanType;
|
||||
class VarDecl;
|
||||
class SILType;
|
||||
|
||||
namespace irgen {
|
||||
class HeapLayout;
|
||||
@@ -37,6 +38,10 @@ namespace irgen {
|
||||
class IRGenModule;
|
||||
class OwnedAddress;
|
||||
|
||||
OwnedAddress projectPhysicalClassMemberAddress(IRGenFunction &IGF,
|
||||
llvm::Value *base,
|
||||
SILType baseType,
|
||||
VarDecl *field);
|
||||
OwnedAddress projectPhysicalClassMemberAddress(IRGenFunction &IGF,
|
||||
llvm::Value *base,
|
||||
CanType baseType,
|
||||
|
||||
@@ -97,9 +97,9 @@ namespace {
|
||||
|
||||
OwnedAddress irgen::projectPhysicalStructMemberAddress(IRGenFunction &IGF,
|
||||
OwnedAddress base,
|
||||
CanType baseType,
|
||||
SILType baseType,
|
||||
unsigned fieldIndex) {
|
||||
assert((baseType->is<StructType>() || baseType->is<BoundGenericStructType>())
|
||||
assert((baseType.is<StructType>() || baseType.is<BoundGenericStructType>())
|
||||
&& "not a struct type");
|
||||
auto &baseTI = IGF.getFragileTypeInfo(baseType).as<StructTypeInfo>();
|
||||
auto &fieldI = baseTI.getFields()[fieldIndex];
|
||||
@@ -109,7 +109,7 @@ OwnedAddress irgen::projectPhysicalStructMemberAddress(IRGenFunction &IGF,
|
||||
}
|
||||
|
||||
void irgen::projectPhysicalStructMemberFromExplosion(IRGenFunction &IGF,
|
||||
CanType baseType,
|
||||
SILType baseType,
|
||||
Explosion &base,
|
||||
unsigned fieldNo,
|
||||
Explosion &out) {
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace swift {
|
||||
class GenericMemberRefExpr;
|
||||
class MemberRefExpr;
|
||||
class CanType;
|
||||
class SILType;
|
||||
|
||||
namespace irgen {
|
||||
class IRGenFunction;
|
||||
@@ -29,10 +30,10 @@ namespace irgen {
|
||||
|
||||
OwnedAddress projectPhysicalStructMemberAddress(IRGenFunction &IGF,
|
||||
OwnedAddress base,
|
||||
CanType baseType,
|
||||
SILType baseType,
|
||||
unsigned fieldIndex);
|
||||
void projectPhysicalStructMemberFromExplosion(IRGenFunction &IGF,
|
||||
CanType baseType,
|
||||
SILType baseType,
|
||||
Explosion &base,
|
||||
unsigned fieldNo,
|
||||
Explosion &out);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "swift/AST/Types.h"
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/Pattern.h"
|
||||
#include "swift/SIL/SILType.h"
|
||||
#include "swift/Basic/Optional.h"
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
|
||||
@@ -224,19 +225,20 @@ const TypeInfo *TypeConverter::convertTupleType(TupleType *tuple) {
|
||||
} while(0)
|
||||
|
||||
void irgen::projectTupleElementFromExplosion(IRGenFunction &IGF,
|
||||
CanType tupleType,
|
||||
SILType tupleType,
|
||||
Explosion &tuple,
|
||||
unsigned fieldNo,
|
||||
Explosion &out) {
|
||||
FOR_TUPLE_IMPL(IGF, tupleType, projectElementFromExplosion,
|
||||
FOR_TUPLE_IMPL(IGF, tupleType.getSwiftRValueType(),
|
||||
projectElementFromExplosion,
|
||||
tuple, fieldNo, out);
|
||||
}
|
||||
|
||||
OwnedAddress irgen::projectTupleElementAddress(IRGenFunction &IGF,
|
||||
OwnedAddress tuple,
|
||||
CanType tupleType,
|
||||
SILType tupleType,
|
||||
unsigned fieldNo) {
|
||||
FOR_TUPLE_IMPL(IGF, tupleType, projectElementAddress,
|
||||
FOR_TUPLE_IMPL(IGF, tupleType.getSwiftRValueType(), projectElementAddress,
|
||||
tuple, fieldNo);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace irgen {
|
||||
/// Project the address of a tuple element.
|
||||
OwnedAddress projectTupleElementAddress(IRGenFunction &IGF,
|
||||
OwnedAddress base,
|
||||
CanType tupleType,
|
||||
SILType tupleType,
|
||||
unsigned fieldNo);
|
||||
|
||||
/// Project a tuple element rvalue from an already-exploded tuple rvalue.
|
||||
void projectTupleElementFromExplosion(IRGenFunction &IGF,
|
||||
CanType tupleType,
|
||||
SILType tupleType,
|
||||
Explosion &tuple,
|
||||
unsigned fieldNo,
|
||||
Explosion &out);
|
||||
|
||||
@@ -850,18 +850,17 @@ void IRGenSILFunction::visitExtractInst(swift::ExtractInst *i) {
|
||||
SILValue v(i, 0);
|
||||
Explosion lowered(CurExplosionLevel);
|
||||
Explosion operand = getLoweredExplosion(i->getOperand());
|
||||
CanType baseType = i->getOperand().getType().getSwiftRValueType();
|
||||
CanType refType = i->getOperand().getType().getSwiftType();
|
||||
SILType baseType = i->getOperand().getType();
|
||||
|
||||
if (baseType->is<TupleType>()) {
|
||||
if (baseType.is<TupleType>()) {
|
||||
projectTupleElementFromExplosion(*this,
|
||||
refType,
|
||||
baseType,
|
||||
operand,
|
||||
i->getFieldNo(),
|
||||
lowered);
|
||||
} else {
|
||||
projectPhysicalStructMemberFromExplosion(*this,
|
||||
refType,
|
||||
baseType,
|
||||
operand,
|
||||
i->getFieldNo(),
|
||||
lowered);
|
||||
@@ -872,10 +871,10 @@ void IRGenSILFunction::visitExtractInst(swift::ExtractInst *i) {
|
||||
|
||||
void IRGenSILFunction::visitElementAddrInst(swift::ElementAddrInst *i) {
|
||||
Address base = getLoweredAddress(i->getOperand());
|
||||
CanType baseType = i->getOperand().getType().getSwiftRValueType();
|
||||
SILType baseType = i->getOperand().getType();
|
||||
|
||||
Address field;
|
||||
if (baseType->is<TupleType>()) {
|
||||
if (baseType.is<TupleType>()) {
|
||||
field = projectTupleElementAddress(*this,
|
||||
OwnedAddress(base, nullptr),
|
||||
baseType,
|
||||
@@ -893,7 +892,7 @@ void IRGenSILFunction::visitRefElementAddrInst(swift::RefElementAddrInst *i) {
|
||||
Explosion base = getLoweredExplosion(i->getOperand());
|
||||
llvm::Value *value = base.claimNext();
|
||||
|
||||
CanType baseTy = i->getOperand().getType().getSwiftType();
|
||||
SILType baseTy = i->getOperand().getType();
|
||||
Address field = projectPhysicalClassMemberAddress(*this,
|
||||
value,
|
||||
baseTy,
|
||||
|
||||
Reference in New Issue
Block a user