Skip to content

Track dependencies of SIL instructions on opened archetypes which they use #3197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 81 additions & 41 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "swift/SIL/SILDebugScope.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILOpenedArchetypesTracker.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/StringExtras.h"

Expand All @@ -40,6 +41,16 @@ class SILBuilder {
/// recorded in this list.
SmallVectorImpl<SILInstruction *> *InsertedInstrs = nullptr;

/// An immutable view on the set of available opened archetypes.
/// It is passed down to SILInstruction constructors and create
/// methods.
SILOpenedArchetypesState OpenedArchetypes;

/// Maps opened archetypes to their definitions. If provided,
/// can be used by the builder. It is supposed to be used
/// only by SILGen or SIL deserializers.
SILOpenedArchetypesTracker *OpenedArchetypesTracker = nullptr;

public:
SILBuilder(SILFunction &F) : F(F), BB(0) {}

Expand Down Expand Up @@ -75,6 +86,19 @@ class SILBuilder {
return F.getModule().getTypeLowering(T);
}

void setOpenedArchetypesTracker(SILOpenedArchetypesTracker *Tracker) {
this->OpenedArchetypesTracker = Tracker;
this->OpenedArchetypes.setOpenedArchetypesTracker(OpenedArchetypesTracker);
}

SILOpenedArchetypesTracker *getOpenedArchetypesTracker() const {
return OpenedArchetypesTracker;
}

SILOpenedArchetypesState &getOpenedArchetypes() {
return OpenedArchetypes;
}

void setCurrentDebugScope(const SILDebugScope *DS) { CurDebugScope = DS; }
const SILDebugScope *getCurrentDebugScope() const { return CurDebugScope; }

Expand Down Expand Up @@ -214,54 +238,57 @@ class SILBuilder {
SILDebugVariable Var = SILDebugVariable()) {
Loc.markAsPrologue();
return insert(AllocStackInst::create(getSILDebugLocation(Loc),
elementType, F, Var));
elementType, F, OpenedArchetypes,
Var));
}

AllocRefInst *createAllocRef(SILLocation Loc, SILType elementType, bool objc,
bool canAllocOnStack) {
// AllocRefInsts expand to function calls and can therefore not be
// counted towards the function prologue.
assert(!Loc.isInPrologue());
return insert(new (F.getModule()) AllocRefInst(
getSILDebugLocation(Loc), elementType, F, objc, canAllocOnStack));
return insert(AllocRefInst::create(getSILDebugLocation(Loc), elementType, F,
objc, canAllocOnStack,
OpenedArchetypes));
}

AllocRefDynamicInst *createAllocRefDynamic(SILLocation Loc, SILValue operand,
SILType type, bool objc) {
// AllocRefDynamicInsts expand to function calls and can therefore
// not be counted towards the function prologue.
assert(!Loc.isInPrologue());
return insert(new (F.getModule()) AllocRefDynamicInst(
getSILDebugLocation(Loc), operand, type, objc));
return insert(AllocRefDynamicInst::create(getSILDebugLocation(Loc), operand,
type, objc, F, OpenedArchetypes));
}

AllocValueBufferInst *
createAllocValueBuffer(SILLocation Loc, SILType valueType, SILValue operand) {
return insert(new (F.getModule()) AllocValueBufferInst(
getSILDebugLocation(Loc), valueType, operand));
return insert(AllocValueBufferInst::create(
getSILDebugLocation(Loc), valueType, operand, F, OpenedArchetypes));
}

AllocBoxInst *createAllocBox(SILLocation Loc, SILType ElementType,
SILDebugVariable Var = SILDebugVariable()) {
Loc.markAsPrologue();
return insert(
AllocBoxInst::create(getSILDebugLocation(Loc), ElementType, F, Var));
return insert(AllocBoxInst::create(getSILDebugLocation(Loc), ElementType, F,
OpenedArchetypes, Var));
}

AllocExistentialBoxInst *
createAllocExistentialBox(SILLocation Loc, SILType ExistentialType,
CanType ConcreteType,
ArrayRef<ProtocolConformanceRef> Conformances) {
return insert(AllocExistentialBoxInst::create(
getSILDebugLocation(Loc), ExistentialType, ConcreteType,
Conformances, &F));
getSILDebugLocation(Loc), ExistentialType, ConcreteType, Conformances,
&F, OpenedArchetypes));
}

