[proj] Add Projection::create{Addr,Value}Projection so one can create Projections without knowing what the internal state of the projection is.

Swift SVN r23371
This commit is contained in:
Michael Gottesman
2014-11-17 17:52:16 +00:00
parent ebba297951
commit 2d703a28f5
5 changed files with 136 additions and 66 deletions

View File

@@ -251,33 +251,11 @@ forwardAddrToLdWithExtractPath(SILValue Address, SILValue StoredValue,
// from our list of address projections.
SILValue LastExtract = StoredValue;
SILBuilderWithScope<16> Builder(Inst);
for (auto II = Path->rbegin(), IE = Path->rend(); II != IE; ++II) {
auto P = *II;
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");
}
// Construct the path!
for (auto PI = Path->rbegin(), PE = Path->rend(); PI != PE; ++PI) {
LastExtract = PI->createValueProjection(Builder, Inst->getLoc(),
LastExtract).get();
}
// Return the last extract we created.