Audit all SILPasses to ensure that new instructions are never created

without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
This commit is contained in:
Adrian Prantl
2014-10-28 01:49:11 +00:00
parent 35488903d3
commit c41b30299f
36 changed files with 383 additions and 211 deletions

View File

@@ -15,6 +15,7 @@
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILDebugScope.h"
namespace swift {
@@ -1057,6 +1058,37 @@ private:
}
};
/// An RAII version of SILBuilder that automatically sets up identical
/// SILDebugScopes for all instructions. This is useful for
/// situations where a single SIL instruction is lowered into a
/// sequence of SIL instructions.
template<unsigned N = 4> class SILBuilderWithScope : public SILBuilder {
SmallVector<SILInstruction*, N> InsertedInstrs;
SILDebugScope *DebugScope;
public:
explicit SILBuilderWithScope(SILInstruction *I)
: SILBuilder(I, &InsertedInstrs), DebugScope(I->getDebugScope()) {
assert((DebugScope || maybeScopeless(*I)) && "no debug scope");
}
explicit SILBuilderWithScope(SILInstruction *I, SILDebugScope *DS)
: SILBuilder(I, &InsertedInstrs), DebugScope(DS) {
}
explicit SILBuilderWithScope(SILBasicBlock *BB, SILDebugScope *DS)
: SILBuilder(BB, &InsertedInstrs), DebugScope(DS) {
}
~SILBuilderWithScope() {
for (auto *I : InsertedInstrs) {
assert(!I->getDebugScope() && "instruction was already assigned a scope");
I->setDebugScope(DebugScope);
}
}
};
} // end swift namespace
#endif

View File

@@ -52,6 +52,7 @@ public:
return getBuilder().getTrackingList();
}
SILBuilder &getBuilder() { return Builder; }
protected:
#define VALUE(CLASS, PARENT) \
@@ -64,8 +65,6 @@ protected:
void visitSILBasicBlock(SILBasicBlock* BB);
SILBuilder &getBuilder() { return Builder; }
// Derived classes of SILCloner using the CRTP can implement the following
// functions to customize behavior; the remap functions are called before
// cloning to modify constructor arguments and the post process function is
@@ -224,10 +223,16 @@ protected:
SILBasicBlock *getOpBasicBlock(SILBasicBlock *BB) {
return asImpl().remapBasicBlock(BB);
}
public:
void doPostProcess(SILInstruction *Orig, SILInstruction *Cloned) {
asImpl().postProcess(Orig, Cloned);
assert((Orig->getDebugScope() ? Cloned->getDebugScope()!=nullptr : true) &&
"cloned instruction dropped debug scope");
}
protected:
SILBuilder Builder;
SILBasicBlock *InsertBeforeBB;
llvm::DenseMap<SILValue, SILValue> ValueMap;
@@ -236,6 +241,31 @@ protected:
TypeSubstitutionMap OpenedExistentialSubs;
};
/// \brief A SILBuilder that automatically invokes postprocess on each
/// inserted instruction.
template<class SomeSILCloner, unsigned N = 4>
class SILBuilderWithPostProcess : public SILBuilder {
SomeSILCloner &SC;
SILInstruction *Orig;
SmallVector<SILInstruction*, N> InsertedInstrs;
public:
SILBuilderWithPostProcess(SomeSILCloner *sc, SILInstruction *Orig)
: SILBuilder(sc->getBuilder().getInsertionBB(), &InsertedInstrs),
SC(*sc), Orig(Orig)
{
setInsertionPoint(SC.getBuilder().getInsertionBB(),
SC.getBuilder().getInsertionPoint());
}
~SILBuilderWithPostProcess() {
for (auto *I : InsertedInstrs) {
SC.doPostProcess(Orig, I);
}
}
};
/// SILClonerWithScopes - a SILCloner that automatically clones
/// SILDebugScopes. In contrast to inline scopes, this generates a
/// deep copy of the scope tree.

View File

@@ -68,6 +68,11 @@ public:
void setParent(SILDebugScope *P) { Parent = P; }
};
#ifndef NDEBUG
/// Determine whether an instruction may not have a SILDebugScope.
bool maybeScopeless(SILInstruction &I);
#endif
}
#endif

View File

@@ -154,17 +154,15 @@ protected:
// the newly specialized function.
SILValue CalleeVal = Inst->getCallee();
FunctionRefInst *FRI = dyn_cast<FunctionRefInst>(CalleeVal);
SILBuilder &Builder = getBuilder();
SILBuilderWithPostProcess<TypeSubstCloner, 4> Builder(this, Inst);
if (FRI && FRI->getReferencedFunction() == Inst->getFunction()) {
FRI = Builder.createFunctionRef(getOpLocation(Inst->getLoc()),
&Builder.getFunction());
PartialApplyInst *NPAI =
Builder.createPartialApply(getOpLocation(Inst->getLoc()), FRI,
getOpType(Inst->getSubstCalleeSILType()),
ArrayRef<Substitution>(),
Args,
getOpType(Inst->getType()));
doPostProcess(Inst, NPAI);
return;
}
@@ -173,11 +171,10 @@ protected:
TempSubstList.push_back(asImpl().getOpSubstitution(Sub));
}
PartialApplyInst *N = Builder.createPartialApply(
Builder.createPartialApply(
getOpLocation(Inst->getLoc()), getOpValue(CalleeVal),
getOpType(Inst->getSubstCalleeSILType()), TempSubstList, Args,
getOpType(Inst->getType()));
doPostProcess(Inst, N);
}
void visitWitnessMethodInst(WitnessMethodInst *Inst) {
@@ -236,7 +233,7 @@ protected:
SILType sourceType = getOpType(inst->getOperand().getType());
SILType targetType = getOpType(inst->getType());
SILLocation loc = getOpLocation(inst->getLoc());
SILBuilder &B = getBuilder();
SILBuilderWithPostProcess<TypeSubstCloner, 16> B(this, inst);
// The non-addr CheckedCastInsts can currently only be used for
// types that don't have abstraction differences, so this is okay.
@@ -279,7 +276,7 @@ protected:
SILLocation loc = getOpLocation(inst->getLoc());
SILValue src = getOpValue(inst->getSrc());
SILValue dest = getOpValue(inst->getDest());
SILBuilder &B = getBuilder();
SILBuilderWithPostProcess<TypeSubstCloner, 16> B(this, inst);
CanType sourceType = getOpASTType(inst->getSourceType());
CanType targetType = getOpASTType(inst->getTargetType());
@@ -295,11 +292,9 @@ protected:
case DynamicCastFeasibility::MaySucceed: {
// TODO: simplify?
auto newInst =
B.createUnconditionalCheckedCastAddr(loc, inst->getConsumptionKind(),
src, sourceType,
dest, targetType);
doPostProcess(inst, newInst);
return;
}
@@ -307,8 +302,7 @@ protected:
// runtime as the spec for the instruction requires and propagate
// undef to all uses.
case DynamicCastFeasibility::WillFail: {
auto newInst = B.createBuiltinTrap(loc);
doPostProcess(inst, newInst);
B.createBuiltinTrap(loc);
// mem2reg's invariants get unhappy if we don't try to
// initialize a loadable result.
@@ -335,15 +329,14 @@ protected:
SILBasicBlock *succBB = getOpBasicBlock(inst->getSuccessBB());
SILBasicBlock *failBB = getOpBasicBlock(inst->getFailureBB());
SILBuilder &B = getBuilder();
SILBuilderWithPostProcess<TypeSubstCloner, 16> B(this, inst);
switch (classifyDynamicCast(SwiftMod, sourceType, targetType)) {
case DynamicCastFeasibility::WillSucceed: {
emitSuccessfulIndirectUnconditionalCast(B, SwiftMod, loc,
inst->getConsumptionKind(),
src, sourceType,
dest, targetType);
auto br = B.createBranch(loc, succBB);
doPostProcess(inst, br);
B.createBranch(loc, succBB);
return;
}
@@ -360,11 +353,10 @@ protected:
}
// Otherwise, use the indirect cast.
auto br = B.createCheckedCastAddrBranch(loc, inst->getConsumptionKind(),
B.createCheckedCastAddrBranch(loc, inst->getConsumptionKind(),
src, sourceType,
dest, targetType,
succBB, failBB);
doPostProcess(inst, br);
return;
}
@@ -373,7 +365,7 @@ protected:
auto &srcTL = B.getModule().getTypeLowering(src.getType());
srcTL.emitDestroyAddress(B, loc, src);
}
doPostProcess(inst, B.createBranch(loc, failBB));
B.createBranch(loc, failBB);
return;
}
}
@@ -391,7 +383,7 @@ protected:
SILLocation loc = getOpLocation(inst->getLoc());
SILBasicBlock *succBB = getOpBasicBlock(inst->getSuccessBB());
SILBasicBlock *failBB = getOpBasicBlock(inst->getFailureBB());
SILBuilder &B = getBuilder();
SILBuilderWithPostProcess<TypeSubstCloner, 16> B(this, inst);
SILValue operand = getOpValue(inst->getOperand());
@@ -406,8 +398,7 @@ protected:
// we're still using checked_cast_branch for address-only stuff.
if (loweredTargetType.isAddress()) {
if (sourceType == targetType) {
auto br = B.createBranch(loc, succBB, operand);
doPostProcess(inst, br);
B.createBranch(loc, succBB, operand);
return;
}
goto maySucceed;
@@ -418,21 +409,19 @@ protected:
loweredTargetType, sourceType,
targetType);
auto br = B.createBranch(loc, succBB, result);
doPostProcess(inst, br);
B.createBranch(loc, succBB, result);
return;
}
maySucceed:
case DynamicCastFeasibility::MaySucceed: {
auto br = B.createCheckedCastBranch(loc, /*exact*/ false, operand,
B.createCheckedCastBranch(loc, /*exact*/ false, operand,
loweredTargetType, succBB, failBB);
doPostProcess(inst, br);
return;
}
case DynamicCastFeasibility::WillFail:
doPostProcess(inst, B.createBranch(loc, failBB));
B.createBranch(loc, failBB);
return;
}
}