ApplyInst *createApply(SILLocation Loc, SILValue Fn, SILType SubstFnTy,
SILType Result, ArrayRef<Substitution> Subs,
ArrayRef<SILValue> Args, bool isNonThrowing) {
return insert(ApplyInst::create(getSILDebugLocation(Loc), Fn, SubstFnTy,
Result, Subs, Args, isNonThrowing, F));
Result, Subs, Args, isNonThrowing, F,
OpenedArchetypes));
}

ApplyInst *createApply(SILLocation Loc, SILValue Fn, ArrayRef<SILValue> Args,
Expand All @@ -278,16 +305,18 @@ class SILBuilder {
SILBasicBlock *errorBB) {
return insertTerminator(TryApplyInst::create(getSILDebugLocation(Loc),
fn, substFnTy, subs, args,
normalBB, errorBB, F));
normalBB, errorBB, F,
OpenedArchetypes));
}

PartialApplyInst *createPartialApply(SILLocation Loc, SILValue Fn,
SILType SubstFnTy,
ArrayRef<Substitution> Subs,
ArrayRef<SILValue> Args,
SILType ClosureTy) {
return insert(PartialApplyInst::create(
getSILDebugLocation(Loc), Fn, SubstFnTy, Subs, Args, ClosureTy, F));
return insert(PartialApplyInst::create(getSILDebugLocation(Loc), Fn,
SubstFnTy, Subs, Args, ClosureTy, F,
OpenedArchetypes));
}

