[proj] Prepare Projection so that I can add generic create{Addr,Value}Projection.

I want to cleanup some code paths in SILCombine and LoadStoreOpts to use
generic create{Addr,Value}Projection methods which create the
appropriate projection instruction for a Projection method. Also this
will allow me to start to hide more of the internal state of Projection.

Swift SVN r23366
This commit is contained in:
Michael Gottesman
2014-11-17 06:43:37 +00:00
parent 5d4e87baa3
commit eeab468c8e
5 changed files with 194 additions and 101 deletions

View File

@@ -253,29 +253,30 @@ forwardAddrToLdWithExtractPath(SILValue Address, SILValue StoredValue,
SILBuilderWithScope<16> Builder(Inst);
for (auto II = Path->rbegin(), IE = Path->rend(); II != IE; ++II) {
auto P = *II;
if (ValueDecl *D = P.getDecl()) {
if (P.getNominalType() == Projection::NominalType::Struct) {
LastExtract = Builder.createStructExtract(Inst->getLoc(), LastExtract,
cast<VarDecl>(D),
P.getType().getObjectType());
assert(cast<StructExtractInst>(*LastExtract).getStructDecl() &&
"Instruction must have a struct decl!");
} else {
assert(P.getNominalType() == Projection::NominalType::Enum &&
"Expected an enum decl here. Only other possibility is a "
"class which we do not support");
LastExtract = Builder.createUncheckedEnumData(
Inst->getLoc(), LastExtract, cast<EnumElementDecl>(D),
P.getType().getObjectType());
assert(cast<UncheckedEnumDataInst>(*LastExtract).getElement() &&
"Instruction must have an enum element decl!");
}
} else {
switch (P.getKind()) {
case ProjectionKind::Struct:
LastExtract = Builder.createStructExtract(Inst->getLoc(), LastExtract,
cast<VarDecl>(P.getDecl()),
P.getType().getObjectType());
assert(cast<StructExtractInst>(*LastExtract).getStructDecl() &&
"Instruction must have a struct decl!");
break;
case ProjectionKind::Enum:
LastExtract = Builder.createUncheckedEnumData(
Inst->getLoc(), LastExtract, cast<EnumElementDecl>(P.getDecl()),
P.getType().getObjectType());
assert(cast<UncheckedEnumDataInst>(*LastExtract).getElement() &&
"Instruction must have an enum element decl!");
break;
case ProjectionKind::Tuple:
LastExtract = Builder.createTupleExtract(Inst->getLoc(), LastExtract,
P.getIndex(),
P.getType().getObjectType());
assert(cast<TupleExtractInst>(*LastExtract).getTupleType() &&
"Instruction must have a tuple type!");
break;
case ProjectionKind::Class:
llvm_unreachable("Can not handle classes here");
}
}