View File

@@ -96,7 +96,8 @@ private:
return InLoc;
// Inlined location wraps the call site that is being inlined, regardless
// of the input location.
return Loc.hasValue() ? Loc.getValue() : SILLocation((Decl*)nullptr);
return Loc.hasValue() ? Loc.getValue() :
MandatoryInlinedLocation::getMandatoryInlinedLocation((Decl*)nullptr);
}
InlineKind IKind;

View File

@@ -1285,6 +1285,7 @@ void IRGenSILFunction::emitFunctionArgDebugInfo(SILBasicBlock *BB) {
}
}
void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
// Insert into the lowered basic block.
llvm::BasicBlock *llBB = getLoweredBB(BB).bb;
@@ -1352,8 +1353,12 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
// Until SILDebugScopes are properly serialized, bare functions
// are allowed to not have a scope.
if (!DS && CurSILFn->isBare())
if (!DS) {
if (CurSILFn->isBare())
DS = CurSILFn->getDebugScope();
else
assert(maybeScopeless(I) && "instruction has location, but no scope");
}
// Ignore scope-less instructions and have IRBuilder reuse the
// previous location and scope.

View File

@@ -285,4 +285,39 @@ SILValue SILBuilder::emitObjCToThickMetatype(SILLocation Loc, SILValue Op,
return createObjCToThickMetatype(Loc, Op, Ty);
}
#ifndef NDEBUG
/// Determine whether an instruction may not have a SILDebugScope.
bool swift::maybeScopeless(SILInstruction &I) {
// This list is supposed to get ever shorter as we are tightening
// the requirements for the optimizer.
switch (I.getLoc().getKind()) {
case SILLocation::CleanupKind:
case SILLocation::ImplicitReturnKind:
case SILLocation::ArtificialUnreachableKind:
case SILLocation::SILFileKind:
return true;
default: break;
}
if (!I.getLoc().isNull() || I.getLoc().isAutoGenerated())
return true;
switch (I.getKind()) {
case ValueKind::BranchInst:
case ValueKind::CondBranchInst:
case ValueKind::DebugValueAddrInst:
case ValueKind::DebugValueInst:
case ValueKind::GlobalAddrInst:
case ValueKind::ReleaseValueInst:
case ValueKind::RetainValueInst:
case ValueKind::StrongReleaseInst:
case ValueKind::StrongRetainInst:
case ValueKind::TupleInst:
case ValueKind::UnreachableInst:
return true;
default: break;
}
auto *Fn = I.getParent()->getParent();
return Fn->isTransparent() || Fn->isBare();
}
#endif

View File