BuiltinInst *createBuiltin(SILLocation Loc, Identifier Name, SILType ResultTy,
Expand Down Expand Up @@ -526,8 +555,8 @@ class SILBuilder {

UncheckedRefCastInst *createUncheckedRefCast(SILLocation Loc, SILValue Op,
SILType Ty) {
return insert(new (F.getModule()) UncheckedRefCastInst(
getSILDebugLocation(Loc), Op, Ty));
return insert(UncheckedRefCastInst::create(getSILDebugLocation(Loc), Op, Ty,
F, OpenedArchetypes));
}

UncheckedRefCastAddrInst *
Expand All @@ -539,20 +568,20 @@ class SILBuilder {

UncheckedAddrCastInst *createUncheckedAddrCast(SILLocation Loc, SILValue Op,
SILType Ty) {
return insert(new (F.getModule()) UncheckedAddrCastInst(
getSILDebugLocation(Loc), Op, Ty));
return insert(UncheckedAddrCastInst::create(getSILDebugLocation(Loc), Op,
Ty, F, OpenedArchetypes));
}

UncheckedTrivialBitCastInst *
createUncheckedTrivialBitCast(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule()) UncheckedTrivialBitCastInst(
getSILDebugLocation(Loc), Op, Ty));
return insert(UncheckedTrivialBitCastInst::create(
getSILDebugLocation(Loc), Op, Ty, F, OpenedArchetypes));
}

UncheckedBitwiseCastInst *
createUncheckedBitwiseCast(SILLocation Loc, SILValue Op, SILType Ty) {
return insert(new (F.getModule()) UncheckedBitwiseCastInst(
getSILDebugLocation(Loc), Op, Ty));
return insert(UncheckedBitwiseCastInst::create(getSILDebugLocation(Loc), Op,
Ty, F, OpenedArchetypes));
}

RefToBridgeObjectInst *createRefToBridgeObject(SILLocation Loc, SILValue Ref,
Expand Down Expand Up @@ -648,8 +677,8 @@ class SILBuilder {

UnconditionalCheckedCastInst *
createUnconditionalCheckedCast(SILLocation Loc, SILValue op, SILType destTy) {
return insert(new (F.getModule()) UnconditionalCheckedCastInst(
getSILDebugLocation(Loc), op, destTy));
return insert(UnconditionalCheckedCastInst::create(
getSILDebugLocation(Loc), op, destTy, F, OpenedArchetypes));
}

UnconditionalCheckedCastAddrInst *createUnconditionalCheckedCastAddr(
Expand Down Expand Up @@ -896,11 +925,10 @@ class SILBuilder {
WitnessMethodInst *createWitnessMethod(SILLocation Loc, CanType LookupTy,
ProtocolConformanceRef Conformance,
SILDeclRef Member, SILType MethodTy,
SILValue OptionalOpenedExistential,
bool Volatile = false) {
return insert(WitnessMethodInst::create(
getSILDebugLocation(Loc), LookupTy, Conformance, Member, MethodTy,
&F, OptionalOpenedExistential, Volatile));
&F, OpenedArchetypes, Volatile));
}

DynamicMethodInst *createDynamicMethod(SILLocation Loc, SILValue Operand,
Expand All @@ -912,27 +940,39 @@ class SILBuilder {

OpenExistentialAddrInst *
createOpenExistentialAddr(SILLocation Loc, SILValue Operand, SILType SelfTy) {
return insert(new (F.getModule()) OpenExistentialAddrInst(
auto *I = insert(new (F.getModule()) OpenExistentialAddrInst(
getSILDebugLocation(Loc), Operand, SelfTy));
if (OpenedArchetypesTracker)
OpenedArchetypesTracker->registerOpenedArchetypes(I);
return I;
}

OpenExistentialMetatypeInst *createOpenExistentialMetatype(SILLocation Loc,
SILValue operand,
SILType selfTy) {
return insert(new (F.getModule()) OpenExistentialMetatypeInst(
auto *I = insert(new (F.getModule()) OpenExistentialMetatypeInst(
getSILDebugLocation(Loc), operand, selfTy));
if (OpenedArchetypesTracker)
OpenedArchetypesTracker->registerOpenedArchetypes(I);
return I;
}

OpenExistentialRefInst *
createOpenExistentialRef(SILLocation Loc, SILValue Operand, SILType Ty) {
return insert(new (F.getModule()) OpenExistentialRefInst(
auto *I = insert(new (F.getModule()) OpenExistentialRefInst(
getSILDebugLocation(Loc), Operand, Ty));
if (OpenedArchetypesTracker)
OpenedArchetypesTracker->registerOpenedArchetypes(I);
return I;
}

OpenExistentialBoxInst *
createOpenExistentialBox(SILLocation Loc, SILValue Operand, SILType Ty) {
return insert(new (F.getModule()) OpenExistentialBoxInst(
auto *I = insert(new (F.getModule()) OpenExistentialBoxInst(
getSILDebugLocation(Loc), Operand, Ty));
if (OpenedArchetypesTracker)
OpenedArchetypesTracker->registerOpenedArchetypes(I);
return I;
}

InitExistentialAddrInst *
Expand All @@ -942,25 +982,25 @@ class SILBuilder {
ArrayRef<ProtocolConformanceRef> Conformances) {
return insert(InitExistentialAddrInst::create(
getSILDebugLocation(Loc), Existential, FormalConcreteType,
LoweredConcreteType, Conformances, &F));
LoweredConcreteType, Conformances, &F, OpenedArchetypes));
}

InitExistentialMetatypeInst *
createInitExistentialMetatype(SILLocation Loc, SILValue metatype,
SILType existentialType,
ArrayRef<ProtocolConformanceRef> conformances) {
return insert(InitExistentialMetatypeInst::create(
getSILDebugLocation(Loc), existentialType, metatype, conformances,
&F));
getSILDebugLocation(Loc), existentialType, metatype, conformances, &F,
OpenedArchetypes));
}

InitExistentialRefInst *
createInitExistentialRef(SILLocation Loc, SILType ExistentialType,
CanType FormalConcreteType, SILValue Concrete,
ArrayRef<ProtocolConformanceRef> Conformances) {
return insert(InitExistentialRefInst::create(
getSILDebugLocation(Loc), ExistentialType, FormalConcreteType,
Concrete, Conformances, &F));
getSILDebugLocation(Loc), ExistentialType, FormalConcreteType, Concrete,
Conformances, &F, OpenedArchetypes));
}

DeinitExistentialAddrInst *createDeinitExistentialAddr(SILLocation Loc,
Expand Down Expand Up @@ -992,8 +1032,8 @@ class SILBuilder {
}

MetatypeInst *createMetatype(SILLocation Loc, SILType Metatype) {
return insert(new (F.getModule())
MetatypeInst(getSILDebugLocation(Loc), Metatype));
return insert(MetatypeInst::create(getSILDebugLocation(Loc), Metatype,
&F, OpenedArchetypes));
}

ObjCMetatypeToObjectInst *
Expand Down Expand Up @@ -1306,9 +1346,9 @@ class SILBuilder {
SILValue op, SILType destTy,
SILBasicBlock *successBB,
SILBasicBlock *failureBB) {
return insertTerminator(new (F.getModule()) CheckedCastBranchInst(
getSILDebugLocation(Loc), isExact, op, destTy, successBB,
failureBB));
return insertTerminator(CheckedCastBranchInst::create(
getSILDebugLocation(Loc), isExact, op, destTy, successBB, failureBB, F,
OpenedArchetypes));
}

CheckedCastAddrBranchInst *
Expand Down
Loading