Skip to content

Commit

Permalink
[silgen] Perform last gen => SGF. Now SILGen always uses SGF.
Browse files Browse the repository at this point in the history
  • Loading branch information
gottesmm committed Aug 11, 2017
1 parent ef34642 commit bd32f9e
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 293 deletions.
6 changes: 3 additions & 3 deletions lib/SILGen/SILGenEpilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void SILGenFunction::prepareRethrowEpilog(CleanupLocation cleanupLoc) {
///
/// Note that this intentionally loses any tuple sub-structure of the
/// formal result type.
static SILValue buildReturnValue(SILGenFunction &gen, SILLocation loc,
static SILValue buildReturnValue(SILGenFunction &SGF, SILLocation loc,
ArrayRef<SILValue> directResults) {
if (directResults.size() == 1)
return directResults[0];
Expand All @@ -63,8 +63,8 @@ static SILValue buildReturnValue(SILGenFunction &gen, SILLocation loc,
for (auto elt : directResults)
eltTypes.push_back(elt->getType().getSwiftRValueType());
auto resultType = SILType::getPrimitiveObjectType(
CanType(TupleType::get(eltTypes, gen.getASTContext())));
return gen.B.createTuple(loc, resultType, directResults);
CanType(TupleType::get(eltTypes, SGF.getASTContext())));
return SGF.B.createTuple(loc, resultType, directResults);
}

std::pair<Optional<SILValue>, SILLocation>
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
const TypeLowering &optTL,
SGFContext C = SGFContext());

typedef llvm::function_ref<ManagedValue(SILGenFunction &gen,
typedef llvm::function_ref<ManagedValue(SILGenFunction &SGF,
SILLocation loc,
ManagedValue input,
SILType loweredResultTy,
Expand Down
14 changes: 7 additions & 7 deletions lib/SILGen/SILGenGlobalVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,23 @@ void SILGenFunction::emitLazyGlobalInitializer(PatternBindingDecl *binding,
B.createReturn(ImplicitReturnLocation::getImplicitReturnLoc(binding), ret);
}

static void emitOnceCall(SILGenFunction &gen, VarDecl *global,
static void emitOnceCall(SILGenFunction &SGF, VarDecl *global,
SILGlobalVariable *onceToken, SILFunction *onceFunc) {
SILType rawPointerSILTy
= gen.getLoweredLoadableType(gen.getASTContext().TheRawPointerType);
= SGF.getLoweredLoadableType(SGF.getASTContext().TheRawPointerType);

// Emit a reference to the global token.
SILValue onceTokenAddr = gen.B.createGlobalAddr(global, onceToken);
onceTokenAddr = gen.B.createAddressToPointer(global, onceTokenAddr,
SILValue onceTokenAddr = SGF.B.createGlobalAddr(global, onceToken);
onceTokenAddr = SGF.B.createAddressToPointer(global, onceTokenAddr,
rawPointerSILTy);

// Emit a reference to the function to execute.
SILValue onceFuncRef = gen.B.createFunctionRef(global, onceFunc);
SILValue onceFuncRef = SGF.B.createFunctionRef(global, onceFunc);

// Call Builtin.once.
SILValue onceArgs[] = {onceTokenAddr, onceFuncRef};
gen.B.createBuiltin(global, gen.getASTContext().getIdentifier("once"),
gen.SGM.Types.getEmptyTupleType(), {}, onceArgs);
SGF.B.createBuiltin(global, SGF.getASTContext().getIdentifier("once"),
SGF.SGM.Types.getEmptyTupleType(), {}, onceArgs);
}

void SILGenFunction::emitGlobalAccessor(VarDecl *global,
Expand Down
178 changes: 89 additions & 89 deletions lib/SILGen/SILGenMaterializeForSet.cpp

Large diffs are not rendered by default.

244 changes: 122 additions & 122 deletions lib/SILGen/SILGenPoly.cpp

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class CleanupWriteBackToInOut : public Cleanup {
CleanupWriteBackToInOut(VarDecl *var, SILValue inoutAddr)
: var(var), inoutAddr(inoutAddr) {}

void emit(SILGenFunction &gen, CleanupLocation l) override {
void emit(SILGenFunction &SGF, CleanupLocation l) override {
// Assign from the local variable to the inout address with an
// 'autogenerated' copyaddr.
l.markAutoGenerated();
gen.B.createCopyAddr(l, gen.VarLocs[var].value, inoutAddr,
SGF.B.createCopyAddr(l, SGF.VarLocs[var].value, inoutAddr,
IsNotTake, IsNotInitialization);
}
};
Expand All @@ -60,8 +60,8 @@ class StrongReleaseCleanup : public Cleanup {
SILValue box;
public:
StrongReleaseCleanup(SILValue box) : box(box) {}
void emit(SILGenFunction &gen, CleanupLocation l) override {
gen.B.emitDestroyValueOperation(l, box);
void emit(SILGenFunction &SGF, CleanupLocation l) override {
SGF.B.emitDestroyValueOperation(l, box);
}

void dump(SILGenFunction &) const override {
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace {
/// A helper for creating SILArguments and binding variables to the argument
/// names.
struct ArgumentInitHelper {
SILGenFunction &gen;
SILGenFunction &SGF;
SILFunction &f;
SILGenBuilder &initB;

Expand All @@ -226,8 +226,8 @@ struct ArgumentInitHelper {
ArrayRef<SILParameterInfo> parameters;
unsigned ArgNo = 0;

ArgumentInitHelper(SILGenFunction &gen, SILFunction &f)
: gen(gen), f(f), initB(gen.B),
ArgumentInitHelper(SILGenFunction &SGF, SILFunction &f)
: SGF(SGF), f(f), initB(SGF.B),
parameters(f.getLoweredFunctionType()->getParameters()) {
}

Expand All @@ -238,7 +238,7 @@ struct ArgumentInitHelper {

// Create an RValue by emitting destructured arguments into a basic block.
CanType canTy = ty->eraseDynamicSelfType()->getCanonicalType();
return EmitBBArguments(gen, parent, l, /*functionArgs*/ true,
return EmitBBArguments(SGF, parent, l, /*functionArgs*/ true,
parameters).visit(canTy);
}

Expand All @@ -262,8 +262,8 @@ struct ArgumentInitHelper {
// Builtin.UnsafeValueBuffer, which is not copyable.
if (isa<BuiltinUnsafeValueBufferType>(objectType)) {
// FIXME: mark a debug location?
gen.VarLocs[vd] = SILGenFunction::VarLoc::get(address);
gen.B.createDebugValueAddr(loc, address, {vd->isLet(), ArgNo});
SGF.VarLocs[vd] = SILGenFunction::VarLoc::get(address);
SGF.B.createDebugValueAddr(loc, address, {vd->isLet(), ArgNo});
return;
}
assert(argrv.getType().isAddress() && "expected inout to be address");
Expand All @@ -272,10 +272,10 @@ struct ArgumentInitHelper {
// static metatype, but we have to downcast it to a dynamic Self
// metatype to get the right semantics.
if (metatypeTy->getInstanceType()->is<DynamicSelfType>()) {
auto loweredTy = gen.getLoweredType(ty);
auto loweredTy = SGF.getLoweredType(ty);
if (loweredTy != argrv.getType()) {
argrv = ManagedValue::forUnmanaged(
gen.B.createUncheckedBitCast(loc, argrv.getValue(), loweredTy));
SGF.B.createUncheckedBitCast(loc, argrv.getValue(), loweredTy));
}
}
} else {
Expand All @@ -285,11 +285,11 @@ struct ArgumentInitHelper {
// Leave the cleanup on the argument, if any, in place to consume the
// argument if we're responsible for it.
}
gen.VarLocs[vd] = SILGenFunction::VarLoc::get(argrv.getValue());
SGF.VarLocs[vd] = SILGenFunction::VarLoc::get(argrv.getValue());
if (argrv.getType().isAddress())
gen.B.createDebugValueAddr(loc, argrv.getValue(), {vd->isLet(), ArgNo});
SGF.B.createDebugValueAddr(loc, argrv.getValue(), {vd->isLet(), ArgNo});
else
gen.B.createDebugValue(loc, argrv.getValue(), {vd->isLet(), ArgNo});
SGF.B.createDebugValue(loc, argrv.getValue(), {vd->isLet(), ArgNo});
}

void emitParam(ParamDecl *PD) {
Expand All @@ -316,7 +316,7 @@ struct ArgumentInitHelper {
}

// A value bound to _ is unused and can be immediately released.
Scope discardScope(gen.Cleanups, CleanupLocation(PD));
Scope discardScope(SGF.Cleanups, CleanupLocation(PD));

// Manage the parameter.
ManagedValue argrv = makeArgument(type, &*f.begin(), paramLoc);
Expand All @@ -328,25 +328,25 @@ struct ArgumentInitHelper {
SILLocation loc(PD);
loc.markAsPrologue();
if (argrv.getType().isAddress())
gen.B.createDebugValueAddr(loc, argrv.getValue(), {PD->isLet(), ArgNo});
SGF.B.createDebugValueAddr(loc, argrv.getValue(), {PD->isLet(), ArgNo});
else
gen.B.createDebugValue(loc, argrv.getValue(), {PD->isLet(), ArgNo});
SGF.B.createDebugValue(loc, argrv.getValue(), {PD->isLet(), ArgNo});
}
};
} // end anonymous namespace


static void makeArgument(Type ty, ParamDecl *decl,
SmallVectorImpl<SILValue> &args, SILGenFunction &gen) {
SmallVectorImpl<SILValue> &args, SILGenFunction &SGF) {
assert(ty && "no type?!");

// Destructure tuple arguments.
if (TupleType *tupleTy = ty->getAs<TupleType>()) {
for (auto fieldType : tupleTy->getElementTypes())
makeArgument(fieldType, decl, args, gen);
makeArgument(fieldType, decl, args, SGF);
} else {
auto arg =
gen.F.begin()->createFunctionArgument(gen.getLoweredType(ty), decl);
SGF.F.begin()->createFunctionArgument(SGF.getLoweredType(ty), decl);
args.push_back(arg);
}
}
Expand All @@ -362,7 +362,7 @@ void SILGenFunction::bindParametersForForwarding(const ParameterList *params,
}
}

static void emitCaptureArguments(SILGenFunction &gen,
static void emitCaptureArguments(SILGenFunction &SGF,
AnyFunctionRef closure,
CapturedValue capture,
unsigned ArgNo) {
Expand All @@ -379,63 +379,63 @@ static void emitCaptureArguments(SILGenFunction &gen,
closure.getGenericEnvironment(), interfaceType);
};

switch (gen.SGM.Types.getDeclCaptureKind(capture)) {
switch (SGF.SGM.Types.getDeclCaptureKind(capture)) {
case CaptureKind::None:
break;

case CaptureKind::Constant: {
auto type = getVarTypeInCaptureContext();
auto &lowering = gen.getTypeLowering(type);
auto &lowering = SGF.getTypeLowering(type);
// Constant decls are captured by value.
SILType ty = lowering.getLoweredType();
SILValue val = gen.F.begin()->createFunctionArgument(ty, VD);
SILValue val = SGF.F.begin()->createFunctionArgument(ty, VD);

// If the original variable was settable, then Sema will have treated the
// VarDecl as an lvalue, even in the closure's use. As such, we need to
// allow formation of the address for this captured value. Create a
// temporary within the closure to provide this address.
if (VD->isSettable(VD->getDeclContext())) {
auto addr = gen.emitTemporaryAllocation(VD, ty);
lowering.emitStore(gen.B, VD, val, addr, StoreOwnershipQualifier::Init);
auto addr = SGF.emitTemporaryAllocation(VD, ty);
lowering.emitStore(SGF.B, VD, val, addr, StoreOwnershipQualifier::Init);
val = addr;
}

gen.VarLocs[VD] = SILGenFunction::VarLoc::get(val);
SGF.VarLocs[VD] = SILGenFunction::VarLoc::get(val);
if (auto *AllocStack = dyn_cast<AllocStackInst>(val))
AllocStack->setArgNo(ArgNo);
else
gen.B.createDebugValue(Loc, val, {/*Constant*/true, ArgNo});
SGF.B.createDebugValue(Loc, val, {/*Constant*/true, ArgNo});

// TODO: Closure contexts should always be guaranteed.
if (!gen.SGM.M.getOptions().EnableGuaranteedClosureContexts
if (!SGF.SGM.M.getOptions().EnableGuaranteedClosureContexts
&& !lowering.isTrivial())
gen.enterDestroyCleanup(val);
SGF.enterDestroyCleanup(val);
break;
}

case CaptureKind::Box: {
// LValues are captured as a retained @box that owns
// the captured value.
auto type = getVarTypeInCaptureContext();
auto boxTy = gen.SGM.Types.getContextBoxTypeForCapture(VD,
gen.getLoweredType(type).getSwiftRValueType(),
gen.F.getGenericEnvironment(), /*mutable*/ true);
SILValue box = gen.F.begin()->createFunctionArgument(
auto boxTy = SGF.SGM.Types.getContextBoxTypeForCapture(VD,
SGF.getLoweredType(type).getSwiftRValueType(),
SGF.F.getGenericEnvironment(), /*mutable*/ true);
SILValue box = SGF.F.begin()->createFunctionArgument(
SILType::getPrimitiveObjectType(boxTy), VD);
SILValue addr = gen.B.createProjectBox(VD, box, 0);
gen.VarLocs[VD] = SILGenFunction::VarLoc::get(addr, box);
gen.B.createDebugValueAddr(Loc, addr, {/*Constant*/false, ArgNo});
if (!gen.SGM.M.getOptions().EnableGuaranteedClosureContexts)
gen.Cleanups.pushCleanup<StrongReleaseCleanup>(box);
SILValue addr = SGF.B.createProjectBox(VD, box, 0);
SGF.VarLocs[VD] = SILGenFunction::VarLoc::get(addr, box);
SGF.B.createDebugValueAddr(Loc, addr, {/*Constant*/false, ArgNo});
if (!SGF.SGM.M.getOptions().EnableGuaranteedClosureContexts)
SGF.Cleanups.pushCleanup<StrongReleaseCleanup>(box);
break;
}
case CaptureKind::StorageAddress: {
// Non-escaping stored decls are captured as the address of the value.
auto type = getVarTypeInCaptureContext();
SILType ty = gen.getLoweredType(type).getAddressType();
SILValue addr = gen.F.begin()->createFunctionArgument(ty, VD);
gen.VarLocs[VD] = SILGenFunction::VarLoc::get(addr);
gen.B.createDebugValueAddr(Loc, addr, {/*Constant*/true, ArgNo});
SILType ty = SGF.getLoweredType(type).getAddressType();
SILValue addr = SGF.F.begin()->createFunctionArgument(ty, VD);
SGF.VarLocs[VD] = SILGenFunction::VarLoc::get(addr);
SGF.B.createDebugValueAddr(Loc, addr, {/*Constant*/true, ArgNo});
break;
}
}
Expand Down Expand Up @@ -465,25 +465,25 @@ void SILGenFunction::emitProlog(AnyFunctionRef TheClosure,
}
}

static void emitIndirectResultParameters(SILGenFunction &gen, Type resultType,
static void emitIndirectResultParameters(SILGenFunction &SGF, Type resultType,
DeclContext *DC) {
// Expand tuples.
if (auto tupleType = resultType->getAs<TupleType>()) {
for (auto eltType : tupleType->getElementTypes()) {
emitIndirectResultParameters(gen, eltType, DC);
emitIndirectResultParameters(SGF, eltType, DC);
}
return;
}

// If the return type is address-only, emit the indirect return argument.

const TypeLowering &resultTI =
gen.getTypeLowering(DC->mapTypeIntoContext(resultType));
SGF.getTypeLowering(DC->mapTypeIntoContext(resultType));
if (!SILModuleConventions::isReturnedIndirectlyInSIL(
resultTI.getLoweredType(), gen.SGM.M)) {
resultTI.getLoweredType(), SGF.SGM.M)) {
return;
}
auto &ctx = gen.getASTContext();
auto &ctx = SGF.getASTContext();
auto var = new (ctx) ParamDecl(VarDecl::Specifier::InOut,
SourceLoc(), SourceLoc(),
ctx.getIdentifier("$return_value"), SourceLoc(),
Expand All @@ -492,7 +492,7 @@ static void emitIndirectResultParameters(SILGenFunction &gen, Type resultType,
var->setInterfaceType(resultType);

auto *arg =
gen.F.begin()->createFunctionArgument(resultTI.getLoweredType(), var);
SGF.F.begin()->createFunctionArgument(resultTI.getLoweredType(), var);
(void)arg;
}

Expand Down
20 changes: 10 additions & 10 deletions lib/SILGen/SILGenStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ namespace {
SmallVectorImpl<CleanupHandle> &cleanups)
: Storage(storage), Cleanups(cleanups) {}

void copyOrInitValueInto(SILGenFunction &gen, SILLocation loc,
void copyOrInitValueInto(SILGenFunction &SGF, SILLocation loc,
ManagedValue value, bool isInit) override {
Storage = value.getValue();
auto cleanup = value.getCleanup();
Expand All @@ -263,7 +263,7 @@ namespace {
} // end anonymous namespace

static InitializationPtr
prepareIndirectResultInit(SILGenFunction &gen, CanType resultType,
prepareIndirectResultInit(SILGenFunction &SGF, CanType resultType,
ArrayRef<SILResultInfo> &allResults,
MutableArrayRef<SILValue> &directResults,
ArrayRef<SILArgument*> &indirectResultAddrs,
Expand All @@ -274,7 +274,7 @@ prepareIndirectResultInit(SILGenFunction &gen, CanType resultType,
tupleInit->SubInitializations.reserve(resultTupleType->getNumElements());

for (auto resultEltType : resultTupleType.getElementTypes()) {
auto eltInit = prepareIndirectResultInit(gen, resultEltType, allResults,
auto eltInit = prepareIndirectResultInit(SGF, resultEltType, allResults,
directResults,
indirectResultAddrs, cleanups);
tupleInit->SubInitializations.push_back(std::move(eltInit));
Expand All @@ -288,14 +288,14 @@ prepareIndirectResultInit(SILGenFunction &gen, CanType resultType,
allResults = allResults.slice(1);

// If it's indirect, we should be emitting into an argument.
if (gen.silConv.isSILIndirect(result)) {
if (SGF.silConv.isSILIndirect(result)) {
// Pull off the next indirect result argument.
SILValue addr = indirectResultAddrs.front();
indirectResultAddrs = indirectResultAddrs.slice(1);

// Create an initialization which will initialize it.
auto &resultTL = gen.getTypeLowering(addr->getType());
auto temporary = gen.useBufferAsTemporary(addr, resultTL);
auto &resultTL = SGF.getTypeLowering(addr->getType());
auto temporary = SGF.useBufferAsTemporary(addr, resultTL);

// Remember the cleanup that will be activated.
auto cleanup = temporary->getInitializedCleanup();
Expand All @@ -320,19 +320,19 @@ prepareIndirectResultInit(SILGenFunction &gen, CanType resultType,
/// \param cleanups - will be filled (after initialization completes)
/// with all the active cleanups managing the result values
static std::unique_ptr<Initialization>
prepareIndirectResultInit(SILGenFunction &gen, CanType formalResultType,
prepareIndirectResultInit(SILGenFunction &SGF, CanType formalResultType,
SmallVectorImpl<SILValue> &directResultsBuffer,
SmallVectorImpl<CleanupHandle> &cleanups) {
auto fnConv = gen.F.getConventions();
auto fnConv = SGF.F.getConventions();

// Make space in the direct-results array for all the entries we need.
directResultsBuffer.append(fnConv.getNumDirectSILResults(), SILValue());

ArrayRef<SILResultInfo> allResults = fnConv.funcTy->getResults();
MutableArrayRef<SILValue> directResults = directResultsBuffer;
ArrayRef<SILArgument*> indirectResultAddrs = gen.F.getIndirectResults();
ArrayRef<SILArgument*> indirectResultAddrs = SGF.F.getIndirectResults();

auto init = prepareIndirectResultInit(gen, formalResultType, allResults,
auto init = prepareIndirectResultInit(SGF, formalResultType, allResults,
directResults, indirectResultAddrs,
cleanups);

Expand Down
Loading

0 comments on commit bd32f9e

Please sign in to comment.