@@ -432,6 +432,7 @@ static ManagedValue emitGlobalVariableRef(SILGenFunction &gen,
// VarLocs.
auto &entryBB = gen.getFunction().getBlocks().front();
SILBuilder B(&entryBB, entryBB.begin());
B.setTrackingList(gen.getBuilder().getTrackingList());
auto *silG = gen.SGM.getSILGlobalVariable(var, NotForDefinition);
SILValue addr = B.createGlobalAddr(var, silG);
@@ -3311,8 +3312,10 @@ void SILGenFunction::emitEpilog(SILLocation TopLevel, bool AutoGen) {
if (!returnValue)
returnValue = emitEmptyTuple(CleanupLocation::getCleanupLocation(TopLevel));
B.createReturn(returnLoc, returnValue)
->setDebugScope(MainScope);
B.createReturn(returnLoc, returnValue);
if (!MainScope)
MainScope = F.getDebugScope();
setDebugScopeForInsertedInstrs(MainScope);
}
void SILGenFunction::emitDestroyingDestructor(DestructorDecl *dd) {
@@ -4650,6 +4653,9 @@ void SILGenFunction::emitGlobalAccessor(VarDecl *global,
addr = B.createAddressToPointer(global, addr, rawPointerSILTy);
B.createReturn(global, addr);
if (!MainScope)
MainScope = F.getDebugScope();
setDebugScopeForInsertedInstrs(MainScope);
}
RValue RValueEmitter::
@@ -5817,6 +5823,7 @@ RValue RValueEmitter::emitForceValue(SILLocation loc, Expr *E,
failureBB->eraseFromParent();
} else {
SILBuilder failureBuilder(failureBB);
failureBuilder.setTrackingList(SGF.getBuilder().getTrackingList());
auto boolTy = SILType::getBuiltinIntegerType(1, SGF.getASTContext());
auto trueV = failureBuilder.createIntegerLiteral(loc, boolTy, 1);
failureBuilder.createCondFail(loc, trueV);

View File

@@ -123,8 +123,9 @@ public:
SmallVector<SILInstruction*, 32> InsertedInstrs;
size_t LastInsnWithoutScope;
/// B - The SILBuilder used to construct the SILFunction. It is what maintains
/// the notion of the current block being emitted into.
/// B - The SILBuilder used to construct the SILFunction. It is
/// what maintains the notion of the current block being emitted
/// into.
SILBuilder B;
/// IndirectReturnAddress - For a function with an indirect return, holds a

View File

@@ -428,13 +428,13 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI,
if (isa<DeallocBoxInst>(LastRelease))
continue;
SILBuilder BuildDestroy(LastRelease);
SILBuilderWithScope<1> BuildDestroy(LastRelease);
BuildDestroy.emitDestroyAddr(Loc, PointerResult);
}
}
for (auto Return : Returns) {
SILBuilder BuildDealloc(Return);
SILBuilderWithScope<1> BuildDealloc(Return);
BuildDealloc.createDeallocStack(Loc, ASI->getContainerResult());
}
@@ -632,7 +632,7 @@ static PartialApplyInst *specializePartialApply(PartialApplyInst *PartialApply,
}
// Build the function_ref and partial_apply.
SILBuilder Builder(PartialApply);
SILBuilderWithScope<2> Builder(PartialApply);
SILValue FunctionRef = Builder.createFunctionRef(PartialApply->getLoc(),
Cloner.getCloned());
CanSILFunctionType CanFnTy = Cloner.getCloned()->getLoweredFunctionType();

View File

@@ -622,6 +622,7 @@ struct InductionInfo {
return;
auto Loc = Inc->getLoc();
auto Scope = Inc->getDebugScope();
auto FName = getCmpFunction(Loc, "cmp_sge", Start.getType(), Builder);
SmallVector<SILValue, 4> Args(1, Start);
@@ -629,7 +630,8 @@ struct InductionInfo {
auto CmpSGE = Builder.createBuiltin(Loc, FName,
SILType::getBuiltinIntegerType(1, Builder.getASTContext()),
{}, Args);
Builder.createCondFail(Loc, CmpSGE);
CmpSGE->setDebugScope(Scope);
Builder.createCondFail(Loc, CmpSGE)->setDebugScope(Scope);
IsOverflowCheckInserted = true;
// We can now remove the cond fail on the increment the above comparison
@@ -796,9 +798,10 @@ public:
void hoistCheckToPreheader(ArraySemanticsCall CheckToHoist,
SILBasicBlock *Preheader,
DominanceInfo *DT) {
SILBuilder Builder(Preheader->getTerminator());
ApplyInst *AI = CheckToHoist;
SILLocation Loc = AI->getLoc();
SILBuilderWithScope<> Builder(Preheader->getTerminator(),
AI->getDebugScope());
// Get the first induction value.
auto FirstVal = Ind->getFirstValue();
@@ -988,7 +991,7 @@ static bool hoistBoundsChecks(SILLoop *Loop, DominanceInfo *DT, SILLoopInfo *LI,
if (IVarsFound)
for (auto *Arg: Header->getBBArgs())
if (auto *IV = IndVars[Arg]) {
SILBuilder B(Preheader->getTerminator());
SILBuilderWithScope<> B(Preheader->getTerminator());
IV->checkOverflow(B);
}

View File

@@ -391,7 +391,8 @@ ClosureCloner::visitStrongReleaseInst(StrongReleaseInst *Inst) {
// object type argument.
SILFunction &F = getBuilder().getFunction();
auto &typeLowering = F.getModule().getTypeLowering(I->second.getType());
typeLowering.emitReleaseValue(getBuilder(), Inst->getLoc(), I->second);
SILBuilderWithPostProcess<ClosureCloner, 1> B(this, Inst);
typeLowering.emitReleaseValue(B, Inst->getLoc(), I->second);
return;
}
}
@@ -438,7 +439,8 @@ ClosureCloner::visitLoadInst(LoadInst *Inst) {
if (I != AddrArgumentMap.end()) {
// Loads of a struct_element_addr of an argument get replaced with
// struct_extract of the new object type argument.
SILValue V = getBuilder().emitStructExtract(Inst->getLoc(), I->second,
SILBuilderWithPostProcess<ClosureCloner, 1> B(this, Inst);
SILValue V = B.emitStructExtract(Inst->getLoc(), I->second,
SEAI->getField(),
Inst->getType());
ValueMap.insert(std::make_pair(Inst, V));
@@ -683,7 +685,7 @@ processPartialApplyInst(PartialApplyInst *PAI, IndicesSet &PromotableIndices,
// Initialize a SILBuilder and create a function_ref referencing the cloned
// closure.
SILBuilder B(PAI);
SILBuilderWithScope<8> B(PAI);
SILValue FnVal = B.createFunctionRef(PAI->getLoc(), ClonedFn);
SILType FnTy = FnVal.getType();

View File

@@ -235,7 +235,7 @@ SILFunction *CapturePropagation::specializeConstClosure(PartialApplyInst *PAI,
void CapturePropagation::rewritePartialApply(PartialApplyInst *OrigPAI,
SILFunction *SpecialF) {
SILBuilder Builder(OrigPAI);
SILBuilderWithScope<2> Builder(OrigPAI);
auto FuncRef = Builder.createFunctionRef(OrigPAI->getLoc(), SpecialF);
auto NewPAI = Builder.createPartialApply(OrigPAI->getLoc(),
FuncRef,

View File

@@ -223,7 +223,7 @@ struct ArgDescriptor {
/// Update the callsite to pass in the correct arguments.
static void rewriteApplyInst(ArgDescriptor &AD, SILFunction *NewF) {
SILBuilder Builder(AD.AI);
SILBuilderWithScope<2> Builder(AD.AI);
FunctionRefInst *FRI = Builder.createFunctionRef(AD.AI->getLoc(), NewF);
// Create the args for the new apply by removing the closure argument and

View File

@@ -43,7 +43,7 @@ static SILInstruction *constructResultWithOverflowTuple(BuiltinInst *BI,
// Construct the folded instruction - a tuple of two literals, the
// result and overflow.
SILBuilder B(BI);
SILBuilderWithScope<4> B(BI);
SILLocation Loc = BI->getLoc();
SILValue Result[] = {
B.createIntegerLiteral(Loc, ResTy1, Res),
@@ -217,7 +217,7 @@ static SILInstruction *constantFoldCompare(BuiltinInst *BI,
case BuiltinValueKind::ICMP_ULE: Res = V1.ule(V2); break;
case BuiltinValueKind::ICMP_UGE: Res = V1.uge(V2); break;
}
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
return B.createIntegerLiteral(BI->getLoc(), BI->getType(), Res);
}
@@ -301,7 +301,7 @@ constantFoldAndCheckDivision(BuiltinInst *BI, BuiltinValueKind ID,
}
// Add the literal instruction to represnet the result of the division.
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
return B.createIntegerLiteral(BI->getLoc(), BI->getType(), ResVal);
}
@@ -368,7 +368,7 @@ static SILInstruction *constantFoldBinary(BuiltinInst *BI,
break;
}
// Add the literal instruction to represent the result.
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
return B.createIntegerLiteral(BI->getLoc(), BI->getType(), ResI);
}
case BuiltinValueKind::FAdd:
@@ -399,7 +399,7 @@ static SILInstruction *constantFoldBinary(BuiltinInst *BI,
}
// Add the literal instruction to represent the result.
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
return B.createFloatLiteral(BI->getLoc(), BI->getType(), LHSF);
}
}
@@ -664,7 +664,7 @@ case BuiltinValueKind::id:
}
// Add the literal instruction to represent the result of the cast.
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
return B.createIntegerLiteral(BI->getLoc(), BI->getType(), CastResV);
}
@@ -712,7 +712,7 @@ case BuiltinValueKind::id:
}
// The call to the builtin should be replaced with the constant value.
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
return B.createFloatLiteral(Loc, BI->getType(), TruncVal);
}
}
@@ -803,7 +803,7 @@ static bool CCPFunctionBody(SILFunction &F, bool EnableDiagnostics,
if (auto *BI = dyn_cast<BuiltinInst>(I)) {
if (isApplyOfBuiltin(*BI, BuiltinValueKind::AssertConf)) {
// Instantiate the constant.
SILBuilder B(BI);
SILBuilderWithScope<1> B(BI);
auto AssertConfInt = B.createIntegerLiteral(
BI->getLoc(), BI->getType(), AssertConfiguration);
BI->replaceAllUsesWith(AssertConfInt);

View File

@@ -398,7 +398,8 @@ bool CopyForwarding::propagateCopy(CopyAddrInst *CopyInst) {
DEBUG(llvm::dbgs() << " Forwarding Copy:" << *CopyInst);
if (!CopyInst->isInitializationOfDest()) {
SILBuilder(CopyInst).createDestroyAddr(CopyInst->getLoc(),
CopyInst->getDest());
CopyInst->getDest())
->setDebugScope(CopyInst->getDebugScope());
}
CopyInst->eraseFromParent();
HasChanged = true;
@@ -500,7 +501,8 @@ bool CopyForwarding::forwardPropagateCopy(
assert(!Copy->isInitializationOfDest() && "expected a deinit");
DestroyAddrInst *Destroy =
SILBuilder(SI).createDestroyAddr(Copy->getLoc(), CopyDest);
SILBuilderWithScope<1>(SI, Copy->getDebugScope())
.createDestroyAddr(Copy->getLoc(), CopyDest);
Copy->setIsInitializationOfDest(IsInitialization);
assert(ValueUses.back()->getUser() == Copy && "bad value use");
@@ -563,7 +565,8 @@ bool CopyForwarding::backwardPropagateCopy(
// initialization.
if (auto Copy = dyn_cast<CopyAddrInst>(&*SI)) {
if (Copy->getDest() == CopySrc && !Copy->isInitializationOfDest()) {
SILBuilder(SI).createDestroyAddr(Copy->getLoc(), CopySrc);
SILBuilder(SI).createDestroyAddr(Copy->getLoc(), CopySrc)
->setDebugScope(Copy->getDebugScope());
Copy->setIsInitializationOfDest(IsInitialization);
}
}
@@ -626,7 +629,8 @@ bool CopyForwarding::hoistDestroy(SILInstruction *DestroyPoint,
return false;
DEBUG(llvm::dbgs() << " Hoisting to Use:" << *Inst);
SILBuilder(std::next(SI)).createDestroyAddr(DestroyLoc, CurrentDef);
SILBuilder(std::next(SI)).createDestroyAddr(DestroyLoc, CurrentDef)
->setDebugScope(Inst->getDebugScope());
HasChanged = true;
return true;
}
@@ -702,7 +706,8 @@ void CopyForwarding::forwardCopiesOf(SILValue Def, SILFunction *F) {
// We make no attempt to use the best DebugLoc, because in all known
// cases, we only have one.
SILBuilder(SuccBB->begin()).createDestroyAddr(DestroyLoc, CurrentDef);
SILBuilder(SuccBB->begin()).createDestroyAddr(DestroyLoc, CurrentDef)
->setDebugScope(HoistedDestroy->getDebugScope());
HasChanged = true;
}
}

View File

@@ -312,7 +312,7 @@ static void getScalarizedElements(SILValue V,
/// can return the newly generated sub-element loads.
static SILValue scalarizeLoad(LoadInst *LI,
SmallVectorImpl<SILValue> &ElementAddrs) {
SILBuilder B(LI);
SILBuilderWithScope<16> B(LI);
SmallVector<SILValue, 4> ElementTmps;
for (unsigned i = 0, e = ElementAddrs.size(); i != e; ++i) {
@@ -689,7 +689,8 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
if (!UsesToScalarize.empty()) {
SILInstruction *PointerInst = cast<SILInstruction>(Pointer);
SmallVector<SILValue, 4> ElementAddrs;
SILBuilder AddrBuilder(++SILBasicBlock::iterator(PointerInst));
SILBuilderWithScope<16> AddrBuilder(++SILBasicBlock::iterator(PointerInst),
PointerInst->getDebugScope());
getScalarizedElementAddresses(Pointer, AddrBuilder, PointerInst->getLoc(),
ElementAddrs);
@@ -707,10 +708,9 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
continue;
}
SILBuilder B(User);
// Scalarize AssignInst
if (auto *AI = dyn_cast<AssignInst>(User)) {
SILBuilderWithScope<> B(User, AI->getDebugScope());
getScalarizedElements(AI->getOperand(0), ElementTmps, AI->getLoc(), B);
for (unsigned i = 0, e = ElementAddrs.size(); i != e; ++i)
@@ -721,6 +721,7 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
// Scalarize StoreInst
if (auto *SI = dyn_cast<StoreInst>(User)) {
SILBuilderWithScope<> B(User, SI->getDebugScope());
getScalarizedElements(SI->getOperand(0), ElementTmps, SI->getLoc(), B);
for (unsigned i = 0, e = ElementAddrs.size(); i != e; ++i)
@@ -731,6 +732,7 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
// Scalarize CopyAddrInst.
auto *CAI = cast<CopyAddrInst>(User);
SILBuilderWithScope<> B(User, CAI->getDebugScope());
// Determine if this is a copy *from* or *to* "Pointer".
if (CAI->getSrc() == Pointer) {

View File

@@ -308,9 +308,11 @@ void DCE::replaceBranchWithJump(SILInstruction *Inst, SILBasicBlock *Block) {
assert(!LiveValues.count(*A) && "Unexpected live block argument!");
Args.push_back(SILUndef::get((*A)->getType(), (*A)->getModule()));
}
Branch = SILBuilder(Inst).createBranch(Inst->getLoc(), Block, Args);
Branch = SILBuilder(Inst).createBranch(Inst->getLoc(), Block, Args)
->setDebugScope(Inst->getDebugScope());
} else {
Branch = SILBuilder(Inst).createBranch(Inst->getLoc(), Block);
Branch = SILBuilder(Inst).createBranch(Inst->getLoc(), Block)
->setDebugScope(Inst->getDebugScope());
}
DEBUG(llvm::dbgs() << "Inserted unconditional branch:\n");
DEBUG(Branch->dump());

View File

@@ -1053,7 +1053,7 @@ void LifetimeChecker::updateInstructionForInitState(DIMemoryUse &InstInfo) {
unsigned FirstElement = InstInfo.FirstElement;
unsigned NumElements = InstInfo.NumElements;
SmallVector<SILInstruction*, 8> InsertedInsts;
SmallVector<SILInstruction*, 4> InsertedInsts;
SILBuilder B(Inst, &InsertedInsts);
LowerAssignInstruction(B, AI, InitKind);
@@ -1061,6 +1061,7 @@ void LifetimeChecker::updateInstructionForInitState(DIMemoryUse &InstInfo) {
// If lowering of the assign introduced any new loads or stores, keep track
// of them.
for (auto I : InsertedInsts) {
I->setDebugScope(AI->getDebugScope());
if (isa<StoreInst>(I)) {
NonLoadUses[I] = Uses.size();
Uses.push_back(DIMemoryUse(I, Kind, FirstElement, NumElements));
@@ -1119,7 +1120,7 @@ void LifetimeChecker::processNonTrivialRelease(unsigned ReleaseID) {
// free the memory. If this is a derived class, we may have to do a load of
// the 'self' box to get the class reference.
if (TheMemory.isClassInitSelf()) {
SILBuilder B(Release);
SILBuilderWithScope<4> B(Release);
SILValue Pointer = Release->getOperand(0);
// If we see an alloc_box as the pointer, then we're deallocating a 'box'
@@ -1198,7 +1199,8 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
// Create the control variable as the first instruction in the function (so
// that it is easy to destroy the stack location.
SILBuilder B(TheMemory.getFunctionEntryPoint());
SILBuilderWithScope<16> B(TheMemory.getFunctionEntryPoint(),
TheMemory.getFunction().getDebugScope());
SILType IVType =
SILType::getBuiltinIntegerType(NumMemoryElements, Module.getASTContext());
auto Alloc = B.createAllocStack(Loc, IVType);
@@ -1343,7 +1345,7 @@ SILValue LifetimeChecker::handleConditionalInitAssign() {
/// to emit branching logic when an element may or may not be initialized.
void LifetimeChecker::
handleConditionalDestroys(SILValue ControlVariableAddr) {
SILBuilder B(TheMemory.MemoryInst);
SILBuilderWithScope<16> B(TheMemory.MemoryInst);
Identifier ShiftRightFn, TruncateFn;
unsigned NumMemoryElements = TheMemory.getNumMemoryElements();
@@ -1786,7 +1788,7 @@ static bool lowerRawSILOperations(SILFunction &Fn) {
// Unprocessed assigns just lower into assignments, not initializations.
if (auto *AI = dyn_cast<AssignInst>(Inst)) {
SILBuilder B(AI);
SILBuilderWithScope<4> B(AI);
LowerAssignInstruction(B, AI, IsNotInitialization);
// Assign lowering may split the block. If it did,
// reset our iteration range to the block after the insertion.

View File

@@ -145,7 +145,7 @@ static bool devirtMethod(ApplyInst *AI, SILDeclRef Member,
// method inst.
SILType FuncSelfTy = paramTypes[paramTypes.size() - 1];
SILType OriginTy = ClassInstance.getType();
SILBuilder B(AI);
SILBuilderWithScope<16> B(AI);
// Then compare the two types and if they are unequal...
if (FuncSelfTy != OriginTy) {
@@ -339,7 +339,7 @@ bool WitnessMethodDevirtualizer::devirtualize() {
bool WitnessMethodDevirtualizer::processNormalProtocolConformance(
bool PartOfSpecialized) {
// Ok, we found the member we are looking for. Devirtualize away!
SILBuilder Builder(AI);
SILBuilderWithScope<2> Builder(AI);
SILLocation Loc = AI->getLoc();
FunctionRefInst *FRI = Builder.createFunctionRef(Loc, F);
@@ -404,7 +404,7 @@ bool WitnessMethodDevirtualizer::processInheritedProtocolConformance() {
assert(SILTy.isSuperclassOf(SelfTy) &&
"Should only create upcasts for sub class devirtualization.");
Self = SILBuilder(AI).createUpcast(AI->getLoc(), *Self, SILTy);
Self = SILBuilderWithScope<1>(AI).createUpcast(AI->getLoc(), *Self, SILTy);
SmallVector<Substitution, 16> SelfDerivedSubstitutions;
for (auto &origSub : AI->getSubstitutions())
@@ -620,11 +620,13 @@ static ApplyInst *CloneApply(ApplyInst *AI, SILBuilder &Builder) {
for (unsigned i = 0, e = Args.size(); i != e; ++i)
Ret[i] = Args[i];
return Builder.createApply(AI->getLoc(), AI->getCallee(),
auto NAI = Builder.createApply(AI->getLoc(), AI->getCallee(),
AI->getSubstCalleeSILType(),
AI->getType(),
AI->getSubstitutions(),
Ret, AI->isTransparent());
NAI->setDebugScope(AI->getDebugScope());
return NAI;
}
/// Insert monomorphic inline caches for a specific class type \p SubClassTy.
@@ -662,7 +664,7 @@ static ApplyInst* insertMonomorphicInlineCaches(ApplyInst *AI,
SILBasicBlock *Continue = Entry->splitBasicBlock(It);
SILBuilder Builder(Entry);
SILBuilderWithScope<> Builder(Entry, AI->getDebugScope());
// Create the checked_cast_branch instruction that checks at runtime if the
// class instance is identical to the SILType.
assert(SubClassTy.getClassOrBoundGenericClass() &&
@@ -683,8 +685,10 @@ static ApplyInst* insertMonomorphicInlineCaches(ApplyInst *AI,
if (!SRI && It != Entry->begin())
SRI = dyn_cast<StrongRetainInst>(--It);
if (SRI && SRI->getOperand() == ClassInstance) {
VirtBuilder.createStrongRetain(SRI->getLoc(), ClassInstance);
IdenBuilder.createStrongRetain(SRI->getLoc(), DownCastedClassInstance);
VirtBuilder.createStrongRetain(SRI->getLoc(), ClassInstance)
->setDebugScope(SRI->getDebugScope());
IdenBuilder.createStrongRetain(SRI->getLoc(), DownCastedClassInstance)
->setDebugScope(SRI->getDebugScope());
SRI->eraseFromParent();
}
}
@@ -696,8 +700,10 @@ static ApplyInst* insertMonomorphicInlineCaches(ApplyInst *AI,
// Create a PHInode for returning the return value from both apply
// instructions.
SILArgument *Arg = Continue->createArgument(AI->getType());
IdenBuilder.createBranch(AI->getLoc(), Continue, ArrayRef<SILValue>(IdenAI));
VirtBuilder.createBranch(AI->getLoc(), Continue, ArrayRef<SILValue>(VirtAI));
IdenBuilder.createBranch(AI->getLoc(), Continue, ArrayRef<SILValue>(IdenAI))
->setDebugScope(AI->getDebugScope());
VirtBuilder.createBranch(AI->getLoc(), Continue, ArrayRef<SILValue>(VirtAI))
->setDebugScope(AI->getDebugScope());
// Remove the old Apply instruction.
AI->replaceAllUsesWith(Arg);

View File

@@ -155,7 +155,7 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
PI != PE; ++PI) {
SILBasicBlock *PredB = *PI;
BranchInst *BI = cast<BranchInst>(PredB->getTerminator());
SILBuilder Bldr(PredB);
SILBuilderWithScope<1> Bldr(PredB, BI->getDebugScope());
Bldr.createBranch(BI->getLoc(), BI->getDestBB());
ToBeDeleted.push_back(BI);
}
@@ -197,21 +197,19 @@ static bool constantFoldTerminator(SILBasicBlock &BB,
if (IntegerLiteralInst *ConstCond =
dyn_cast_or_null<IntegerLiteralInst>(CondI)) {
SILBuilder B(&BB);
SILBuilderWithScope<> B(&BB, CBI->getDebugScope());
// Determine which of the successors is unreachable and create a new
// terminator that only branches to the reachable sucessor.
SILBasicBlock *UnreachableBlock = nullptr;
bool CondIsTrue = false;
if (ConstCond->getValue() == APInt(1, /*value*/ 0, false)) {
B.createBranch(Loc,
CBI->getFalseBB(), CBI->getFalseArgs());
B.createBranch(Loc, CBI->getFalseBB(), CBI->getFalseArgs());
UnreachableBlock = CBI->getTrueBB();
} else {
assert(ConstCond->getValue() == APInt(1, /*value*/ 1, false) &&
"Our representation of true/false does not match.");
B.createBranch(Loc,
CBI->getTrueBB(), CBI->getTrueArgs());
B.createBranch(Loc, CBI->getTrueBB(), CBI->getTrueArgs());
UnreachableBlock = CBI->getFalseBB();
CondIsTrue = true;
}
@@ -277,12 +275,11 @@ static bool constantFoldTerminator(SILBasicBlock &BB,
return false;
// Replace the switch with a branch to the TheSuccessorBlock.
SILBuilder B(&BB);
SILBuilderWithScope<> B(&BB, TI->getDebugScope());
SILLocation Loc = TI->getLoc();
if (!TheSuccessorBlock->bbarg_empty()) {
assert(TheEnum->hasOperand());
B.createBranch(Loc, TheSuccessorBlock,
TheEnum->getOperand());
B.createBranch(Loc, TheSuccessorBlock, TheEnum->getOperand());
} else
B.createBranch(Loc, TheSuccessorBlock);
@@ -348,7 +345,7 @@ static bool constantFoldTerminator(SILBasicBlock &BB,
// Add the branch instruction with the block.
if (TheSuccessorBlock) {
SILBuilder B(&BB);
SILBuilderWithScope<1> B(&BB, TI->getDebugScope());
B.createBranch(TI->getLoc(), TheSuccessorBlock);
recursivelyDeleteTriviallyDeadInstructions(TI, true);
NumTerminatorsFolded++;

View File

@@ -418,7 +418,7 @@ bool BBEnumTagDataflowState::visitRetainValueInst(RetainValueInst *RVI) {
DEBUG(llvm::dbgs() << " Found RetainValue: " << *RVI);
DEBUG(llvm::dbgs() << " Paired to Enum Oracle: " << FindResult->first);
SILBuilder Builder(RVI);
SILBuilderWithScope<8> Builder(RVI);
createRefCountOpForPayload(Builder, RVI, FindResult->second);
RVI->eraseFromParent();
return true;
@@ -438,7 +438,7 @@ bool BBEnumTagDataflowState::visitReleaseValueInst(ReleaseValueInst *RVI) {
DEBUG(llvm::dbgs() << " Found ReleaseValue: " << *RVI);
DEBUG(llvm::dbgs() << " Paired to Enum Oracle: " << FindResult->first);
SILBuilder Builder(RVI);
SILBuilderWithScope<8> Builder(RVI);
createRefCountOpForPayload(Builder, RVI, FindResult->second);
RVI->eraseFromParent();
return true;
@@ -528,7 +528,8 @@ BBEnumTagDataflowState::moveReleasesUpCFGIfCasesCovered(AliasAnalysis *AA) {
// predecessor.
assert(P.first->getSingleSuccessor() &&
"Can not hoist release into BB that has multiple successors");
SILBuilder Builder(P.first->getTerminator());
SILBuilderWithScope<8> Builder(P.first->getTerminator(),
RVI->getDebugScope());
createRefCountOpForPayload(Builder, RVI, P.second);
}

View File

@@ -382,7 +382,7 @@ static void
rewriteApplyInstToCallNewFunction(FunctionAnalyzer &Analyzer, SILFunction *NewF,
CallGraphNode::CallerCallSiteList CallSites) {
for (ApplyInst *AI : CallSites) {
SILBuilder Builder(AI);
SILBuilderWithScope<16> Builder(AI);
FunctionRefInst *FRI = Builder.createFunctionRef(AI->getLoc(), NewF);
@@ -429,7 +429,7 @@ static void createThunkBody(SILBasicBlock *BB, SILFunction *NewF,
FunctionAnalyzer &Analyzer) {
// TODO: What is the proper location to use here?
SILLocation Loc = BB->getParent()->getLocation();
SILBuilder Builder(BB);
SILBuilderWithScope<16> Builder(BB, NewF->getDebugScope());
FunctionRefInst *FRI = Builder.createFunctionRef(Loc, NewF);

View File

@@ -48,6 +48,7 @@ static SILInstruction *createIncrement(SILValue Ptr, SILInstruction *InsertPt) {
// TODO: What is the correct SILLocation to use here? If the InsertPt is a
// terminator, then we will have the wrong location type and hit an assertion.
// Also: what scope?
auto Loc = SILFileLocation(SourceLoc());
// If Ptr has reference semantics itself, create the strong_retain and
@@ -68,6 +69,7 @@ static SILInstruction *createDecrement(SILValue Ptr, SILInstruction *InsertPt) {
// TODO: What is the correct SILLocation to use here? If the InsertPt is a
// terminator, then we will have the wrong location type and hit an assertion.
// Also: what scope?
auto Loc = SILFileLocation(SourceLoc());
// If Ptr has reference semantics itself, create a strong_release.

View File

@@ -54,7 +54,7 @@ findExtractPathFromAddressValueToLoad(SILValue Address, SILValue StoredValue,
// Ok, at this point we know that we can construct our aggregate projections
// from our list of address projections.
SILValue LastExtract = StoredValue;
SILBuilder Builder(Inst);
SILBuilderWithScope<16> Builder(Inst);
while (!ProjectionPath.empty()) {
auto P = ProjectionPath.pop_back_val();
if (ValueDecl *D = P.getDecl()) {
@@ -404,7 +404,7 @@ forwardAddressValueToUncheckedAddrToLoad(SILValue Address,
SILType OutputTy = UADCI->getType();
bool OutputIsTrivial = OutputTy.isTrivial(Mod);
SILBuilder B(LI);
SILBuilderWithScope<1> B(LI);
SILValue CastValue;
// If the output is trivial, we have a trivial bit cast.

View File

@@ -47,7 +47,7 @@ static void fixupReferenceCounts(SILBasicBlock::iterator I, SILLocation Loc,
SmallVectorImpl<SILValue> &CaptureArgs) {
// Either release the callee (which the apply would have done) or remove a
// retain that happens to be the immediately preceding instruction.
SILBuilder B(I);
SILBuilderWithScope<16> B(I);
auto *NewRelease = B.emitStrongRelease(Loc, CalleeValue);
// Important: we move the insertion point before this new release, just in
@@ -115,7 +115,8 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
// source of the store and erase it.
if (SRI) {
if (CalleeValue.isValid())
SILBuilder(SRI).emitStrongRelease(SRI->getLoc(), CalleeValue);
SILBuilderWithScope<1>(SRI).
emitStrongRelease(SRI->getLoc(), CalleeValue);
SRI->eraseFromParent();
}
@@ -145,7 +146,7 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
// If there is a strong release of the partial apply, then replace it with
// releases of the captured arguments.
if (SRI) {
SILBuilder B(SRI);
SILBuilderWithScope<16> B(SRI);
for (auto &CaptureArg : CaptureArgs)
if (!CaptureArg.getType().isAddress())
B.emitReleaseValueOperation(SRI->getLoc(), CaptureArg);

View File

@@ -512,7 +512,7 @@ AggregateAvailableValues(SILInstruction *Inst, SILType LoadTy,
}
SILBuilder B(Inst);
SILBuilderWithScope<16> B(Inst);
if (TupleType *TT = LoadTy.getAs<TupleType>()) {
SmallVector<SILValue, 4> ResultElts;
@@ -726,7 +726,7 @@ bool AllocOptimize::promoteDestroyAddr(DestroyAddrInst *DAI) {
DEBUG(llvm::dbgs() << " *** Promoting destroy_addr: " << *DAI << "\n");
DEBUG(llvm::dbgs() << " To value: " << *NewVal.getDef() << "\n");
SILBuilder(DAI).emitReleaseValueOperation(DAI->getLoc(), NewVal);
SILBuilderWithScope<1>(DAI).emitReleaseValueOperation(DAI->getLoc(), NewVal);
DAI->eraseFromParent();
return true;
}
@@ -792,6 +792,7 @@ void AllocOptimize::explodeCopyAddr(CopyAddrInst *CAI) {
// Update the instructions that touch the memory. NewInst can grow as this
// iterates, so we can't use a foreach loop.
for (auto *NewInst : NewInsts) {
NewInst->setDebugScope(CAI->getDebugScope());
switch (NewInst->getKind()) {
default:
NewInst->dump();

View File

@@ -466,7 +466,7 @@ static bool tryToSinkRefCountAcrossSwitch(SwitchEnumInst *Switch,
return false;
// Ok, we have a ref count instruction, sink it!
SILBuilder Builder(Switch);
SILBuilderWithScope<> Builder(Switch, RV->getDebugScope());
for (unsigned i = 0, e = Switch->getNumCases(); i != e; ++i) {
auto Case = Switch->getCase(i);
EnumElementDecl *Enum = Case.first;
@@ -551,7 +551,7 @@ static bool tryToSinkRefCountAcrossSelectEnum(CondBranchInst *CondBr,
Elts[1] = OtherElt;
SILBuilder Builder(SEI);
SILBuilderWithScope<> Builder(SEI, I->getDebugScope());
// Ok, we have a ref count instruction, sink it!
for (unsigned i = 0; i != 2; ++i) {
@@ -615,7 +615,7 @@ static bool tryToSinkRefCountInst(SILBasicBlock::iterator T,
// copy of this instruction in each one of our successors unless they are
// ignoreable trap blocks.
DEBUG(llvm::dbgs() << " Sinking " << *I);
SILBuilder Builder(T);
SILBuilderWithScope<> Builder(T, I->getDebugScope());
for (auto &Succ : T->getParent()->getSuccs()) {
SILBasicBlock *SuccBB = Succ.getBB();
@@ -1075,7 +1075,7 @@ bool BBEnumTagDataflowState::visitRetainValueInst(RetainValueInst *RVI) {
DEBUG(llvm::dbgs() << " Found RetainValue: " << *RVI);
DEBUG(llvm::dbgs() << " Paired to Enum Oracle: " << FindResult->first);
SILBuilder Builder(RVI);
SILBuilderWithScope<> Builder(RVI, RVI->getDebugScope());
createRefCountOpForPayload(Builder, RVI, FindResult->second);
RVI->eraseFromParent();
return true;
@@ -1095,7 +1095,7 @@ bool BBEnumTagDataflowState::visitReleaseValueInst(ReleaseValueInst *RVI) {
DEBUG(llvm::dbgs() << " Found ReleaseValue: " << *RVI);
DEBUG(llvm::dbgs() << " Paired to Enum Oracle: " << FindResult->first);
SILBuilder Builder(RVI);
SILBuilderWithScope<> Builder(RVI , RVI->getDebugScope());
createRefCountOpForPayload(Builder, RVI, FindResult->second);
RVI->eraseFromParent();
return true;
@@ -1185,7 +1185,8 @@ BBEnumTagDataflowState::hoistDecrementsIntoSwitchRegions(AliasAnalysis *AA) {
// predecessor.
assert(P.first->getSingleSuccessor() &&
"Can not hoist release into BB that has multiple successors");
SILBuilder Builder(P.first->getTerminator());
SILBuilderWithScope<> Builder(P.first->getTerminator(),
RVI->getDebugScope());
createRefCountOpForPayload(Builder, RVI, P.second);
}

View File

@@ -112,9 +112,10 @@ SILInstruction *SILCombiner::visitSwitchEnumAddrInst(SwitchEnumAddrInst *SEAI) {
SILBasicBlock *Default = SEAI->hasDefault() ? SEAI->getDefaultBB() : 0;
LoadInst *EnumVal = Builder->createLoad(SEAI->getLoc(),
SEAI->getOperand());
Builder->createSwitchEnum(SEAI->getLoc(), EnumVal, Default, Cases);
LoadInst *EnumVal = Builder->createLoad(SEAI->getLoc(), SEAI->getOperand());
EnumVal->setDebugScope(SEAI->getDebugScope());
Builder->createSwitchEnum(SEAI->getLoc(), EnumVal, Default, Cases)
->setDebugScope(SEAI->getDebugScope());
return eraseInstFromFunction(*SEAI);
}
@@ -135,9 +136,12 @@ SILInstruction *SILCombiner::visitSelectEnumAddrInst(SelectEnumAddrInst *SEAI) {
SILValue Default = SEAI->hasDefault() ? SEAI->getDefaultResult() : SILValue();
LoadInst *EnumVal = Builder->createLoad(SEAI->getLoc(),
SEAI->getEnumOperand());
return SelectEnumInst::create(SEAI->getLoc(), EnumVal, SEAI->getType(),
EnumVal->setDebugScope(SEAI->getDebugScope());
auto *I = SelectEnumInst::create(SEAI->getLoc(), EnumVal, SEAI->getType(),
Default, Cases,
*SEAI->getParent()->getParent());
I->setDebugScope(SEAI->getDebugScope());
return I;
}
SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
@@ -187,6 +191,7 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
if (LegalUsers && IEI) {
auto *ConcAlloc = Builder->createAllocStack(AS->getLoc(),
IEI->getLoweredConcreteType());
ConcAlloc->setDebugScope(AS->getDebugScope());
SILValue(IEI, 0).replaceAllUsesWith(ConcAlloc->getAddressResult());
eraseInstFromFunction(*IEI);
@@ -194,13 +199,15 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
for (Operand *Op: AS->getUses()) {
if (auto *DA = dyn_cast<DestroyAddrInst>(Op->getUser())) {
Builder->setInsertionPoint(DA);
Builder->createDestroyAddr(DA->getLoc(), SILValue(ConcAlloc, 1));
Builder->createDestroyAddr(DA->getLoc(), SILValue(ConcAlloc, 1))
->setDebugScope(DA->getDebugScope());
eraseInstFromFunction(*DA);
}
if (auto *DS = dyn_cast<DeallocStackInst>(Op->getUser())) {
Builder->setInsertionPoint(DS);
Builder->createDeallocStack(DS->getLoc(), SILValue(ConcAlloc, 0));
Builder->createDeallocStack(DS->getLoc(), SILValue(ConcAlloc, 0))
->setDebugScope(DS->getDebugScope());
eraseInstFromFunction(*DS);
}
}
@@ -216,7 +223,8 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
// (load (upcast-ptr %x)) -> (upcast-ref (load %x))
if (auto *UI = dyn_cast<UpcastInst>(LI->getOperand())) {
SILValue NewLI = Builder->createLoad(LI->getLoc(), UI->getOperand());
auto NewLI = Builder->createLoad(LI->getLoc(), UI->getOperand());
NewLI->setDebugScope(LI->getDebugScope());
return new (UI->getModule()) UpcastInst(LI->getLoc(), NewLI,
LI->getType());
}
@@ -274,7 +282,9 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
Builder->createStructElementAddr(LI->getLoc(), LI->getOperand(),
cast<VarDecl>(V),
Inst->getType(0).getAddressType());
SEA->setDebugScope(LI->getDebugScope());
LastNewLoad = Builder->createLoad(LI->getLoc(), SEA);
LastNewLoad->setDebugScope(LI->getDebugScope());
replaceInstUsesWith(*Inst, LastNewLoad, 0);
eraseInstFromFunction(*Inst);
continue;
@@ -289,7 +299,9 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
Builder->createTupleElementAddr(LI->getLoc(), LI->getOperand(),
Proj.getIndex(),
Inst->getType(0).getAddressType());
TEA->setDebugScope(LI->getDebugScope());
LastNewLoad = Builder->createLoad(LI->getLoc(), TEA);
LastNewLoad->setDebugScope(LI->getDebugScope());
replaceInstUsesWith(*Inst, LastNewLoad, 0);
eraseInstFromFunction(*Inst);
}
@@ -435,7 +447,8 @@ SILInstruction *SILCombiner::visitPartialApplyInst(PartialApplyInst *PAI) {
if (!Param.isIndirect() && Param.isConsumed())
if (!Arg.getType().isAddress())
Builder->createReleaseValue(Loc, Arg);
Builder->createReleaseValue(Loc, Arg)
->setDebugScope(PAI->getDebugScope());
}
Builder->setInsertionPoint(OrigInsertPoint);
@@ -494,10 +507,12 @@ SILCombiner::optimizeApplyOfPartialApply(ApplyInst *AI, PartialApplyInst *PAI) {
ApplyInst *NAI = Builder->createApply(AI->getLoc(), FRI, FnType, ResultTy,
Subs, Args, AI->isTransparent());
NAI->setDebugScope(AI->getDebugScope());
// We also need to release the partial_apply instruction itself because it
// is consumed by the apply_instruction.
Builder->createStrongRelease(AI->getLoc(), PAI);
Builder->createStrongRelease(AI->getLoc(), PAI)
->setDebugScope(AI->getDebugScope());
replaceInstUsesWith(*AI, NAI);
return eraseInstFromFunction(*AI);
@@ -582,13 +597,15 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(ApplyInst *AI,
// other types alone.
if (OldOpType.isAddress()) {
assert(NewOpType.isAddress() && "Addresses should map to addresses.");
Args.push_back(Builder->createUncheckedAddrCast(AI->getLoc(),
Op, NewOpType));
auto UAC = Builder->createUncheckedAddrCast(AI->getLoc(), Op, NewOpType);
UAC->setDebugScope(AI->getDebugScope());
Args.push_back(UAC);
} else if (OldOpType.isHeapObjectReferenceType()) {
assert(NewOpType.isHeapObjectReferenceType() &&
"refs should map to refs.");
Args.push_back(Builder->createUncheckedRefCast(AI->getLoc(),
Op, NewOpType));
auto URC = Builder->createUncheckedRefCast(AI->getLoc(), Op, NewOpType);
URC->setDebugScope(AI->getDebugScope());
Args.push_back(URC);
} else {
Args.push_back(Op);
}
@@ -596,10 +613,12 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(ApplyInst *AI,
SILType CCSILTy = SILType::getPrimitiveObjectType(ConvertCalleeTy);
// Create the new apply inst.
return ApplyInst::create(AI->getLoc(), FRI, CCSILTy,
auto NAI = ApplyInst::create(AI->getLoc(), FRI, CCSILTy,
ConvertCalleeTy->getSILResult(),
ArrayRef<Substitution>(), Args, false,
*FRI->getReferencedFunction());
NAI->setDebugScope(AI->getDebugScope());
return NAI;
}
typedef SmallVector<SILInstruction*, 4> UserListTy;
@@ -765,6 +784,7 @@ void StringConcatenationOptimizer::adjustEncodings() {
// Convert UTF8 representation into UTF16.
SLILeft = Builder->createStringLiteral(AI->getLoc(), SLILeft->getValue(),
StringLiteralInst::Encoding::UTF16);
SLILeft->setDebugScope(AI->getDebugScope());
}
if (SLIRight->getEncoding() == StringLiteralInst::Encoding::UTF8 &&
@@ -775,6 +795,7 @@ void StringConcatenationOptimizer::adjustEncodings() {
// Convert UTF8 representation into UTF16.
SLIRight = Builder->createStringLiteral(AI->getLoc(), SLIRight->getValue(),
StringLiteralInst::Encoding::UTF16);
SLIRight->setDebugScope(AI->getDebugScope());
}
// It should be impossible to have two operands with different
@@ -838,12 +859,14 @@ SILInstruction *StringConcatenationOptimizer::optimize() {
auto *NewSLI = Builder->createStringLiteral(AI->getLoc(),
LV + Twine(RV),
Encoding);
NewSLI->setDebugScope(AI->getDebugScope());
Arguments.push_back(NewSLI);
// Length of the concatenated literal according to its encoding.
auto *Len = Builder->createIntegerLiteral(AI->getLoc(),
AILeft->getOperand(2).getType(),
getConcatenatedLength());
Len->setDebugScope(AI->getDebugScope());
Arguments.push_back(Len);
// isAscii flag for UTF8-encoded string literals.
@@ -853,6 +876,7 @@ SILInstruction *StringConcatenationOptimizer::optimize() {
auto *Ascii = Builder->createIntegerLiteral(AI->getLoc(),
ILType,
intmax_t(IsAscii));
Ascii->setDebugScope(AI->getDebugScope());
Arguments.push_back(Ascii);
}
@@ -1140,7 +1164,9 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
EnumInst *E =
Builder->createEnum(IEAI->getLoc(), SILValue(), IEAI->getElement(),
IEAI->getOperand().getType().getObjectType());
Builder->createStore(IEAI->getLoc(), E, IEAI->getOperand());
E->setDebugScope(IEAI->getDebugScope());
Builder->createStore(IEAI->getLoc(), E, IEAI->getOperand())
->setDebugScope(IEAI->getDebugScope());
return eraseInstFromFunction(*IEAI);
}
@@ -1167,8 +1193,9 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
EnumInst *E =
Builder->createEnum(IEDAI->getLoc(), SI->getSrc(), IEDAI->getElement(),
IEDAI->getOperand().getType().getObjectType());
Builder->createStore(IEDAI->getLoc(), E, IEDAI->getOperand());
E->setDebugScope(IEDAI->getDebugScope());
Builder->createStore(IEDAI->getLoc(), E, IEDAI->getOperand())
->setDebugScope(IEDAI->getDebugScope());
// Cleanup.
eraseInstFromFunction(*SI);
eraseInstFromFunction(*IEDAI);
@@ -1240,6 +1267,7 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
SILValue Distance = Bytes->getArguments()[0];
auto *NewPTAI =
Builder->createPointerToAddress(PTAI->getLoc(), Ptr, PTAI->getType());
NewPTAI->setDebugScope(PTAI->getDebugScope());
return new (PTAI->getModule())
IndexAddrInst(PTAI->getLoc(), NewPTAI, Distance);
}
@@ -1303,6 +1331,7 @@ SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
SILValue Op = UADCI->getOperand();
SILLocation Loc = UADCI->getLoc();
SILDebugScope *Scope = UADCI->getDebugScope();
// Ok, we have all loads. Lets simplify this. Go back through the loads a
// second time, rewriting them into a load + bitcast from our source.
@@ -1312,6 +1341,7 @@ SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
// Insert a new load from our source and bitcast that as appropriate.
LoadInst *NewLoad = Builder->createLoad(Loc, Op);
NewLoad->setDebugScope(Scope);
SILInstruction *BitCast = nullptr;
if (OutputIsTrivial)
BitCast = Builder->createUncheckedTrivialBitCast(Loc, NewLoad,
@@ -1319,6 +1349,7 @@ SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
else
BitCast = Builder->createUncheckedRefBitCast(Loc, NewLoad,
OutputTy.getObjectType());
BitCast->setDebugScope(Scope);
// Replace all uses of the old load with the new bitcasted result and erase
// the old load.
@@ -1416,6 +1447,7 @@ visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *TEDAI) {
// Grab the EnumAddr.
SILLocation Loc = TEDAI->getLoc();
SILDebugScope *Scope = TEDAI->getDebugScope();
SILValue EnumAddr = TEDAI->getOperand();
EnumElementDecl *EnumElt = TEDAI->getElement();
SILType PayloadType = TEDAI->getType().getObjectType();
@@ -1427,8 +1459,11 @@ visitUncheckedTakeEnumDataAddrInst(UncheckedTakeEnumDataAddrInst *TEDAI) {
LoadInst *L = cast<LoadInst>(U->getUser());
// Insert a new Load of the enum and extract the data from that.
auto *Load = Builder->createLoad(Loc, EnumAddr);
Load->setDebugScope(Scope);
auto *D = Builder->createUncheckedEnumData(
Loc, Builder->createLoad(Loc, EnumAddr), EnumElt, PayloadType);
Loc, Load, EnumElt, PayloadType);
D->setDebugScope(Scope);
// Replace all uses of the old load with the data and erase the old load.
replaceInstUsesWith(*L, D, 0);

View File

@@ -77,7 +77,7 @@ static bool expandCopyAddr(CopyAddrInst *CA) {
if (SrcType.isAddressOnly(M))
return false;
SILBuilder Builder(CA);
SILBuilderWithScope<16> Builder(CA);
// %new = load %0 : $*T
LoadInst *New = Builder.createLoad(CA->getLoc(), Source);
@@ -129,7 +129,7 @@ static bool expandCopyAddr(CopyAddrInst *CA) {
static bool expandDestroyAddr(DestroyAddrInst *DA) {
SILModule &Module = DA->getModule();
SILBuilder Builder(DA);
SILBuilderWithScope<16> Builder(DA);
// Strength reduce destroy_addr inst into release/store if
// we have a non-address only type.
@@ -155,7 +155,7 @@ static bool expandDestroyAddr(DestroyAddrInst *DA) {
static bool expandReleaseValue(ReleaseValueInst *DV) {
SILModule &Module = DV->getModule();
SILBuilder Builder(DV);
SILBuilderWithScope<16> Builder(DV);
// Strength reduce destroy_addr inst into release/store if
// we have a non-address only type.
@@ -178,7 +178,7 @@ static bool expandReleaseValue(ReleaseValueInst *DV) {
static bool expandRetainValue(RetainValueInst *CV) {
SILModule &Module = CV->getModule();
SILBuilder Builder(CV);
SILBuilderWithScope<16> Builder(CV);
// Strength reduce destroy_addr inst into release/store if
// we have a non-address only type.

View File

@@ -195,7 +195,7 @@ bool SROAMemoryUseAnalyzer::analyze() {
void
SROAMemoryUseAnalyzer::
createAllocas(llvm::SmallVector<AllocStackInst *, 4> &NewAllocations) {
SILBuilder B(AI);
SILBuilderWithScope<16> B(AI);
SILType Type = AI->getType(1).getObjectType();
if (TT) {
@@ -226,7 +226,7 @@ void SROAMemoryUseAnalyzer::chopUpAlloca(std::vector<AllocStackInst *> &Worklist
// Change any aggregate loads into field loads + aggregate structure.
for (auto *LI : Loads) {
SILBuilder B(LI);
SILBuilderWithScope<16> B(LI);
llvm::SmallVector<SILValue, 4> Elements;
for (auto *NewAI : NewAllocations)
Elements.push_back(B.createLoad(LI->getLoc(), SILValue(NewAI, 1)));
@@ -238,7 +238,7 @@ void SROAMemoryUseAnalyzer::chopUpAlloca(std::vector<AllocStackInst *> &Worklist
// Change any aggregate stores into extracts + field stores.
for (auto *SI : Stores) {
SILBuilder B(SI);
SILBuilderWithScope<16> B(SI);
for (unsigned EltNo : indices(NewAllocations))
B.createStore(SI->getLoc(),
createAggProjection(B, SI->getLoc(), SI->getSrc(), EltNo),
@@ -265,7 +265,8 @@ void SROAMemoryUseAnalyzer::chopUpAlloca(std::vector<AllocStackInst *> &Worklist
DEBUG(llvm::dbgs() << " Found DeallocStackInst!\n");
// Create the allocations in reverse order.
for (auto *NewAI : swift::reversed(NewAllocations))
B.createDeallocStack(DSI->getLoc(), SILValue(NewAI));
B.createDeallocStack(DSI->getLoc(), SILValue(NewAI))
->setDebugScope(DSI->getDebugScope());
DSI->eraseFromParent();
}
}

View File

@@ -151,7 +151,7 @@ static void simplifySwitchEnumInst(SwitchEnumInst *SEI,
auto *Dest = SEI->getCaseDestination(Element);
if (Dest->bbarg_empty()) {
SILBuilder(SEI).createBranch(SEI->getLoc(), Dest);
SILBuilderWithScope<1>(SEI).createBranch(SEI->getLoc(), Dest);
SEI->eraseFromParent();
return;
}
@@ -162,16 +162,15 @@ static void simplifySwitchEnumInst(SwitchEnumInst *SEI,
auto &Mod = SEI->getModule();
auto OpndTy = SEI->getOperand()->getType(0);
auto Ty = OpndTy.getEnumElementType(Element, Mod);
auto *UED = SILBuilder(SEI).createUncheckedEnumData(SEI->getLoc(),
SEI->getOperand(),
Element, Ty);
auto *UED = SILBuilderWithScope<1>(SEI)
.createUncheckedEnumData(SEI->getLoc(), SEI->getOperand(), Element, Ty);
Arg = SILValue(UED);
} else {
Arg = BB->getBBArg(0);
}
ArrayRef<SILValue> Args = { Arg };
SILBuilder(SEI).createBranch(SEI->getLoc(), Dest, Args);
SILBuilderWithScope<1>(SEI).createBranch(SEI->getLoc(), Dest, Args);
SEI->eraseFromParent();
}
@@ -179,10 +178,12 @@ static void simplifyCheckedCastBranchInst(CheckedCastBranchInst *CCBI,
bool SuccessTaken,
SILBasicBlock *DomBB) {
if (SuccessTaken)
SILBuilder(CCBI).createBranch(CCBI->getLoc(), CCBI->getSuccessBB(),
SILBuilderWithScope<1>(CCBI).createBranch(CCBI->getLoc(),
CCBI->getSuccessBB(),
SILValue(DomBB->getBBArg(0)));
else
SILBuilder(CCBI).createBranch(CCBI->getLoc(), CCBI->getFailureBB());
SILBuilderWithScope<1>(CCBI).createBranch(CCBI->getLoc(),
CCBI->getFailureBB());
CCBI->eraseFromParent();
}
@@ -258,7 +259,7 @@ static void simplifyCondBranchInst(CondBranchInst *BI, bool BranchTaken) {
auto LiveArgs = BranchTaken ? BI->getTrueArgs(): BI->getFalseArgs();
auto *LiveBlock = BranchTaken ? BI->getTrueBB() : BI->getFalseBB();
SILBuilder(BI).createBranch(BI->getLoc(), LiveBlock, LiveArgs);
SILBuilderWithScope<1>(BI).createBranch(BI->getLoc(), LiveBlock, LiveArgs);
BI->dropAllReferences();
BI->eraseFromParent();
}
@@ -820,7 +821,8 @@ bool SimplifyCFG::simplifyBranchBlock(BranchInst *BI) {
// then jump directly.
if (isTrampolineBlock(DestBB)) {
BranchInst* Br = dyn_cast<BranchInst>(DestBB->getTerminator());
SILBuilder(BI).createBranch(BI->getLoc(), Br->getDestBB(), BI->getArgs());
SILBuilderWithScope<1>(BI).createBranch(BI->getLoc(), Br->getDestBB(),
BI->getArgs());
// Eliminating the trampoline can expose opportuntities to improve the
// new block we branch to.
addToWorklist(Br->getDestBB());
@@ -856,7 +858,7 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
auto *DeadBlock = !isFalse ? BI->getFalseBB() : BI->getTrueBB();
auto *ThisBB = BI->getParent();
SILBuilder(BI).createBranch(BI->getLoc(), LiveBlock, LiveArgs);
SILBuilderWithScope<1>(BI).createBranch(BI->getLoc(), LiveBlock, LiveArgs);
BI->eraseFromParent();
if (IL->use_empty()) IL->eraseFromParent();
@@ -874,7 +876,8 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
if (isTrampolineBlock(TrueSide)) {
BranchInst* Br = cast<BranchInst>(TrueSide->getTerminator());
SILBuilder(BI).createCondBranch(BI->getLoc(), BI->getCondition(),
SILBuilderWithScope<1>(BI)
.createCondBranch(BI->getLoc(), BI->getCondition(),
Br->getDestBB(), BI->getTrueArgs(),
BI->getFalseBB(), BI->getFalseArgs());
BI->eraseFromParent();
@@ -885,7 +888,8 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
if (isTrampolineBlock(FalseSide)) {
BranchInst* Br = cast<BranchInst>(FalseSide->getTerminator());
SILBuilder(BI).createCondBranch(BI->getLoc(), BI->getCondition(),
SILBuilderWithScope<1>(BI)
.createCondBranch(BI->getLoc(), BI->getCondition(),
BI->getTrueBB(), BI->getTrueArgs(),
Br->getDestBB(), BI->getFalseArgs());
BI->eraseFromParent();
@@ -910,7 +914,7 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
}
if (SameArgs) {
SILBuilder(BI).createBranch(BI->getLoc(), TrueSide, TrueArgs);
SILBuilderWithScope<1>(BI).createBranch(BI->getLoc(), TrueSide, TrueArgs);
BI->eraseFromParent();
addToWorklist(ThisBB);
addToWorklist(TrueSide);
@@ -956,7 +960,8 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
{SecondElt, FirstValue},
};
auto *NewSEI = SILBuilder(SEI).createSelectEnum(SEI->getLoc(),
auto *NewSEI = SILBuilderWithScope<1>(SEI)
.createSelectEnum(SEI->getLoc(),
SEI->getEnumOperand(),
SEI->getType(),
SILValue(),
@@ -1016,7 +1021,7 @@ bool SimplifyCFG::simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI) {
if (!Dest) {
addToWorklist(SEI->getParent());
SILBuilder(SEI).createUnreachable(SEI->getLoc());
SILBuilderWithScope<1>(SEI).createUnreachable(SEI->getLoc());
SEI->eraseFromParent();
return true;
}
@@ -1024,7 +1029,7 @@ bool SimplifyCFG::simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI) {
if (!Element || !Element->hasArgumentType() || Dest->bbarg_empty()) {
assert(Dest->bbarg_empty() && "Unexpected argument at destination!");
SILBuilder(SEI).createBranch(SEI->getLoc(), Dest);
SILBuilderWithScope<1>(SEI).createBranch(SEI->getLoc(), Dest);
addToWorklist(SEI->getParent());
addToWorklist(Dest);
@@ -1036,13 +1041,12 @@ bool SimplifyCFG::simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI) {
auto &Mod = SEI->getModule();
auto OpndTy = SEI->getOperand()->getType(0);
auto Ty = OpndTy.getEnumElementType(Element, Mod);
auto *UED = SILBuilder(SEI).createUncheckedEnumData(SEI->getLoc(),
SEI->getOperand(),
Element, Ty);
auto *UED = SILBuilderWithScope<1>(SEI)
.createUncheckedEnumData(SEI->getLoc(), SEI->getOperand(), Element, Ty);
assert(Dest->bbarg_size() == 1 && "Expected only one argument!");
ArrayRef<SILValue> Args = { UED };
SILBuilder(SEI).createBranch(SEI->getLoc(), Dest, Args);
SILBuilderWithScope<1>(SEI).createBranch(SEI->getLoc(), Dest, Args);
addToWorklist(SEI->getParent());
addToWorklist(Dest);
@@ -1078,10 +1082,10 @@ bool SimplifyCFG::simplifySwitchEnumBlock(SwitchEnumInst *SEI) {
}
if (EI->hasOperand() && !LiveBlock->bbarg_empty())
SILBuilder(SEI).createBranch(SEI->getLoc(), LiveBlock,
SILBuilderWithScope<1>(SEI).createBranch(SEI->getLoc(), LiveBlock,
EI->getOperand());
else
SILBuilder(SEI).createBranch(SEI->getLoc(), LiveBlock);
SILBuilderWithScope<1>(SEI).createBranch(SEI->getLoc(), LiveBlock);
SEI->eraseFromParent();
if (EI->use_empty()) EI->eraseFromParent();
@@ -1263,7 +1267,7 @@ bool SimplifyCFG::run() {
static void
removeArgumentFromTerminator(SILBasicBlock *BB, SILBasicBlock *Dest, int idx) {
TermInst *Branch = BB->getTerminator();
SILBuilder Builder(Branch);
SILBuilderWithScope<2> Builder(Branch);
if (CondBranchInst *CBI = dyn_cast<CondBranchInst>(Branch)) {
DEBUG(llvm::dbgs() << "*** Fixing CondBranchInst.\n");
@@ -1398,7 +1402,7 @@ bool simplifySwitchEnumToSelectEnum(SILBasicBlock *BB,
// Only a single BB has a true value. We can create select_enum for this
// single case.
SILBuilder B(SWI);
SILBuilderWithScope<4> B(SWI);
auto TrueDef = B.createIntegerLiteral(SWI->getLoc(),
BoolArg->getType(),

View File

@@ -28,7 +28,7 @@ using namespace swift;
/// The argument is appended at the end of the argument tuple.
TermInst *swift::addNewEdgeValueToBranch(TermInst *Branch, SILBasicBlock *Dest,
SILValue Val) {
SILBuilder Builder(Branch);
SILBuilderWithScope<2> Builder(Branch);
TermInst *NewBr = nullptr;
if (CondBranchInst *CBI = dyn_cast<CondBranchInst>(Branch)) {
@@ -88,7 +88,7 @@ TermInst *swift::addNewEdgeValueToBranch(TermInst *Branch, SILBasicBlock *Dest,
/// specified index.
TermInst *swift::changeEdgeValue(TermInst *Branch, SILBasicBlock *Dest,
size_t Idx, SILValue Val) {
SILBuilder Builder(Branch);
SILBuilderWithScope<2> Builder(Branch);
if (CondBranchInst *CBI = dyn_cast<CondBranchInst>(Branch)) {
SmallVector<SILValue, 8> TrueArgs;
@@ -187,7 +187,7 @@ SILBasicBlock *replaceSwitchDest(SwitchEnumTy *S,
static void changeBranchTargetAndStripArgs(TermInst *T, unsigned EdgeIdx,
SILBasicBlock *NewDest) {
SILBuilder B(T);
SILBuilderWithScope<8> B(T);
if (auto Br = dyn_cast<BranchInst>(T)) {
B.createBranch(T->getLoc(), NewDest);

View File

@@ -208,7 +208,7 @@ void swift::replaceWithSpecializedFunction(ApplyInst *AI, SILFunction *NewF) {
Arguments.push_back(Op.get());
}
SILBuilder Builder(AI);
SILBuilderWithScope<2> Builder(AI);
FunctionRefInst *FRI = Builder.createFunctionRef(Loc, NewF);
ApplyInst *NAI =
@@ -262,7 +262,7 @@ void swift::placeFuncRef(ApplyInst *AI, DominanceInfo *DT) {
/// instruction.
TermInst *swift::addArgumentToBranch(SILValue Val, SILBasicBlock *Dest,
TermInst *Branch) {
SILBuilder Builder(Branch);
SILBuilderWithScope<2> Builder(Branch);
if (CondBranchInst *CBI = dyn_cast<CondBranchInst>(Branch)) {
SmallVector<SILValue, 8> TrueArgs;
@@ -474,7 +474,7 @@ ApplyInst *swift::ArraySemanticsCall::hoistOrCopy(SILInstruction *InsertBefore,
auto Self = getSelf();
// We are going to have a retain, emit a matching release.
if (!LeaveOriginal)
SILBuilder(SemanticsCall)
SILBuilderWithScope<1>(SemanticsCall)
.createReleaseValue(SemanticsCall->getLoc(), Self);
// Hoist the array load, if neccessary.
@@ -482,7 +482,8 @@ ApplyInst *swift::ArraySemanticsCall::hoistOrCopy(SILInstruction *InsertBefore,
auto NewArrayStructValue = copyArrayLoad(Self, InsertBefore, DT);
// Retain the array.
B.createRetainValue(SemanticsCall->getLoc(), NewArrayStructValue);
B.createRetainValue(SemanticsCall->getLoc(), NewArrayStructValue)
->setDebugScope(SemanticsCall->getDebugScope());
auto Call = hoistOrCopyCall(SemanticsCall, InsertBefore, LeaveOriginal, DT);
Call->setSelfArgument(NewArrayStructValue);
return Call;
@@ -504,7 +505,7 @@ ApplyInst *swift::ArraySemanticsCall::hoistOrCopy(SILInstruction *InsertBefore,
void swift::ArraySemanticsCall::replaceByRetainValue() {
assert(getKind() < ArrayCallKind::kMakeMutable &&
"Must be a semantics call that passes the array by value");
SILBuilder(SemanticsCall)
SILBuilderWithScope<1>(SemanticsCall)
.createReleaseValue(SemanticsCall->getLoc(), getSelf());
SemanticsCall->eraseFromParent();
}

View File

@@ -70,6 +70,7 @@ bool SILInliner::inlineFunction(ApplyInst *AI, ArrayRef<SILValue> Args) {
SILDebugScope(AI->getLoc(), F, AIScope);
CallSiteScope->InlinedCallSite = AIScope->InlinedCallSite;
}
assert(CallSiteScope && "call site has no scope");
// Increment the ref count for the inlined function, so it doesn't
// get deleted before we can emit abstract debug info for it.
@@ -147,7 +148,8 @@ bool SILInliner::inlineFunction(ApplyInst *AI, ArrayRef<SILValue> Args) {
// trying to clone the ReturnInst.
if (ReturnInst *RI = dyn_cast<ReturnInst>(BI->first->getTerminator())) {
getBuilder().createBranch(Loc.getValue(), ReturnToBB,
remapValue(RI->getOperand()));
remapValue(RI->getOperand()))
->setDebugScope(AIScope);
continue;
}

View File

@@ -13,8 +13,7 @@ func ifelseexpr() -> Int {
} else {
x.x--;
}
// CHECK: @swift_release {{.*}}1X{{.*}}, !dbg ![[CLEANUP:.*]]
// CHECK: ret{{.*}}, !dbg ![[RET:.*]]
// CHECK: ![[CLEANUP]] = metadata !{i32 [[@LINE+1]],
// CHECK: @swift_release {{.*}}1X{{.*}}, !dbg ![[RET:.*]]
// CHECK: ret{{.*}}, !dbg ![[RET]]
return x.x; // CHECK: ![[RET]] = metadata !{i32 [[@LINE]],
}