From e42bf07af456310df8fab0c8098ab7833b84a8e5 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Thu, 24 Nov 2016 23:29:31 -0600 Subject: [PATCH 1/6] [gardening] Always create SILBasicBlocks via SILFunction::createBasicBlock. This eliminates all inline creation of SILBasicBlock via placement new. There are a few reasons to do this: 1. A SILBasicBlock is always created with a parent function. This commit formalizes this into the SILBasicBlock API by only allowing for SILFunctions to create SILBasicBlocks. This is implemented via the type system by making all SILBasicBlock constructors private. Since SILFunction is a friend of SILBasicBlock, SILFunction can still create a SILBasicBlock without issue. 2. Since all SILBasicBlocks will be created in only a few functions, it becomes very easy to determine using instruments the amount of memory being allocated for SILBasicBlocks by simply inverting the call tree in Allocations. With LTO+PGO, normal inlining can occur if profitable so there shouldn't be overhead that we care about in shipping compilers. --- include/swift/SIL/SILBasicBlock.h | 3 ++- include/swift/SIL/SILCloner.h | 2 +- include/swift/SIL/SILFunction.h | 1 + include/swift/SILOptimizer/Utils/Local.h | 2 +- lib/Parse/ParseSIL.cpp | 10 +++++----- lib/SIL/SILBuilder.cpp | 2 +- lib/SIL/SILFunction.cpp | 4 ++++ lib/SILGen/SILGenStmt.cpp | 14 +++++++------- lib/SILOptimizer/IPO/CapturePromotion.cpp | 2 +- lib/SILOptimizer/IPO/CapturePropagation.cpp | 2 +- lib/SILOptimizer/IPO/ClosureSpecializer.cpp | 2 +- lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp | 2 +- lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp | 2 +- .../Mandatory/DefiniteInitialization.cpp | 5 ++--- lib/SILOptimizer/Transforms/AllocBoxToStack.cpp | 2 +- lib/SILOptimizer/Utils/CFG.cpp | 2 +- lib/SILOptimizer/Utils/GenericCloner.cpp | 2 +- lib/SILOptimizer/Utils/Generics.cpp | 6 +++--- lib/SILOptimizer/Utils/LoopUtils.cpp | 7 +++---- lib/Serialization/DeserializeSIL.cpp | 4 ++-- 20 files changed, 40 insertions(+), 36 deletions(-) diff --git a/include/swift/SIL/SILBasicBlock.h b/include/swift/SIL/SILBasicBlock.h index 993f80f9a76f0..560415e20b366 100644 --- a/include/swift/SIL/SILBasicBlock.h +++ b/include/swift/SIL/SILBasicBlock.h @@ -51,8 +51,9 @@ public llvm::ilist_node, public SILAllocated { void operator=(const SILBasicBlock &) = delete; void operator delete(void *Ptr, size_t) = delete; -public: SILBasicBlock(SILFunction *F, SILBasicBlock *afterBB = nullptr); + +public: ~SILBasicBlock(); /// Gets the ID (= index in the function's block list) of the block. diff --git a/include/swift/SIL/SILCloner.h b/include/swift/SIL/SILCloner.h index b8759525a839c..baaf8272afef7 100644 --- a/include/swift/SIL/SILCloner.h +++ b/include/swift/SIL/SILCloner.h @@ -397,7 +397,7 @@ SILCloner::visitSILBasicBlock(SILBasicBlock* BB) { // Only visit a successor that has not already been visited. if (BBI == BBMap.end()) { // Map the successor to a new BB. - auto MappedBB = new (F.getModule()) SILBasicBlock(&F); + auto *MappedBB = F.createBasicBlock(); BBMap.insert(std::make_pair(Succ.getBB(), MappedBB)); // Create new arguments for each of the original block's arguments. for (auto &Arg : Succ.getBB()->getBBArgs()) { diff --git a/include/swift/SIL/SILFunction.h b/include/swift/SIL/SILFunction.h index 6f7dfce47d993..fe11dc3694c77 100644 --- a/include/swift/SIL/SILFunction.h +++ b/include/swift/SIL/SILFunction.h @@ -619,6 +619,7 @@ class SILFunction const SILBasicBlock &front() const { return *begin(); } SILBasicBlock *createBasicBlock(); + SILBasicBlock *createBasicBlock(SILBasicBlock *After); /// Splice the body of \p F into this function at end. void spliceBody(SILFunction *F) { diff --git a/include/swift/SILOptimizer/Utils/Local.h b/include/swift/SILOptimizer/Utils/Local.h index 2685416b0d57f..8be33616a1f63 100644 --- a/include/swift/SILOptimizer/Utils/Local.h +++ b/include/swift/SILOptimizer/Utils/Local.h @@ -368,7 +368,7 @@ class EdgeThreadingCloner : public BaseThreadingCloner { auto *Fn = BI->getFunction(); auto *SrcBB = BI->getParent(); auto *DestBB = BI->getDestBB(); - auto *EdgeBB = new (Fn->getModule()) SILBasicBlock(Fn, SrcBB); + auto *EdgeBB = Fn->createBasicBlock(SrcBB); // Create block arguments. unsigned ArgIdx = 0; diff --git a/lib/Parse/ParseSIL.cpp b/lib/Parse/ParseSIL.cpp index 8c547b750ffe5..59480e25c8406 100644 --- a/lib/Parse/ParseSIL.cpp +++ b/lib/Parse/ParseSIL.cpp @@ -477,12 +477,12 @@ SILFunction *SILParser::getGlobalNameForReference(Identifier Name, SILBasicBlock *SILParser::getBBForDefinition(Identifier Name, SourceLoc Loc) { // If there was no name specified for this block, just create a new one. if (Name.empty()) - return new (SILMod) SILBasicBlock(F); - + return F->createBasicBlock(); + SILBasicBlock *&BB = BlocksByName[Name]; // If the block has never been named yet, just create it. if (BB == nullptr) - return BB = new (SILMod) SILBasicBlock(F); + return BB = F->createBasicBlock(); // If it already exists, it was either a forward reference or a redefinition. // If it is a forward reference, it should be in our undefined set. @@ -491,7 +491,7 @@ SILBasicBlock *SILParser::getBBForDefinition(Identifier Name, SourceLoc Loc) { // instructions after the terminator. P.diagnose(Loc, diag::sil_basicblock_redefinition, Name); HadError = true; - return new (SILMod) SILBasicBlock(F); + return F->createBasicBlock(); } // FIXME: Splice the block to the end of the function so they come out in the @@ -510,7 +510,7 @@ SILBasicBlock *SILParser::getBBForReference(Identifier Name, SourceLoc Loc) { // Otherwise, create it and remember that this is a forward reference so // that we can diagnose use without definition problems. - BB = new (SILMod) SILBasicBlock(F); + BB = F->createBasicBlock(); UndefinedBlocks[BB] = {Loc, Name}; return BB; } diff --git a/lib/SIL/SILBuilder.cpp b/lib/SIL/SILBuilder.cpp index 766abb7e20f56..6c185f44da5d6 100644 --- a/lib/SIL/SILBuilder.cpp +++ b/lib/SIL/SILBuilder.cpp @@ -138,7 +138,7 @@ void SILBuilder::emitBlock(SILBasicBlock *BB, SILLocation BranchLoc) { SILBasicBlock *SILBuilder::splitBlockForFallthrough() { // If we are concatenating, just create and return a new block. if (insertingAtEndOfBlock()) { - return new (F.getModule()) SILBasicBlock(&F, BB); + return F.createBasicBlock(BB); } // Otherwise we need to split the current block at the insertion point. diff --git a/lib/SIL/SILFunction.cpp b/lib/SIL/SILFunction.cpp index f291d0b8e68c5..e6c434acd5454 100644 --- a/lib/SIL/SILFunction.cpp +++ b/lib/SIL/SILFunction.cpp @@ -288,6 +288,10 @@ SILBasicBlock *SILFunction::createBasicBlock() { return new (getModule()) SILBasicBlock(this); } +SILBasicBlock *SILFunction::createBasicBlock(SILBasicBlock *AfterBlock) { + return new (getModule()) SILBasicBlock(this, AfterBlock); +} + //===----------------------------------------------------------------------===// // View CFG Implementation //===----------------------------------------------------------------------===// diff --git a/lib/SILGen/SILGenStmt.cpp b/lib/SILGen/SILGenStmt.cpp index 31f39463592eb..f8bc911065a89 100644 --- a/lib/SILGen/SILGenStmt.cpp +++ b/lib/SILGen/SILGenStmt.cpp @@ -34,14 +34,14 @@ static void diagnose(ASTContext &Context, SourceLoc loc, Diag diag, SILBasicBlock *SILGenFunction::createBasicBlock(SILBasicBlock *afterBB) { // Honor an explicit placement if given. if (afterBB) { - return new (F.getModule()) SILBasicBlock(&F, afterBB); + return F.createBasicBlock(afterBB); - // If we don't have a requested placement, but we do have a current - // insertion point, insert there. + // If we don't have a requested placement, but we do have a current + // insertion point, insert there. } else if (B.hasValidInsertionPoint()) { - return new (F.getModule()) SILBasicBlock(&F, B.getInsertionBB()); + return F.createBasicBlock(B.getInsertionBB()); - // Otherwise, insert at the end of the current section. + // Otherwise, insert at the end of the current section. } else { return createBasicBlock(CurFunctionSection); } @@ -55,13 +55,13 @@ SILBasicBlock *SILGenFunction::createBasicBlock(FunctionSection section) { SILBasicBlock *afterBB = (StartOfPostmatter != F.end()) ? &*std::prev(StartOfPostmatter) : nullptr; - return new (F.getModule()) SILBasicBlock(&F, afterBB); + return F.createBasicBlock(afterBB); } case FunctionSection::Postmatter: { // The end of the postmatter section is always the end of the function. // Register the new block as the start of the postmatter if needed. - SILBasicBlock *newBB = new (F.getModule()) SILBasicBlock(&F, nullptr); + SILBasicBlock *newBB = F.createBasicBlock(nullptr); if (StartOfPostmatter == F.end()) StartOfPostmatter = newBB->getIterator(); return newBB; diff --git a/lib/SILOptimizer/IPO/CapturePromotion.cpp b/lib/SILOptimizer/IPO/CapturePromotion.cpp index 4ff863cab94b9..dddeca527d879 100644 --- a/lib/SILOptimizer/IPO/CapturePromotion.cpp +++ b/lib/SILOptimizer/IPO/CapturePromotion.cpp @@ -467,7 +467,7 @@ ClosureCloner::populateCloned() { // Create arguments for the entry block SILBasicBlock *OrigEntryBB = &*Orig->begin(); - SILBasicBlock *ClonedEntryBB = new (M) SILBasicBlock(Cloned); + SILBasicBlock *ClonedEntryBB = Cloned->createBasicBlock(); unsigned ArgNo = 0; auto I = OrigEntryBB->bbarg_begin(), E = OrigEntryBB->bbarg_end(); while (I != E) { diff --git a/lib/SILOptimizer/IPO/CapturePropagation.cpp b/lib/SILOptimizer/IPO/CapturePropagation.cpp index 8c99f8bb7a127..4032d41e69bb4 100644 --- a/lib/SILOptimizer/IPO/CapturePropagation.cpp +++ b/lib/SILOptimizer/IPO/CapturePropagation.cpp @@ -165,7 +165,7 @@ void CapturePropagationCloner::cloneBlocks( // Create the entry basic block with the function arguments. SILBasicBlock *OrigEntryBB = &*OrigF->begin(); - SILBasicBlock *ClonedEntryBB = new (M) SILBasicBlock(&CloneF); + SILBasicBlock *ClonedEntryBB = CloneF.createBasicBlock(); CanSILFunctionType CloneFTy = CloneF.getLoweredFunctionType(); // Only clone the arguments that remain in the new function type. The trailing diff --git a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp index 11113745add56..ed88747a795e1 100644 --- a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp +++ b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp @@ -572,7 +572,7 @@ void ClosureSpecCloner::populateCloned() { // Create arguments for the entry block. SILBasicBlock *ClosureUserEntryBB = &*ClosureUser->begin(); - SILBasicBlock *ClonedEntryBB = new (M) SILBasicBlock(Cloned); + SILBasicBlock *ClonedEntryBB = Cloned->createBasicBlock(); // Remove the closure argument. SILArgument *ClosureArg = nullptr; diff --git a/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp b/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp index 6b378cff4e156..34668ef0f7c05 100644 --- a/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp +++ b/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp @@ -1975,7 +1975,7 @@ class RegionCloner : public SILCloner { } // Create the cloned start basic block. - auto *ClonedStartBB = new (Mod) SILBasicBlock(CurFun); + auto *ClonedStartBB = CurFun->createBasicBlock(); BBMap[StartBB] = ClonedStartBB; // Clone the arguments. diff --git a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp index 1f39f2d5b0f47..cc45ecd260aa2 100644 --- a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp +++ b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp @@ -79,7 +79,7 @@ void LoopCloner::cloneLoop() { for (auto *ExitBB : ExitBlocks) BBMap[ExitBB] = ExitBB; - auto *ClonedHeader = new (Mod) SILBasicBlock(CurFun); + auto *ClonedHeader = CurFun->createBasicBlock(); BBMap[Header] = ClonedHeader; // Clone the arguments. diff --git a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp index f5d10986e65ab..4cf6d70d2b39f 100644 --- a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp +++ b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp @@ -125,7 +125,6 @@ static void InsertCFGDiamond(SILValue Cond, SILLocation Loc, SILBuilder &B, SILBasicBlock *&FalseBB, SILBasicBlock *&ContBB) { SILBasicBlock *StartBB = B.getInsertionBB(); - SILModule &Module = StartBB->getModule(); // Start by splitting the current block. ContBB = StartBB->splitBasicBlock(B.getInsertionPoint()); @@ -136,7 +135,7 @@ static void InsertCFGDiamond(SILValue Cond, SILLocation Loc, SILBuilder &B, TrueDest = ContBB; TrueBB = nullptr; } else { - TrueDest = new (Module) SILBasicBlock(StartBB->getParent()); + TrueDest = StartBB->getParent()->createBasicBlock(); B.moveBlockTo(TrueDest, ContBB); B.setInsertionPoint(TrueDest); B.createBranch(Loc, ContBB); @@ -149,7 +148,7 @@ static void InsertCFGDiamond(SILValue Cond, SILLocation Loc, SILBuilder &B, FalseDest = ContBB; FalseBB = nullptr; } else { - FalseDest = new (Module) SILBasicBlock(StartBB->getParent()); + FalseDest = StartBB->getParent()->createBasicBlock(); B.moveBlockTo(FalseDest, ContBB); B.setInsertionPoint(FalseDest); B.createBranch(Loc, ContBB); diff --git a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp index ec5b126f7dae2..5a9554ad66640 100644 --- a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp +++ b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp @@ -589,7 +589,7 @@ PromotedParamCloner::populateCloned() { // Create arguments for the entry block SILBasicBlock *OrigEntryBB = &*Orig->begin(); - SILBasicBlock *ClonedEntryBB = new (M) SILBasicBlock(Cloned); + SILBasicBlock *ClonedEntryBB = Cloned->createBasicBlock(); unsigned ArgNo = 0; auto I = OrigEntryBB->bbarg_begin(), E = OrigEntryBB->bbarg_end(); while (I != E) { diff --git a/lib/SILOptimizer/Utils/CFG.cpp b/lib/SILOptimizer/Utils/CFG.cpp index 678c7e4fdd6e9..f9d45e4f06071 100644 --- a/lib/SILOptimizer/Utils/CFG.cpp +++ b/lib/SILOptimizer/Utils/CFG.cpp @@ -579,7 +579,7 @@ SILBasicBlock *swift::splitEdge(TermInst *T, unsigned EdgeIdx, SILBasicBlock *DestBB = T->getSuccessors()[EdgeIdx]; // Create a new basic block in the edge, and insert it after the SrcBB. - auto *EdgeBB = new (Fn->getModule()) SILBasicBlock(Fn, SrcBB); + auto *EdgeBB = Fn->createBasicBlock(SrcBB); SmallVector Args; getEdgeArgs(T, EdgeIdx, EdgeBB, Args); diff --git a/lib/SILOptimizer/Utils/GenericCloner.cpp b/lib/SILOptimizer/Utils/GenericCloner.cpp index 5ccc860a012ca..0c71e5dd00e96 100644 --- a/lib/SILOptimizer/Utils/GenericCloner.cpp +++ b/lib/SILOptimizer/Utils/GenericCloner.cpp @@ -61,7 +61,7 @@ void GenericCloner::populateCloned() { // Create arguments for the entry block. SILBasicBlock *OrigEntryBB = &*Original.begin(); - SILBasicBlock *ClonedEntryBB = new (M) SILBasicBlock(Cloned); + SILBasicBlock *ClonedEntryBB = Cloned->createBasicBlock(); getBuilder().setInsertionPoint(ClonedEntryBB); llvm::SmallVector AllocStacks; diff --git a/lib/SILOptimizer/Utils/Generics.cpp b/lib/SILOptimizer/Utils/Generics.cpp index 4728de62363c4..471e639a5692c 100644 --- a/lib/SILOptimizer/Utils/Generics.cpp +++ b/lib/SILOptimizer/Utils/Generics.cpp @@ -371,7 +371,7 @@ static SILFunction *createReabstractionThunk(const ReabstractionInfo &ReInfo, if (!Thunk->empty()) return Thunk; - SILBasicBlock *EntryBB = new (M) SILBasicBlock(Thunk); + SILBasicBlock *EntryBB = Thunk->createBasicBlock(); SILBuilder Builder(EntryBB); SILBasicBlock *SpecEntryBB = &*SpecializedFunc->begin(); CanSILFunctionType SpecType = SpecializedFunc->getLoweredFunctionType(); @@ -421,8 +421,8 @@ static SILFunction *createReabstractionThunk(const ReabstractionInfo &ReInfo, SILValue ReturnValue; if (SpecType->hasErrorResult()) { // Create the logic for calling a throwing function. - SILBasicBlock *NormalBB = new (M) SILBasicBlock(Thunk); - SILBasicBlock *ErrorBB = new (M) SILBasicBlock(Thunk); + SILBasicBlock *NormalBB = Thunk->createBasicBlock(); + SILBasicBlock *ErrorBB = Thunk->createBasicBlock(); Builder.createTryApply(Loc, FRI, SpecializedFunc->getLoweredType(), {}, Arguments, NormalBB, ErrorBB); auto *ErrorVal = new (M) SILArgument(ErrorBB, diff --git a/lib/SILOptimizer/Utils/LoopUtils.cpp b/lib/SILOptimizer/Utils/LoopUtils.cpp index 2ce00b55c1a2e..5da66ed1d006e 100644 --- a/lib/SILOptimizer/Utils/LoopUtils.cpp +++ b/lib/SILOptimizer/Utils/LoopUtils.cpp @@ -24,8 +24,8 @@ using namespace swift; static SILBasicBlock *createInitialPreheader(SILBasicBlock *Header) { - auto *Preheader = new (Header->getModule()) - SILBasicBlock(Header->getParent(), &*std::prev(Header->getIterator())); + auto *Preheader = + Header->getParent()->createBasicBlock(&*std::prev(Header->getIterator())); // Clone the arguments from header into the pre-header. llvm::SmallVector Args; @@ -116,8 +116,7 @@ static SILBasicBlock *insertBackedgeBlock(SILLoop *L, DominanceInfo *DT, } // Create and insert the new backedge block... - SILBasicBlock *BEBlock = - new (F->getModule()) SILBasicBlock(F, BackedgeBlocks.back()); + SILBasicBlock *BEBlock = F->createBasicBlock(BackedgeBlocks.back()); DEBUG(llvm::dbgs() << " Inserting unique backedge block " << *BEBlock << "\n"); diff --git a/lib/Serialization/DeserializeSIL.cpp b/lib/Serialization/DeserializeSIL.cpp index 9b125e5ed0465..24b2fcebe85cc 100644 --- a/lib/Serialization/DeserializeSIL.cpp +++ b/lib/Serialization/DeserializeSIL.cpp @@ -252,7 +252,7 @@ SILBasicBlock *SILDeserializer::getBBForDefinition(SILFunction *Fn, SILBasicBlock *&BB = BlocksByID[ID]; // If the block has never been named yet, just create it. if (BB == nullptr) - return BB = new (SILMod) SILBasicBlock(Fn, Prev); + return BB = Fn->createBasicBlock(Prev); // If it already exists, it was either a forward reference or a redefinition. // The latter should never happen. @@ -273,7 +273,7 @@ SILBasicBlock *SILDeserializer::getBBForReference(SILFunction *Fn, return BB; // Otherwise, create it and remember that this is a forward reference - BB = new (SILMod) SILBasicBlock(Fn); + BB = Fn->createBasicBlock(); UndefinedBlocks[BB] = ID; return BB; } From bf6920650ca09b2d9e1e284a24ce69dace2dda4c Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Fri, 25 Nov 2016 00:14:08 -0600 Subject: [PATCH 2/6] [gardening] Drop BB from all argument related code in SILBasicBlock. Before this commit all code relating to handling arguments in SILBasicBlock had somewhere in the name BB. This is redundant given that the class's name is already SILBasicBlock. This commit drops those names. Some examples: getBBArg() => getArgument() BBArgList => ArgumentList bbarg_begin() => args_begin() --- include/swift/SIL/SILArgument.h | 8 +- include/swift/SIL/SILBasicBlock.h | 55 +++++----- include/swift/SIL/SILCloner.h | 2 +- include/swift/SIL/SILFunction.h | 14 +-- include/swift/SIL/SILVisitor.h | 3 +- include/swift/SILOptimizer/Utils/Local.h | 19 ++-- lib/IRGen/IRGenSIL.cpp | 23 ++-- lib/SIL/SILArgument.cpp | 10 +- lib/SIL/SILBasicBlock.cpp | 27 +++-- lib/SIL/SILBuilder.cpp | 2 +- lib/SIL/SILFunction.cpp | 2 +- lib/SIL/SILPrinter.cpp | 11 +- lib/SIL/SILVerifier.cpp | 102 +++++++++--------- lib/SILGen/Condition.cpp | 2 +- lib/SILGen/SILGen.cpp | 4 +- lib/SILGen/SILGenApply.cpp | 6 +- lib/SILGen/SILGenBridging.cpp | 8 +- lib/SILGen/SILGenConvert.cpp | 4 +- lib/SILGen/SILGenEpilog.cpp | 8 +- lib/SILGen/SILGenExpr.cpp | 16 +-- lib/SILGen/SILGenForeignError.cpp | 8 +- lib/SILGen/SILGenFunction.cpp | 4 +- lib/SILGen/SILGenFunction.h | 6 +- lib/SILGen/SILGenLValue.cpp | 3 +- lib/SILGen/SILGenPattern.cpp | 7 +- lib/SILGen/SILGenPoly.cpp | 5 +- lib/SILGen/SILGenStmt.cpp | 4 +- lib/SILOptimizer/ARC/ARCRegionState.cpp | 2 +- .../ARC/GlobalARCSequenceDataflow.cpp | 2 +- lib/SILOptimizer/Analysis/EscapeAnalysis.cpp | 10 +- lib/SILOptimizer/IPO/CapturePromotion.cpp | 4 +- lib/SILOptimizer/IPO/CapturePropagation.cpp | 20 ++-- lib/SILOptimizer/IPO/ClosureSpecializer.cpp | 4 +- lib/SILOptimizer/IPO/EagerSpecializer.cpp | 10 +- lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp | 2 +- .../LoopTransforms/ArrayBoundsCheckOpts.cpp | 4 +- .../LoopTransforms/COWArrayOpt.cpp | 8 +- .../LoopTransforms/LoopRotate.cpp | 4 +- .../LoopTransforms/LoopUnroll.cpp | 4 +- .../Mandatory/DefiniteInitialization.cpp | 2 +- .../Mandatory/DiagnoseUnreachable.cpp | 11 +- .../SILCombiner/SILCombinerApplyVisitors.cpp | 8 +- .../Transforms/AllocBoxToStack.cpp | 4 +- lib/SILOptimizer/Transforms/CSE.cpp | 6 +- .../Transforms/ConditionForwarding.cpp | 12 +-- .../Transforms/DeadCodeElimination.cpp | 8 +- .../Transforms/DeadObjectElimination.cpp | 4 +- .../Transforms/DeadStoreElimination.cpp | 4 +- .../Transforms/FunctionSignatureOpts.cpp | 35 +++--- lib/SILOptimizer/Transforms/SILCodeMotion.cpp | 20 ++-- lib/SILOptimizer/Transforms/SILMem2Reg.cpp | 4 +- lib/SILOptimizer/Transforms/SimplifyCFG.cpp | 72 ++++++------- .../Transforms/SpeculativeDevirtualizer.cpp | 14 +-- .../Transforms/StackPromotion.cpp | 2 +- lib/SILOptimizer/UtilityPasses/AADumper.cpp | 2 +- .../UtilityPasses/IVInfoPrinter.cpp | 2 +- .../UtilityPasses/MemBehaviorDumper.cpp | 2 +- .../UtilityPasses/RCIdentityDumper.cpp | 2 +- lib/SILOptimizer/Utils/CFG.cpp | 43 ++++---- .../Utils/CheckedCastBrJumpThreading.cpp | 4 +- lib/SILOptimizer/Utils/Devirtualize.cpp | 17 +-- lib/SILOptimizer/Utils/GenericCloner.cpp | 2 +- lib/SILOptimizer/Utils/Generics.cpp | 11 +- lib/SILOptimizer/Utils/Local.cpp | 24 ++--- lib/SILOptimizer/Utils/LoopUtils.cpp | 9 +- lib/SILOptimizer/Utils/SILInliner.cpp | 4 +- lib/SILOptimizer/Utils/SILSSAUpdater.cpp | 15 +-- lib/Serialization/SerializeSIL.cpp | 4 +- 68 files changed, 398 insertions(+), 386 deletions(-) diff --git a/include/swift/SIL/SILArgument.h b/include/swift/SIL/SILArgument.h index fa649e9001a41..8cfd2700edb2f 100644 --- a/include/swift/SIL/SILArgument.h +++ b/include/swift/SIL/SILArgument.h @@ -119,13 +119,13 @@ class SILArgument : public ValueBase { const ValueDecl *Decl; public: SILArgument(SILBasicBlock *ParentBB, SILType Ty, const ValueDecl *D=nullptr); - SILArgument(SILBasicBlock *ParentBB, SILBasicBlock::bbarg_iterator Pos, - SILType Ty, const ValueDecl *D=nullptr); + SILArgument(SILBasicBlock *ParentBB, SILBasicBlock::arg_iterator Pos, + SILType Ty, const ValueDecl *D = nullptr); SILArgument(SILFunction::iterator ParentBB, SILType Ty, const ValueDecl *D = nullptr) : SILArgument(&*ParentBB, Ty, D) {} - SILArgument(SILFunction::iterator ParentBB, SILBasicBlock::bbarg_iterator Pos, + SILArgument(SILFunction::iterator ParentBB, SILBasicBlock::arg_iterator Pos, SILType Ty, const ValueDecl *D = nullptr) : SILArgument(&*ParentBB, Pos, Ty, D) {} @@ -149,7 +149,7 @@ class SILArgument : public ValueBase { } unsigned getIndex() const { - ArrayRef Args = getParent()->getBBArgs(); + ArrayRef Args = getParent()->getArguments(); for (unsigned i = 0, e = Args.size(); i != e; ++i) if (Args[i] == this) return i; diff --git a/include/swift/SIL/SILBasicBlock.h b/include/swift/SIL/SILBasicBlock.h index 560415e20b366..ea8fa04025af7 100644 --- a/include/swift/SIL/SILBasicBlock.h +++ b/include/swift/SIL/SILBasicBlock.h @@ -39,8 +39,8 @@ public llvm::ilist_node, public SILAllocated { /// automatically managed by the SILSuccessor class. SILSuccessor *PredList; - /// BBArgList - This is the list of basic block arguments for this block. - std::vector BBArgList; + /// This is the list of basic block arguments for this block. + std::vector ArgumentList; /// The ordered set of instructions in the SILBasicBlock. InstListType InstList; @@ -142,50 +142,51 @@ public llvm::ilist_node, public SILAllocated { // SILBasicBlock Argument List Inspection and Manipulation //===--------------------------------------------------------------------===// - using bbarg_iterator = std::vector::iterator; - using const_bbarg_iterator = std::vector::const_iterator; + using arg_iterator = std::vector::iterator; + using const_arg_iterator = std::vector::const_iterator; - bool bbarg_empty() const { return BBArgList.empty(); } - size_t bbarg_size() const { return BBArgList.size(); } - bbarg_iterator bbarg_begin() { return BBArgList.begin(); } - bbarg_iterator bbarg_end() { return BBArgList.end(); } - const_bbarg_iterator bbarg_begin() const { return BBArgList.begin(); } - const_bbarg_iterator bbarg_end() const { return BBArgList.end(); } + bool args_empty() const { return ArgumentList.empty(); } + size_t args_size() const { return ArgumentList.size(); } + arg_iterator args_begin() { return ArgumentList.begin(); } + arg_iterator args_end() { return ArgumentList.end(); } + const_arg_iterator args_begin() const { return ArgumentList.begin(); } + const_arg_iterator args_end() const { return ArgumentList.end(); } - ArrayRef getBBArgs() const { return BBArgList; } + ArrayRef getArguments() const { return ArgumentList; } - unsigned getNumBBArg() const { return BBArgList.size(); } - const SILArgument *getBBArg(unsigned i) const { return BBArgList[i]; } - SILArgument *getBBArg(unsigned i) { return BBArgList[i]; } + unsigned getNumArguments() const { return ArgumentList.size(); } + const SILArgument *getArgument(unsigned i) const { return ArgumentList[i]; } + SILArgument *getArgument(unsigned i) { return ArgumentList[i]; } /// Replace the \p{i}th BB arg with a new BBArg with SILType \p Ty and ValueDecl /// \p D. - SILArgument *replaceBBArg(unsigned i, SILType Ty, const ValueDecl *D=nullptr); + SILArgument *replaceArgument(unsigned i, SILType Ty, + const ValueDecl *D = nullptr); /// Erase a specific argument from the arg list. - void eraseBBArg(int Index); + void eraseArgument(int Index); /// Allocate a new argument of type \p Ty and append it to the argument /// list. Optionally you can pass in a value decl parameter. - SILArgument *createBBArg(SILType Ty, const ValueDecl *D=nullptr); + SILArgument *createArgument(SILType Ty, const ValueDecl *D = nullptr); /// Insert a new SILArgument with type \p Ty and \p Decl at position \p Pos. - SILArgument *insertBBArg(bbarg_iterator Pos, SILType Ty, - const ValueDecl *D=nullptr); + SILArgument *insertArgument(arg_iterator Pos, SILType Ty, + const ValueDecl *D = nullptr); - SILArgument *insertBBArg(unsigned Index, SILType Ty, - const ValueDecl *D=nullptr) { - bbarg_iterator Pos = BBArgList.begin(); + SILArgument *insertArgument(unsigned Index, SILType Ty, + const ValueDecl *D = nullptr) { + arg_iterator Pos = ArgumentList.begin(); std::advance(Pos, Index); - return insertBBArg(Pos, Ty, D); + return insertArgument(Pos, Ty, D); } /// \brief Remove all block arguments. - void dropAllBBArgs() { BBArgList.clear(); } + void dropAllArguments() { ArgumentList.clear(); } /// \brief Drops all uses that belong to this basic block. void dropAllReferences() { - dropAllBBArgs(); + dropAllArguments(); for (SILInstruction &I : *this) I.dropAllReferences(); } @@ -299,8 +300,8 @@ public llvm::ilist_node, public SILAllocated { friend class SILArgument; /// BBArgument's ctor adds it to the argument list of this block. - void insertArgument(bbarg_iterator Iter, SILArgument *Arg) { - BBArgList.insert(Iter, Arg); + void insertArgument(arg_iterator Iter, SILArgument *Arg) { + ArgumentList.insert(Iter, Arg); } }; diff --git a/include/swift/SIL/SILCloner.h b/include/swift/SIL/SILCloner.h index baaf8272afef7..0a99d7f0d1cc1 100644 --- a/include/swift/SIL/SILCloner.h +++ b/include/swift/SIL/SILCloner.h @@ -400,7 +400,7 @@ SILCloner::visitSILBasicBlock(SILBasicBlock* BB) { auto *MappedBB = F.createBasicBlock(); BBMap.insert(std::make_pair(Succ.getBB(), MappedBB)); // Create new arguments for each of the original block's arguments. - for (auto &Arg : Succ.getBB()->getBBArgs()) { + for (auto &Arg : Succ.getBB()->getArguments()) { SILValue MappedArg = new (F.getModule()) SILArgument(MappedBB, getOpType(Arg->getType())); diff --git a/include/swift/SIL/SILFunction.h b/include/swift/SIL/SILFunction.h index fe11dc3694c77..cd395f35c6b65 100644 --- a/include/swift/SIL/SILFunction.h +++ b/include/swift/SIL/SILFunction.h @@ -672,29 +672,29 @@ class SILFunction SILArgument *getArgument(unsigned i) { assert(!empty() && "Cannot get argument of a function without a body"); - return begin()->getBBArg(i); + return begin()->getArgument(i); } const SILArgument *getArgument(unsigned i) const { assert(!empty() && "Cannot get argument of a function without a body"); - return begin()->getBBArg(i); + return begin()->getArgument(i); } ArrayRef getArguments() const { assert(!empty() && "Cannot get arguments of a function without a body"); - return begin()->getBBArgs(); + return begin()->getArguments(); } ArrayRef getIndirectResults() const { assert(!empty() && "Cannot get arguments of a function without a body"); - return begin()->getBBArgs().slice(0, - getLoweredFunctionType()->getNumIndirectResults()); + return begin()->getArguments().slice( + 0, getLoweredFunctionType()->getNumIndirectResults()); } ArrayRef getArgumentsWithoutIndirectResults() const { assert(!empty() && "Cannot get arguments of a function without a body"); - return begin()->getBBArgs().slice( - getLoweredFunctionType()->getNumIndirectResults()); + return begin()->getArguments().slice( + getLoweredFunctionType()->getNumIndirectResults()); } const SILArgument *getSelfArgument() const { diff --git a/include/swift/SIL/SILVisitor.h b/include/swift/SIL/SILVisitor.h index 313ac0d032679..1e6a06e2c286f 100644 --- a/include/swift/SIL/SILVisitor.h +++ b/include/swift/SIL/SILVisitor.h @@ -68,8 +68,7 @@ class SILVisitor { } void visitBasicBlockArguments(SILBasicBlock *BB) { - for (auto argI = BB->bbarg_begin(), argEnd = BB->bbarg_end(); - argI != argEnd; + for (auto argI = BB->args_begin(), argEnd = BB->args_end(); argI != argEnd; ++argI) asImpl().visit(*argI); } diff --git a/include/swift/SILOptimizer/Utils/Local.h b/include/swift/SILOptimizer/Utils/Local.h index 8be33616a1f63..2b9cbe0d3cf6a 100644 --- a/include/swift/SILOptimizer/Utils/Local.h +++ b/include/swift/SILOptimizer/Utils/Local.h @@ -373,11 +373,12 @@ class EdgeThreadingCloner : public BaseThreadingCloner { // Create block arguments. unsigned ArgIdx = 0; for (auto Arg : BI->getArgs()) { - assert(Arg->getType() == DestBB->getBBArg(ArgIdx)->getType() && + assert(Arg->getType() == DestBB->getArgument(ArgIdx)->getType() && "Types must match"); - auto *BlockArg = EdgeBB->createBBArg(Arg->getType()); - ValueMap[DestBB->getBBArg(ArgIdx)] = SILValue(BlockArg); - AvailVals.push_back(std::make_pair(DestBB->getBBArg(ArgIdx), BlockArg)); + auto *BlockArg = EdgeBB->createArgument(Arg->getType()); + ValueMap[DestBB->getArgument(ArgIdx)] = SILValue(BlockArg); + AvailVals.push_back( + std::make_pair(DestBB->getArgument(ArgIdx), BlockArg)); ++ArgIdx; } @@ -406,18 +407,18 @@ class BasicBlockCloner : public BaseThreadingCloner { // Create a new BB that is to be used as a target // for cloning. To = From->getParent()->createBasicBlock(); - for (auto *Arg : FromBB->getBBArgs()) { - To->createBBArg(Arg->getType(), Arg->getDecl()); + for (auto *Arg : FromBB->getArguments()) { + To->createArgument(Arg->getType(), Arg->getDecl()); } } DestBB = To; // Populate the value map so that uses of the BBArgs in the SrcBB are // replaced with the BBArgs of the DestBB. - for (unsigned i = 0, e = FromBB->bbarg_size(); i != e; ++i) { - ValueMap[FromBB->getBBArg(i)] = DestBB->getBBArg(i); + for (unsigned i = 0, e = FromBB->args_size(); i != e; ++i) { + ValueMap[FromBB->getArgument(i)] = DestBB->getArgument(i); AvailVals.push_back( - std::make_pair(FromBB->getBBArg(i), DestBB->getBBArg(i))); + std::make_pair(FromBB->getArgument(i), DestBB->getArgument(i))); } } diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index bba2db10eb2f9..a40eb75699928 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -1041,7 +1041,7 @@ emitPHINodesForBBArgs(IRGenSILFunction &IGF, } } - for (SILArgument *arg : make_range(silBB->bbarg_begin(), silBB->bbarg_end())) { + for (SILArgument *arg : make_range(silBB->args_begin(), silBB->args_end())) { size_t first = phis.size(); const TypeInfo &ti = IGF.getTypeInfo(arg->getType()); @@ -1086,7 +1086,7 @@ static ArrayRef emitEntryPointIndirectReturn( IGF.IndirectReturn = retTI.getAddressForPointer(params.claimNext()); } - auto bbargs = entry->getBBArgs(); + auto bbargs = entry->getArguments(); // Map the indirect returns if present. unsigned numIndirectResults = funcTy->getNumIndirectResults(); @@ -1289,11 +1289,12 @@ static void emitEntryPointArgumentsCOrObjC(IRGenSILFunction &IGF, // Bind polymorphic arguments. This can only be done after binding // all the value parameters, and must be done even for non-polymorphic // functions because of imported Objective-C generics. - emitPolymorphicParameters(IGF, *IGF.CurSILFn, params, nullptr, - [&](unsigned paramIndex) -> llvm::Value* { - SILValue parameter = entry->getBBArgs()[paramIndex]; - return IGF.getLoweredSingletonExplosion(parameter); - }); + emitPolymorphicParameters( + IGF, *IGF.CurSILFn, params, nullptr, + [&](unsigned paramIndex) -> llvm::Value * { + SILValue parameter = entry->getArguments()[paramIndex]; + return IGF.getLoweredSingletonExplosion(parameter); + }); } /// Get metadata for the dynamic Self type if we have it. @@ -2462,7 +2463,7 @@ static llvm::BasicBlock *emitBBMapForSwitchEnum( // // FIXME: This is cheesy when the destination BB has only the switch // as a predecessor. - if (!casePair.second->bbarg_empty()) + if (!casePair.second->args_empty()) dests.push_back({casePair.first, llvm::BasicBlock::Create(IGF.IGM.getLLVMContext())}); else @@ -2490,8 +2491,8 @@ void IRGenSILFunction::visitSwitchEnumInst(SwitchEnumInst *inst) { // Bind arguments for cases that want them. for (unsigned i = 0, e = inst->getNumCases(); i < e; ++i) { auto casePair = inst->getCase(i); - - if (!casePair.second->bbarg_empty()) { + + if (!casePair.second->args_empty()) { auto waypointBB = dests[i].second; auto &destLBB = getLoweredBB(casePair.second); @@ -2858,7 +2859,7 @@ void IRGenSILFunction::visitDynamicMethodBranchInst(DynamicMethodBranchInst *i){ && "lowering dynamic_method_br with multiple preds for destination " "not implemented"); // Kill the existing lowered value for the bb arg and its phi nodes. - SILValue methodArg = i->getHasMethodBB()->bbarg_begin()[0]; + SILValue methodArg = i->getHasMethodBB()->args_begin()[0]; Explosion formerLLArg = getLoweredExplosion(methodArg); for (llvm::Value *val : formerLLArg.claimAll()) { auto phi = cast(val); diff --git a/lib/SIL/SILArgument.cpp b/lib/SIL/SILArgument.cpp index d45375d4d4788..99bf7fc012c5c 100644 --- a/lib/SIL/SILArgument.cpp +++ b/lib/SIL/SILArgument.cpp @@ -26,13 +26,13 @@ using namespace swift; SILArgument::SILArgument(SILBasicBlock *ParentBB, SILType Ty, const ValueDecl *D) : ValueBase(ValueKind::SILArgument, Ty), ParentBB(ParentBB), Decl(D) { - ParentBB->insertArgument(ParentBB->bbarg_end(), this); + ParentBB->insertArgument(ParentBB->args_end(), this); } SILArgument::SILArgument(SILBasicBlock *ParentBB, - SILBasicBlock::bbarg_iterator Pos, - SILType Ty, const ValueDecl *D) - : ValueBase(ValueKind::SILArgument, Ty), ParentBB(ParentBB), Decl(D) { + SILBasicBlock::arg_iterator Pos, SILType Ty, + const ValueDecl *D) + : ValueBase(ValueKind::SILArgument, Ty), ParentBB(ParentBB), Decl(D) { // Function arguments need to have a decl. assert( !ParentBB->getParent()->isBare() && @@ -185,5 +185,5 @@ bool SILArgument::isSelf() const { // Return true if we are the last argument of our BB and that our parent // function has a call signature with self. return getFunction()->hasSelfParam() && - getParent()->getBBArgs().back() == this; + getParent()->getArguments().back() == this; } diff --git a/lib/SIL/SILBasicBlock.cpp b/lib/SIL/SILBasicBlock.cpp index fd4509731cba3..f77ae17ba7443 100644 --- a/lib/SIL/SILBasicBlock.cpp +++ b/lib/SIL/SILBasicBlock.cpp @@ -38,7 +38,7 @@ SILBasicBlock::SILBasicBlock(SILFunction *parent, SILBasicBlock *afterBB) } SILBasicBlock::~SILBasicBlock() { // Invalidate all of the basic block arguments. - for (auto *Arg : BBArgList) { + for (auto *Arg : ArgumentList) { getModule().notifyDeleteHandlers(Arg); } @@ -105,41 +105,40 @@ void SILBasicBlock::eraseFromParent() { /// Replace the ith BB argument with a new one with type Ty (and optional /// ValueDecl D). -SILArgument *SILBasicBlock::replaceBBArg(unsigned i, SILType Ty, - const ValueDecl *D) { +SILArgument *SILBasicBlock::replaceArgument(unsigned i, SILType Ty, + const ValueDecl *D) { SILModule &M = getParent()->getModule(); - - assert(BBArgList[i]->use_empty() && "Expected no uses of the old BB arg!"); + assert(ArgumentList[i]->use_empty() && "Expected no uses of the old BB arg!"); // Notify the delete handlers that this argument is being deleted. - M.notifyDeleteHandlers(BBArgList[i]); + M.notifyDeleteHandlers(ArgumentList[i]); auto *NewArg = new (M) SILArgument(Ty, D); NewArg->setParent(this); // TODO: When we switch to malloc/free allocation we'll be leaking memory // here. - BBArgList[i] = NewArg; + ArgumentList[i] = NewArg; return NewArg; } -SILArgument *SILBasicBlock::createBBArg(SILType Ty, const ValueDecl *D) { +SILArgument *SILBasicBlock::createArgument(SILType Ty, const ValueDecl *D) { return new (getModule()) SILArgument(this, Ty, D); } -SILArgument *SILBasicBlock::insertBBArg(bbarg_iterator Iter, SILType Ty, - const ValueDecl *D) { +SILArgument *SILBasicBlock::insertArgument(arg_iterator Iter, SILType Ty, + const ValueDecl *D) { return new (getModule()) SILArgument(this, Iter, Ty, D); } -void SILBasicBlock::eraseBBArg(int Index) { - assert(getBBArg(Index)->use_empty() && +void SILBasicBlock::eraseArgument(int Index) { + assert(getArgument(Index)->use_empty() && "Erasing block argument that has uses!"); // Notify the delete handlers that this BB argument is going away. - getModule().notifyDeleteHandlers(getBBArg(Index)); - BBArgList.erase(BBArgList.begin() + Index); + getModule().notifyDeleteHandlers(getArgument(Index)); + ArgumentList.erase(ArgumentList.begin() + Index); } /// \brief Splits a basic block into two at the specified instruction. diff --git a/lib/SIL/SILBuilder.cpp b/lib/SIL/SILBuilder.cpp index 6c185f44da5d6..7213aeb8e9e99 100644 --- a/lib/SIL/SILBuilder.cpp +++ b/lib/SIL/SILBuilder.cpp @@ -118,7 +118,7 @@ void SILBuilder::emitBlock(SILBasicBlock *BB, SILLocation BranchLoc) { } // Fall though from the currently active block into the given block. - assert(BB->bbarg_empty() && "cannot fall through to bb with args"); + assert(BB->args_empty() && "cannot fall through to bb with args"); // This is a fall through into BB, emit the fall through branch. createBranch(BranchLoc, BB); diff --git a/lib/SIL/SILFunction.cpp b/lib/SIL/SILFunction.cpp index e6c434acd5454..ca3c6c5b2fd61 100644 --- a/lib/SIL/SILFunction.cpp +++ b/lib/SIL/SILFunction.cpp @@ -152,7 +152,7 @@ void SILFunction::numberValues(llvm::DenseMap &ValueToNumberMap) const { unsigned idx = 0; for (auto &BB : *this) { - for (auto I = BB.bbarg_begin(), E = BB.bbarg_end(); I != E; ++I) + for (auto I = BB.args_begin(), E = BB.args_end(); I != E; ++I) ValueToNumberMap[*I] = idx++; for (auto &I : BB) diff --git a/lib/SIL/SILPrinter.cpp b/lib/SIL/SILPrinter.cpp index 016dadd127b03..8a077fa813ddf 100644 --- a/lib/SIL/SILPrinter.cpp +++ b/lib/SIL/SILPrinter.cpp @@ -472,8 +472,8 @@ class SILPrinter : public SILVisitor { void print(const SILBasicBlock *BB) { // Output uses for BB arguments. - if (!BB->bbarg_empty()) { - for (auto I = BB->bbarg_begin(), E = BB->bbarg_end(); I != E; ++I) { + if (!BB->args_empty()) { + for (auto I = BB->args_begin(), E = BB->args_end(); I != E; ++I) { SILValue V = *I; if (V->use_empty()) continue; @@ -505,10 +505,11 @@ class SILPrinter : public SILVisitor { *this << getID(BB); - if (!BB->bbarg_empty()) { + if (!BB->args_empty()) { *this << '('; - for (auto I = BB->bbarg_begin(), E = BB->bbarg_end(); I != E; ++I) { - if (I != BB->bbarg_begin()) *this << ", "; + for (auto I = BB->args_begin(), E = BB->args_end(); I != E; ++I) { + if (I != BB->args_begin()) + *this << ", "; *this << getIDAndType(*I); } *this << ')'; diff --git a/lib/SIL/SILVerifier.cpp b/lib/SIL/SILVerifier.cpp index a4dca4f707b3d..fbd53f2ba413d 100644 --- a/lib/SIL/SILVerifier.cpp +++ b/lib/SIL/SILVerifier.cpp @@ -869,9 +869,9 @@ class SILVerifier : public SILVerifierBase { auto substTy = AI->getSubstCalleeType(); auto normalBB = AI->getNormalBB(); - require(normalBB->bbarg_size() == 1, + require(normalBB->args_size() == 1, "normal destination of try_apply must take one argument"); - requireSameType((*normalBB->bbarg_begin())->getType(), + requireSameType((*normalBB->args_begin())->getType(), substTy->getSILResult(), "normal destination of try_apply must take argument " "of normal result type"); @@ -879,9 +879,9 @@ class SILVerifier : public SILVerifierBase { auto errorBB = AI->getErrorBB(); require(substTy->hasErrorResult(), "try_apply must call function with error result"); - require(errorBB->bbarg_size() == 1, + require(errorBB->args_size() == 1, "error destination of try_apply must take one argument"); - requireSameType((*errorBB->bbarg_begin())->getType(), + requireSameType((*errorBB->args_begin())->getType(), substTy->getErrorResult().getSILType(), "error destination of try_apply must take argument " "of error result type"); @@ -2424,12 +2424,13 @@ class SILVerifier : public SILVerifierBase { CBI->getCastType()); verifyOpenedArchetype(CBI, CBI->getCastType().getSwiftRValueType()); - require(CBI->getSuccessBB()->bbarg_size() == 1, + require(CBI->getSuccessBB()->args_size() == 1, "success dest of checked_cast_br must take one argument"); - require(CBI->getSuccessBB()->bbarg_begin()[0]->getType() - == CBI->getCastType(), - "success dest block argument of checked_cast_br must match type of cast"); - require(CBI->getFailureBB()->bbarg_empty(), + require(CBI->getSuccessBB()->args_begin()[0]->getType() == + CBI->getCastType(), + "success dest block argument of checked_cast_br must match type of " + "cast"); + require(CBI->getFailureBB()->args_empty(), "failure dest of checked_cast_br must take no arguments"); } @@ -2439,9 +2440,11 @@ class SILVerifier : public SILVerifierBase { require(CCABI->getDest()->getType().isAddress(), "checked_cast_addr_br dest must be an address"); - require(CCABI->getSuccessBB()->bbarg_size() == 0, + require( + CCABI->getSuccessBB()->args_size() == 0, "success dest block of checked_cast_addr_br must not take an argument"); - require(CCABI->getFailureBB()->bbarg_size() == 0, + require( + CCABI->getFailureBB()->args_size() == 0, "failure dest block of checked_cast_addr_br must not take an argument"); } @@ -2877,12 +2880,12 @@ class SILVerifier : public SILVerifierBase { "multiple switch_value cases for same value"); cases.insert(value); - require(dest->bbarg_empty(), + require(dest->args_empty(), "switch_value case destination cannot take arguments"); } if (SVI->hasDefault()) - require(SVI->getDefaultBB()->bbarg_empty(), + require(SVI->getDefaultBB()->args_empty(), "switch_value default destination cannot take arguments"); } @@ -2966,22 +2969,22 @@ class SILVerifier : public SILVerifierBase { // The destination BB can take the argument payload, if any, as a BB // arguments, or it can ignore it and take no arguments. if (elt->hasArgumentType()) { - require(dest->getBBArgs().size() == 0 - || dest->getBBArgs().size() == 1, + require(dest->getArguments().size() == 0 || + dest->getArguments().size() == 1, "switch_enum destination for case w/ args must take 0 or 1 " "arguments"); - if (dest->getBBArgs().size() == 1) { + if (dest->getArguments().size() == 1) { SILType eltArgTy = uTy.getEnumElementType(elt, F.getModule()); - SILType bbArgTy = dest->getBBArgs()[0]->getType(); + SILType bbArgTy = dest->getArguments()[0]->getType(); require(eltArgTy == bbArgTy, "switch_enum destination bbarg must match case arg type"); - require(!dest->getBBArgs()[0]->getType().isAddress(), + require(!dest->getArguments()[0]->getType().isAddress(), "switch_enum destination bbarg type must not be an address"); } } else { - require(dest->getBBArgs().size() == 0, + require(dest->getArguments().size() == 0, "switch_enum destination for no-argument case must take no " "arguments"); } @@ -2991,7 +2994,7 @@ class SILVerifier : public SILVerifierBase { require(unswitchedElts.empty() || SOI->hasDefault(), "nonexhaustive switch_enum must have a default destination"); if (SOI->hasDefault()) - require(SOI->getDefaultBB()->bbarg_empty(), + require(SOI->getDefaultBB()->args_empty(), "switch_enum default destination must take no arguments"); } @@ -3025,7 +3028,7 @@ class SILVerifier : public SILVerifierBase { unswitchedElts.erase(elt); // The destination BB must not have BB arguments. - require(dest->getBBArgs().size() == 0, + require(dest->getArguments().size() == 0, "switch_enum_addr destination must take no BB args"); } @@ -3034,7 +3037,7 @@ class SILVerifier : public SILVerifierBase { "nonexhaustive switch_enum_addr must have a default " "destination"); if (SOI->hasDefault()) - require(SOI->getDefaultBB()->bbarg_empty(), + require(SOI->getDefaultBB()->args_empty(), "switch_enum_addr default destination must take " "no arguments"); } @@ -3050,10 +3053,10 @@ class SILVerifier : public SILVerifierBase { } void checkBranchInst(BranchInst *BI) { - require(BI->getArgs().size() == BI->getDestBB()->bbarg_size(), + require(BI->getArgs().size() == BI->getDestBB()->args_size(), "branch has wrong number of arguments for dest bb"); require(std::equal(BI->getArgs().begin(), BI->getArgs().end(), - BI->getDestBB()->bbarg_begin(), + BI->getDestBB()->args_begin(), [&](SILValue branchArg, SILArgument *bbArg) { return verifyBranchArgs(branchArg, bbArg); }), @@ -3072,24 +3075,24 @@ class SILVerifier : public SILVerifierBase { CBI->getCondition()->getType().getASTContext()), "condition of conditional branch must have Int1 type"); - require(CBI->getTrueArgs().size() == CBI->getTrueBB()->bbarg_size(), + require(CBI->getTrueArgs().size() == CBI->getTrueBB()->args_size(), "true branch has wrong number of arguments for dest bb"); require(CBI->getTrueBB() != CBI->getFalseBB(), "identical destinations"); require(std::equal(CBI->getTrueArgs().begin(), CBI->getTrueArgs().end(), - CBI->getTrueBB()->bbarg_begin(), - [&](SILValue branchArg, SILArgument *bbArg) { - return verifyBranchArgs(branchArg, bbArg); - }), + CBI->getTrueBB()->args_begin(), + [&](SILValue branchArg, SILArgument *bbArg) { + return verifyBranchArgs(branchArg, bbArg); + }), "true branch argument types do not match arguments for dest bb"); - require(CBI->getFalseArgs().size() == CBI->getFalseBB()->bbarg_size(), + require(CBI->getFalseArgs().size() == CBI->getFalseBB()->args_size(), "false branch has wrong number of arguments for dest bb"); require(std::equal(CBI->getFalseArgs().begin(), CBI->getFalseArgs().end(), - CBI->getFalseBB()->bbarg_begin(), - [&](SILValue branchArg, SILArgument *bbArg) { - return verifyBranchArgs(branchArg, bbArg); - }), + CBI->getFalseBB()->args_begin(), + [&](SILValue branchArg, SILArgument *bbArg) { + return verifyBranchArgs(branchArg, bbArg); + }), "false branch argument types do not match arguments for dest bb"); } @@ -3106,10 +3109,10 @@ class SILVerifier : public SILVerifierBase { } // Check that the branch argument is of the expected dynamic method type. - require(DMBI->getHasMethodBB()->bbarg_size() == 1, + require(DMBI->getHasMethodBB()->args_size() == 1, "true bb for dynamic_method_br must take an argument"); - - auto bbArgTy = DMBI->getHasMethodBB()->bbarg_begin()[0]->getType(); + + auto bbArgTy = DMBI->getHasMethodBB()->args_begin()[0]->getType(); require(getDynamicMethodType(operandType, DMBI->getMember()) .getSwiftRValueType() ->isBindableTo(bbArgTy.getSwiftRValueType(), nullptr), @@ -3225,20 +3228,22 @@ class SILVerifier : public SILVerifierBase { SILFunctionType *ti = F.getLoweredFunctionType(); DEBUG(llvm::dbgs() << "Argument types for entry point BB:\n"; - for (auto *arg : make_range(entry->bbarg_begin(), entry->bbarg_end())) - arg->getType().dump(); + for (auto *arg + : make_range(entry->args_begin(), entry->args_end())) + arg->getType() + .dump(); llvm::dbgs() << "Input types for SIL function type "; - ti->print(llvm::dbgs()); - llvm::dbgs() << ":\n"; - for (auto input : ti->getParameters()) - input.getSILType().dump();); + ti->print(llvm::dbgs()); llvm::dbgs() << ":\n"; + for (auto input + : ti->getParameters()) input.getSILType() + .dump();); - require(entry->bbarg_size() == - ti->getNumIndirectResults() + ti->getParameters().size(), + require(entry->args_size() == + ti->getNumIndirectResults() + ti->getParameters().size(), "entry point has wrong number of arguments"); bool matched = true; - auto argI = entry->bbarg_begin(); + auto argI = entry->args_begin(); auto check = [&](const char *what, SILType ty) { auto mappedTy = F.mapTypeIntoContext(ty); @@ -3262,9 +3267,8 @@ class SILVerifier : public SILVerifierBase { require(matched, "entry point argument types do not match function type"); // TBAA requirement for all address arguments. - require(std::equal(entry->bbarg_begin() + ti->getNumIndirectResults(), - entry->bbarg_end(), - ti->getParameters().begin(), + require(std::equal(entry->args_begin() + ti->getNumIndirectResults(), + entry->args_end(), ti->getParameters().begin(), [&](SILArgument *bbarg, SILParameterInfo paramInfo) { if (!bbarg->getType().isAddress()) return true; diff --git a/lib/SILGen/Condition.cpp b/lib/SILGen/Condition.cpp index 7c489b5036c99..d7f3f5e786dda 100644 --- a/lib/SILGen/Condition.cpp +++ b/lib/SILGen/Condition.cpp @@ -134,7 +134,7 @@ SILBasicBlock *Condition::complete(SILGenFunction &SGF) { // Kill the continuation block if it's not being used. Case-exits // only leave themselves post-terminator if they use the // continuation block, so we're in an acceptable insertion state. - if (ContBB->pred_empty() && ContBB->bbarg_empty()) { + if (ContBB->pred_empty() && ContBB->args_empty()) { SGF.eraseBasicBlock(ContBB); return SGF.B.hasValidInsertionPoint() ? SGF.B.getInsertionBB() : nullptr; } diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 60ac025798816..48940abeb19ae 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1366,7 +1366,7 @@ class SourceFileScope { auto returnBB = gen.createBasicBlock(); if (gen.B.hasValidInsertionPoint()) gen.B.createBranch(returnLoc, returnBB, returnValue); - returnValue = returnBB->createBBArg(returnType); + returnValue = returnBB->createArgument(returnType); gen.B.emitBlock(returnBB); // Emit the rethrow block. @@ -1374,7 +1374,7 @@ class SourceFileScope { FunctionSection::Postmatter); // Log the error. - SILValue error = rethrowBB->getBBArg(0); + SILValue error = rethrowBB->getArgument(0); gen.B.createBuiltin(moduleLoc, sgm.getASTContext().getIdentifier("errorInMain"), sgm.Types.getEmptyTupleType(), {}, {error}); diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index e383332f54a44..9ddec0ca9087f 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -1684,7 +1684,7 @@ SILValue SILGenFunction::emitApplyWithRethrow(SILLocation loc, { B.emitBlock(errorBB); SILValue error = - errorBB->createBBArg(silFnType->getErrorResult().getSILType()); + errorBB->createArgument(silFnType->getErrorResult().getSILType()); B.createBuiltin(loc, SGM.getASTContext().getIdentifier("willThrow"), SGM.Types.getEmptyTupleType(), {}, {error}); @@ -1695,7 +1695,7 @@ SILValue SILGenFunction::emitApplyWithRethrow(SILLocation loc, // Enter the normal path. B.emitBlock(normalBB); - return normalBB->createBBArg(resultType); + return normalBB->createArgument(resultType); } static RValue emitStringLiteral(SILGenFunction &SGF, Expr *E, StringRef Str, @@ -1839,7 +1839,7 @@ static SILValue emitRawApply(SILGenFunction &gen, // Otherwise, we need to create a try_apply. } else { SILBasicBlock *normalBB = gen.createBasicBlock(); - result = normalBB->createBBArg(resultType); + result = normalBB->createArgument(resultType); SILBasicBlock *errorBB = gen.getTryApplyErrorDest(loc, substFnType->getErrorResult(), diff --git a/lib/SILGen/SILGenBridging.cpp b/lib/SILGen/SILGenBridging.cpp index 81c5e8e592391..de25865067f7c 100644 --- a/lib/SILGen/SILGenBridging.cpp +++ b/lib/SILGen/SILGenBridging.cpp @@ -1075,8 +1075,8 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) { // Emit the non-error destination. { B.emitBlock(normalBB); - SILValue nativeResult = normalBB->createBBArg(swiftResultTy); - + SILValue nativeResult = normalBB->createArgument(swiftResultTy); + if (substTy->hasIndirectResults()) { assert(substTy->getNumAllResults() == 1); nativeResult = args[0]; @@ -1097,7 +1097,7 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) { { B.emitBlock(errorBB); SILValue nativeError = - errorBB->createBBArg(substTy->getErrorResult().getSILType()); + errorBB->createArgument(substTy->getErrorResult().getSILType()); // In this branch, the eventual return value is mostly invented. // Store the native error in the appropriate location and return. @@ -1109,7 +1109,7 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) { // Emit the join block. B.emitBlock(contBB); - result = contBB->createBBArg(objcResultTy); + result = contBB->createArgument(objcResultTy); // Leave the scope now. argScope.pop(); diff --git a/lib/SILGen/SILGenConvert.cpp b/lib/SILGen/SILGenConvert.cpp index 9bfa595ed0d8a..1b4d545aa243a 100644 --- a/lib/SILGen/SILGenConvert.cpp +++ b/lib/SILGen/SILGenConvert.cpp @@ -523,7 +523,7 @@ ManagedValue SILGenFunction::emitExistentialErasure( // layering reasons, so perform an unchecked cast down to NSError. SILType anyObjectTy = potentialNSError.getType().getAnyOptionalObjectType(); - SILValue nsError = isPresentBB->createBBArg(anyObjectTy); + SILValue nsError = isPresentBB->createArgument(anyObjectTy); nsError = B.createUncheckedRefCast(loc, nsError, getLoweredType(nsErrorType)); @@ -555,7 +555,7 @@ ManagedValue SILGenFunction::emitExistentialErasure( B.emitBlock(contBB); SILValue existentialResult = - contBB->createBBArg(existentialTL.getLoweredType()); + contBB->createArgument(existentialTL.getLoweredType()); return emitManagedRValueWithCleanup(existentialResult, existentialTL); } } diff --git a/lib/SILGen/SILGenEpilog.cpp b/lib/SILGen/SILGenEpilog.cpp index d7e669dd1943c..8decaf9b73d89 100644 --- a/lib/SILGen/SILGenEpilog.cpp +++ b/lib/SILGen/SILGenEpilog.cpp @@ -100,13 +100,13 @@ SILGenFunction::emitEpilogBB(SILLocation TopLevel) { // Steal the branch argument as the return value if present. SILBasicBlock *pred = *epilogBB->pred_begin(); BranchInst *predBranch = cast(pred->getTerminator()); - assert(predBranch->getArgs().size() == epilogBB->bbarg_size() && + assert(predBranch->getArgs().size() == epilogBB->args_size() && "epilog predecessor arguments does not match block params"); for (auto index : indices(predBranch->getArgs())) { SILValue result = predBranch->getArgs()[index]; directResults.push_back(result); - epilogBB->getBBArg(index)->replaceAllUsesWith(result); + epilogBB->getArgument(index)->replaceAllUsesWith(result); } // If we are optimizing, we should use the return location from the single, @@ -135,7 +135,7 @@ SILGenFunction::emitEpilogBB(SILLocation TopLevel) { // Emit the epilog into the epilog bb. Its arguments are the // direct results. - directResults.append(epilogBB->bbarg_begin(), epilogBB->bbarg_end()); + directResults.append(epilogBB->args_begin(), epilogBB->args_end()); // If we are falling through from the current block, the return is implicit. B.emitBlock(epilogBB, ImplicitReturnFromTopLevel); @@ -221,7 +221,7 @@ void SILGenFunction::emitRethrowEpilog(SILLocation topLevel) { } SILLocation throwLoc = topLevel; - SILValue exn = rethrowBB->bbarg_begin()[0]; + SILValue exn = rethrowBB->args_begin()[0]; bool reposition = true; // If the rethrow destination has a single branch predecessor, diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index bc7eedc3369fd..797f3a244608c 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -829,7 +829,7 @@ RValue RValueEmitter::visitForceTryExpr(ForceTryExpr *E, SGFContext C) { SavedInsertionPoint scope(SGF, catchBB, FunctionSection::Postmatter); ASTContext &ctx = SGF.getASTContext(); - auto error = catchBB->createBBArg(SILType::getExceptionType(ctx)); + auto error = catchBB->createArgument(SILType::getExceptionType(ctx)); SGF.B.createBuiltin(E, ctx.getIdentifier("unexpectedError"), SGF.SGM.Types.getEmptyTupleType(), {}, {error}); SGF.B.createUnreachable(E); @@ -913,8 +913,8 @@ RValue RValueEmitter::visitOptionalTryExpr(OptionalTryExpr *E, SGFContext C) { // result type. SGF.B.emitBlock(catchBB); FullExpr catchCleanups(SGF.Cleanups, E); - auto *errorArg = catchBB->createBBArg( - SILType::getExceptionType(SGF.getASTContext())); + auto *errorArg = + catchBB->createArgument(SILType::getExceptionType(SGF.getASTContext())); (void) SGF.emitManagedRValueWithCleanup(errorArg); catchCleanups.pop(); @@ -932,7 +932,7 @@ RValue RValueEmitter::visitOptionalTryExpr(OptionalTryExpr *E, SGFContext C) { // If this was done in SSA registers, then the value is provided as an // argument to the block. if (!isByAddress) { - auto arg = contBB->createBBArg(optTL.getLoweredType()); + auto arg = contBB->createArgument(optTL.getLoweredType()); return RValue(SGF, E, SGF.emitManagedRValueWithCleanup(arg, optTL)); } @@ -2113,7 +2113,7 @@ static ManagedValue flattenOptional(SILGenFunction &SGF, SILLocation loc, if (resultTL.isAddressOnly()) result = SGF.emitTemporaryAllocation(loc, resultTy); else - result = contBB->createBBArg(resultTy); + result = contBB->createArgument(resultTy); // Branch on whether the input is optional, this doesn't consume the value. auto isPresent = SGF.emitDoesOptionalHaveValue(loc, optVal.getValue()); @@ -2581,9 +2581,9 @@ RValue RValueEmitter::visitIfExpr(IfExpr *E, SGFContext C) { SILBasicBlock *cont = cond.complete(SGF); assert(cont && "no continuation block for if expr?!"); - - SILValue result = cont->bbarg_begin()[0]; - + + SILValue result = cont->args_begin()[0]; + return RValue(SGF, E, SGF.emitManagedRValueWithCleanup(result)); } else { // If the result is address-only, emit the result into a common stack buffer diff --git a/lib/SILGen/SILGenForeignError.cpp b/lib/SILGen/SILGenForeignError.cpp index c14f277d9a27f..0a1491cb10a83 100644 --- a/lib/SILGen/SILGenForeignError.cpp +++ b/lib/SILGen/SILGenForeignError.cpp @@ -57,7 +57,7 @@ static void emitStoreToForeignErrorSlot(SILGenFunction &gen, // If we have the slot, emit a store to it. gen.B.emitBlock(hasSlotBB); - SILValue slot = hasSlotBB->createBBArg(errorPtrObjectTy); + SILValue slot = hasSlotBB->createArgument(errorPtrObjectTy); emitStoreToForeignErrorSlot(gen, loc, slot, errorSrc); gen.B.createBranch(loc, contBB); @@ -276,7 +276,7 @@ void SILGenFunction::emitForeignErrorBlock(SILLocation loc, // If we are not provided with an errorSlot value, then we are passed the // unwrapped optional error as the argument of the errorBB. This value is // passed at +1 meaning that we still need to create a cleanup for errorV. - errorV = errorBB->getBBArg(0); + errorV = errorBB->getArgument(0); } ManagedValue error = emitManagedRValueWithCleanup(errorV); @@ -383,7 +383,7 @@ emitResultIsNilErrorCheck(SILGenFunction &gen, SILLocation loc, // In the continuation block, take ownership of the now non-optional // result value. gen.B.emitBlock(contBB); - SILValue objectResult = contBB->createBBArg(resultObjectType); + SILValue objectResult = contBB->createArgument(resultObjectType); return gen.emitManagedRValueWithCleanup(objectResult); } @@ -401,7 +401,7 @@ emitErrorIsNonNilErrorCheck(SILGenFunction &gen, SILLocation loc, // Switch on the optional error. SILBasicBlock *errorBB = gen.createBasicBlock(FunctionSection::Postmatter); - errorBB->createBBArg(optionalError->getType().unwrapAnyOptionalType()); + errorBB->createArgument(optionalError->getType().unwrapAnyOptionalType()); SILBasicBlock *contBB = gen.createBasicBlock(); gen.B.createSwitchEnum(loc, optionalError, /*default*/ nullptr, { { ctx.getOptionalSomeDecl(), errorBB }, diff --git a/lib/SILGen/SILGenFunction.cpp b/lib/SILGen/SILGenFunction.cpp index d4d731546b2e4..ec95897fc8654 100644 --- a/lib/SILGen/SILGenFunction.cpp +++ b/lib/SILGen/SILGenFunction.cpp @@ -498,8 +498,8 @@ void SILGenFunction::emitClosure(AbstractClosureExpr *ace) { void SILGenFunction::emitArtificialTopLevel(ClassDecl *mainClass) { // Load argc and argv from the entry point arguments. - SILValue argc = F.begin()->getBBArg(0); - SILValue argv = F.begin()->getBBArg(1); + SILValue argc = F.begin()->getArgument(0); + SILValue argv = F.begin()->getArgument(1); switch (mainClass->getArtificialMainKind()) { case ArtificialMainKind::UIApplicationMain: { diff --git a/lib/SILGen/SILGenFunction.h b/lib/SILGen/SILGenFunction.h index e77d4ab3fdc93..aeb92dcfb2c81 100644 --- a/lib/SILGen/SILGenFunction.h +++ b/lib/SILGen/SILGenFunction.h @@ -457,10 +457,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction /// True if 'return' without an operand or falling off the end of the current /// function is valid. - bool allowsVoidReturn() const { - return ReturnDest.getBlock()->bbarg_empty(); - } - + bool allowsVoidReturn() const { return ReturnDest.getBlock()->args_empty(); } + /// This location, when set, is used as an override location for magic /// identifier expansion (e.g. #file). This allows default argument /// expansion to report the location of the call, instead of the location diff --git a/lib/SILGen/SILGenLValue.cpp b/lib/SILGen/SILGenLValue.cpp index b00bf32569892..8f9cfdfae4cfd 100644 --- a/lib/SILGen/SILGenLValue.cpp +++ b/lib/SILGen/SILGenLValue.cpp @@ -957,8 +957,7 @@ namespace { auto rawPointerTy = SILType::getRawPointerType(ctx); // The callback is a BB argument from the switch_enum. - SILValue callback = - writebackBB->createBBArg(rawPointerTy); + SILValue callback = writebackBB->createArgument(rawPointerTy); // Cast the callback to the correct polymorphic function type. auto origCallbackFnType = gen.SGM.Types.getMaterializeForSetCallbackType( diff --git a/lib/SILGen/SILGenPattern.cpp b/lib/SILGen/SILGenPattern.cpp index 1d3fb8e6b11cc..6261ead0107d7 100644 --- a/lib/SILGen/SILGenPattern.cpp +++ b/lib/SILGen/SILGenPattern.cpp @@ -1968,7 +1968,7 @@ JumpDest PatternMatchEmission::getSharedCaseBlockDest(CaseStmt *caseBlock, pattern->forEachVariable([&](VarDecl *V) { if (!V->hasName()) return; - block->createBBArg(SGF.VarLocs[V].value->getType(), V); + block->createArgument(SGF.VarLocs[V].value->getType(), V); }); } } @@ -2024,7 +2024,7 @@ void PatternMatchEmission::emitSharedCaseBlocks() { return; if (V->isLet()) { // Just emit a let with cleanup. - SGF.VarLocs[V].value = caseBB->getBBArg(argIndex++); + SGF.VarLocs[V].value = caseBB->getArgument(argIndex++); SGF.emitInitializationForVarDecl(V)->finishInitialization(SGF); } else { // The pattern variables were all emitted as lets and one got passed in, @@ -2032,7 +2032,8 @@ void PatternMatchEmission::emitSharedCaseBlocks() { SGF.VarLocs.erase(V); auto newVar = SGF.emitInitializationForVarDecl(V); auto loc = SGF.CurrentSILLoc; - auto value = ManagedValue::forUnmanaged(caseBB->getBBArg(argIndex++)); + auto value = + ManagedValue::forUnmanaged(caseBB->getArgument(argIndex++)); auto formalType = V->getType()->getCanonicalType(); RValue(SGF, loc, formalType, value).forwardInto(SGF, loc, newVar.get()); } diff --git a/lib/SILGen/SILGenPoly.cpp b/lib/SILGen/SILGenPoly.cpp index 1ed435f7cf5e3..4ac62f0b47026 100644 --- a/lib/SILGen/SILGenPoly.cpp +++ b/lib/SILGen/SILGenPoly.cpp @@ -1388,7 +1388,7 @@ class ResultPlanner { SmallVectorImpl &innerIndirectResultAddrs) { // Assert that the indirect results are set up like we expect. assert(innerIndirectResultAddrs.empty()); - assert(Gen.F.begin()->bbarg_size() >= outerFnType->getNumIndirectResults()); + assert(Gen.F.begin()->args_size() >= outerFnType->getNumIndirectResults()); innerIndirectResultAddrs.reserve(innerFnType->getNumIndirectResults()); @@ -1494,7 +1494,8 @@ class ResultPlanner { SILValue resultAddr; if (result.isIndirect()) { - resultAddr = Gen.F.begin()->getBBArg(data.NextOuterIndirectResultIndex++); + resultAddr = + Gen.F.begin()->getArgument(data.NextOuterIndirectResultIndex++); } return { result, resultAddr }; diff --git a/lib/SILGen/SILGenStmt.cpp b/lib/SILGen/SILGenStmt.cpp index f8bc911065a89..afb2e7401ec74 100644 --- a/lib/SILGen/SILGenStmt.cpp +++ b/lib/SILGen/SILGenStmt.cpp @@ -620,7 +620,7 @@ void StmtEmitter::visitDoCatchStmt(DoCatchStmt *S) { JumpDest throwDest = createJumpDest(S->getBody(), FunctionSection::Postmatter); SILArgument *exnArg = - throwDest.getBlock()->createBBArg(exnTL.getLoweredType()); + throwDest.getBlock()->createArgument(exnTL.getLoweredType()); // We always need a continuation block because we might fall out of // a catch block. But we don't need a loop block unless the 'do' @@ -906,7 +906,7 @@ SILGenFunction::getTryApplyErrorDest(SILLocation loc, // For now, don't try to re-use destination blocks for multiple // failure sites. SILBasicBlock *destBB = createBasicBlock(FunctionSection::Postmatter); - SILValue exn = destBB->createBBArg(exnResult.getSILType()); + SILValue exn = destBB->createArgument(exnResult.getSILType()); assert(B.hasValidInsertionPoint() && B.insertingAtEndOfBlock()); SavedInsertionPoint savedIP(*this, destBB, FunctionSection::Postmatter); diff --git a/lib/SILOptimizer/ARC/ARCRegionState.cpp b/lib/SILOptimizer/ARC/ARCRegionState.cpp index 401a04d3fc84a..d45736ba6d25c 100644 --- a/lib/SILOptimizer/ARC/ARCRegionState.cpp +++ b/lib/SILOptimizer/ARC/ARCRegionState.cpp @@ -413,7 +413,7 @@ bool ARCRegionState::processBlockTopDown( // anything, we will still pair the retain, releases and then the guaranteed // parameter will ensure it is known safe to remove them. if (BB.isEntry()) { - auto Args = BB.getBBArgs(); + auto Args = BB.getArguments(); for (unsigned i = 0, e = Args.size(); i != e; ++i) { DataflowVisitor.visit(Args[i]); } diff --git a/lib/SILOptimizer/ARC/GlobalARCSequenceDataflow.cpp b/lib/SILOptimizer/ARC/GlobalARCSequenceDataflow.cpp index a0c04534e48a6..fc8a8a97545f9 100644 --- a/lib/SILOptimizer/ARC/GlobalARCSequenceDataflow.cpp +++ b/lib/SILOptimizer/ARC/GlobalARCSequenceDataflow.cpp @@ -69,7 +69,7 @@ bool ARCSequenceDataflowEvaluator::processBBTopDown(ARCBBState &BBState) { // anything, we will still pair the retain, releases and then the guaranteed // parameter will ensure it is known safe to remove them. if (BB.isEntry()) { - auto Args = BB.getBBArgs(); + auto Args = BB.getArguments(); for (unsigned i = 0, e = Args.size(); i != e; ++i) { DataflowVisitor.visit(Args[i]); } diff --git a/lib/SILOptimizer/Analysis/EscapeAnalysis.cpp b/lib/SILOptimizer/Analysis/EscapeAnalysis.cpp index 809fc452be54a..27528b56d3baa 100644 --- a/lib/SILOptimizer/Analysis/EscapeAnalysis.cpp +++ b/lib/SILOptimizer/Analysis/EscapeAnalysis.cpp @@ -386,7 +386,7 @@ void EscapeAnalysis::ConnectionGraph::propagateEscapeStates() { void EscapeAnalysis::ConnectionGraph::computeUsePoints() { // First scan the whole function and add relevant instructions as use-points. for (auto &BB : *F) { - for (SILArgument *BBArg : BB.getBBArgs()) { + for (SILArgument *BBArg : BB.getArguments()) { /// In addition to releasing instructions (see below) we also add block /// arguments as use points. In case of loops, block arguments can /// "extend" the liferange of a reference in upward direction. @@ -1083,7 +1083,7 @@ void EscapeAnalysis::buildConnectionGraph(FunctionInfo *FInfo, // Create defer-edges from the block arguments to it's values in the // predecessor's terminator instructions. - for (SILArgument *BBArg : BB.getBBArgs()) { + for (SILArgument *BBArg : BB.getArguments()) { CGNode *ArgNode = ConGraph->getNode(BBArg, this); if (!ArgNode) continue; @@ -1591,8 +1591,8 @@ bool EscapeAnalysis::deinitIsKnownToNotCapture(SILValue V) { void EscapeAnalysis::setAllEscaping(SILInstruction *I, ConnectionGraph *ConGraph) { if (auto *TAI = dyn_cast(I)) { - setEscapesGlobal(ConGraph, TAI->getNormalBB()->getBBArg(0)); - setEscapesGlobal(ConGraph, TAI->getErrorBB()->getBBArg(0)); + setEscapesGlobal(ConGraph, TAI->getNormalBB()->getArgument(0)); + setEscapesGlobal(ConGraph, TAI->getErrorBB()->getArgument(0)); } // Even if the instruction does not write memory we conservatively set all // operands to escaping, because they may "escape" to the result value in @@ -1740,7 +1740,7 @@ bool EscapeAnalysis::mergeCalleeGraph(SILInstruction *AS, if (CGNode *RetNd = CalleeGraph->getReturnNodeOrNull()) { ValueBase *CallerReturnVal = nullptr; if (auto *TAI = dyn_cast(AS)) { - CallerReturnVal = TAI->getNormalBB()->getBBArg(0); + CallerReturnVal = TAI->getNormalBB()->getArgument(0); } else { CallerReturnVal = AS; } diff --git a/lib/SILOptimizer/IPO/CapturePromotion.cpp b/lib/SILOptimizer/IPO/CapturePromotion.cpp index dddeca527d879..5139febc48e23 100644 --- a/lib/SILOptimizer/IPO/CapturePromotion.cpp +++ b/lib/SILOptimizer/IPO/CapturePromotion.cpp @@ -469,7 +469,7 @@ ClosureCloner::populateCloned() { SILBasicBlock *OrigEntryBB = &*Orig->begin(); SILBasicBlock *ClonedEntryBB = Cloned->createBasicBlock(); unsigned ArgNo = 0; - auto I = OrigEntryBB->bbarg_begin(), E = OrigEntryBB->bbarg_end(); + auto I = OrigEntryBB->args_begin(), E = OrigEntryBB->args_end(); while (I != E) { if (PromotableIndices.count(ArgNo)) { // Handle the case of a promoted capture argument. @@ -610,7 +610,7 @@ ClosureCloner::visitLoadInst(LoadInst *Inst) { static SILArgument *getBoxFromIndex(SILFunction *F, unsigned Index) { assert(F->isDefinition() && "Expected definition not external declaration!"); auto &Entry = F->front(); - return Entry.getBBArg(Index); + return Entry.getArgument(Index); } /// \brief Given a partial_apply instruction and the argument index into its diff --git a/lib/SILOptimizer/IPO/CapturePropagation.cpp b/lib/SILOptimizer/IPO/CapturePropagation.cpp index 4032d41e69bb4..934a27ebd2003 100644 --- a/lib/SILOptimizer/IPO/CapturePropagation.cpp +++ b/lib/SILOptimizer/IPO/CapturePropagation.cpp @@ -175,14 +175,14 @@ void CapturePropagationCloner::cloneBlocks( for (unsigned NewParamEnd = CloneFTy->getNumSILArguments(); ParamIdx != NewParamEnd; ++ParamIdx) { - SILArgument *Arg = OrigEntryBB->getBBArg(ParamIdx); + SILArgument *Arg = OrigEntryBB->getArgument(ParamIdx); SILValue MappedValue = new (M) SILArgument(ClonedEntryBB, remapType(Arg->getType()), Arg->getDecl()); ValueMap.insert(std::make_pair(Arg, MappedValue)); } - assert(OrigEntryBB->bbarg_size() - ParamIdx == PartialApplyArgs.size() - && "unexpected number of partial apply arguments"); + assert(OrigEntryBB->args_size() - ParamIdx == PartialApplyArgs.size() && + "unexpected number of partial apply arguments"); // Replace the rest of the old arguments with constants. BBMap.insert(std::make_pair(OrigEntryBB, ClonedEntryBB)); @@ -196,7 +196,7 @@ void CapturePropagationCloner::cloneBlocks( // The PartialApplyArg from the caller is now mapped to its cloned // instruction. Also map the original argument to the cloned instruction. - SILArgument *InArg = OrigEntryBB->getBBArg(ParamIdx); + SILArgument *InArg = OrigEntryBB->getArgument(ParamIdx); ValueMap.insert(std::make_pair(InArg, remapValue(PartialApplyArg))); ++ParamIdx; } @@ -276,7 +276,7 @@ void CapturePropagation::rewritePartialApply(PartialApplyInst *OrigPAI, /// TODO: Check for other profitable constant propagation, like builtin compare. static bool isProfitable(SILFunction *Callee) { SILBasicBlock *EntryBB = &*Callee->begin(); - for (auto *Arg : EntryBB->getBBArgs()) { + for (auto *Arg : EntryBB->getArguments()) { for (auto *Operand : Arg->getUses()) { if (auto *AI = dyn_cast(Operand->getUser())) { if (AI->getCallee() == Operand->get()) @@ -293,7 +293,7 @@ static bool onlyContainsReturnOrThrowOfArg(SILBasicBlock *BB) { for (SILInstruction &I : *BB) { if (isa(&I) || isa(&I)) { SILValue RetVal = I.getOperand(0); - if (BB->getNumBBArg() == 1 && RetVal == BB->getBBArg(0)) + if (BB->getNumArguments() == 1 && RetVal == BB->getArgument(0)) return true; return false; } @@ -308,7 +308,7 @@ static bool onlyContainsReturnOrThrowOfArg(SILBasicBlock *BB) { static SILFunction *getSpecializedWithDeadParams(SILFunction *Orig, int numDeadParams) { SILBasicBlock &EntryBB = *Orig->begin(); - unsigned NumArgs = EntryBB.getNumBBArg(); + unsigned NumArgs = EntryBB.getNumArguments(); SILModule &M = Orig->getModule(); // Check if all dead parameters have trivial types. We don't support non- @@ -316,7 +316,7 @@ static SILFunction *getSpecializedWithDeadParams(SILFunction *Orig, // those parameters (as a replacement for the removed partial_apply). // TODO: maybe we can skip this restriction when we have semantic ARC. for (unsigned Idx = NumArgs - numDeadParams; Idx < NumArgs; ++Idx) { - SILType ArgTy = EntryBB.getBBArg(Idx)->getType(); + SILType ArgTy = EntryBB.getArgument(Idx)->getType(); if (!ArgTy.isTrivial(M)) return nullptr; } @@ -342,11 +342,11 @@ static SILFunction *getSpecializedWithDeadParams(SILFunction *Orig, // Check if parameters are passes 1-to-1 unsigned NumArgs = FAS.getNumArguments(); - if (EntryBB.getNumBBArg() - numDeadParams != NumArgs) + if (EntryBB.getNumArguments() - numDeadParams != NumArgs) return nullptr; for (unsigned Idx = 0; Idx < NumArgs; ++Idx) { - if (FAS.getArgument(Idx) != (ValueBase *)EntryBB.getBBArg(Idx)) + if (FAS.getArgument(Idx) != (ValueBase *)EntryBB.getArgument(Idx)) return nullptr; } diff --git a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp index ed88747a795e1..917b7493e0dad 100644 --- a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp +++ b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp @@ -576,8 +576,8 @@ void ClosureSpecCloner::populateCloned() { // Remove the closure argument. SILArgument *ClosureArg = nullptr; - for (size_t i = 0, e = ClosureUserEntryBB->bbarg_size(); i != e; ++i) { - SILArgument *Arg = ClosureUserEntryBB->getBBArg(i); + for (size_t i = 0, e = ClosureUserEntryBB->args_size(); i != e; ++i) { + SILArgument *Arg = ClosureUserEntryBB->getArgument(i); if (i == CallSiteDesc.getClosureIndex()) { ClosureArg = Arg; continue; diff --git a/lib/SILOptimizer/IPO/EagerSpecializer.cpp b/lib/SILOptimizer/IPO/EagerSpecializer.cpp index c0948b635d8d0..19d9284695d8e 100644 --- a/lib/SILOptimizer/IPO/EagerSpecializer.cpp +++ b/lib/SILOptimizer/IPO/EagerSpecializer.cpp @@ -68,10 +68,10 @@ static bool isTrivialReturnBlock(SILBasicBlock *RetBB) { if (&*RetBB->begin() != RetInst) return false; - if (RetBB->bbarg_size() != 1) + if (RetBB->args_size() != 1) return false; - return (RetOperand == RetBB->getBBArg(0)); + return (RetOperand == RetBB->getArgument(0)); } /// Adds a CFG edge from the unterminated NewRetBB to a merged "return" or @@ -113,7 +113,7 @@ static void addReturnValueImpl(SILBasicBlock *RetBB, SILBasicBlock *NewRetBB, // Forward the existing return argument to a new BBArg. MergedBB = RetBB->splitBasicBlock(RetInst->getIterator()); SILValue OldRetVal = RetInst->getOperand(0); - RetInst->setOperand(0, MergedBB->createBBArg(OldRetVal->getType())); + RetInst->setOperand(0, MergedBB->createArgument(OldRetVal->getType())); Builder.setInsertionPoint(RetBB); Builder.createBranch(Loc, MergedBB, {OldRetVal}); } @@ -165,7 +165,7 @@ emitApplyWithRethrow(SILBuilder &Builder, // Emit the rethrow logic. Builder.emitBlock(ErrorBB); SILValue Error = - ErrorBB->createBBArg(CanSILFuncTy->getErrorResult().getSILType()); + ErrorBB->createArgument(CanSILFuncTy->getErrorResult().getSILType()); Builder.createBuiltin(Loc, Builder.getASTContext().getIdentifier("willThrow"), @@ -180,7 +180,7 @@ emitApplyWithRethrow(SILBuilder &Builder, // result value. Builder.clearInsertionPoint(); Builder.emitBlock(NormalBB); - return Builder.getInsertionBB()->createBBArg(CanSILFuncTy->getSILResult()); + return Builder.getInsertionBB()->createArgument(CanSILFuncTy->getSILResult()); } /// Emits code to invoke the specified nonpolymorphic CalleeFunc using the diff --git a/lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp b/lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp index 6de6fad5d4dee..c66488e41dec5 100644 --- a/lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp +++ b/lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp @@ -396,7 +396,7 @@ void GlobalPropertyOpt::scanInstructions() { // Add dependencies from predecessor's terminator operands to the block // arguments. int argIdx = 0; - for (auto *BBArg : BB.getBBArgs()) { + for (auto *BBArg : BB.getArguments()) { bool hasPreds = false; SILType Type = BBArg->getType(); if (isArrayType(Type) || isTupleWithArray(Type.getSwiftRValueType())) { diff --git a/lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp b/lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp index 6811681d0bba4..d0fe30d597bfe 100644 --- a/lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp +++ b/lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp @@ -790,7 +790,7 @@ class InductionAnalysis { bool analyze() { bool FoundIndVar = false; - for (auto *Arg : Header->getBBArgs()) { + for (auto *Arg : Header->getArguments()) { // Look for induction variables. IVInfo::IVDesc IV; if (!(IV = IVs.getInductionDesc(Arg))) { @@ -1208,7 +1208,7 @@ static bool hoistBoundsChecks(SILLoop *Loop, DominanceInfo *DT, SILLoopInfo *LI, if (IVarsFound) { SILValue TrueVal; SILValue FalseVal; - for (auto *Arg: Header->getBBArgs()) { + for (auto *Arg : Header->getArguments()) { if (auto *IV = IndVars[Arg]) { SILBuilderWithScope B(Preheader->getTerminator(), IV->getInstruction()); diff --git a/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp b/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp index 34668ef0f7c05..59223b0383376 100644 --- a/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp +++ b/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp @@ -427,7 +427,7 @@ bool COWArrayOpt::checkUniqueArrayContainer(SILValue ArrayContainer) { // Check that the argument is passed as an inout type. This means there are // no aliases accessible within this function scope. auto Params = Function->getLoweredFunctionType()->getParameters(); - ArrayRef FunctionArgs = Function->begin()->getBBArgs(); + ArrayRef FunctionArgs = Function->begin()->getArguments(); for (unsigned ArgIdx = 0, ArgEnd = Params.size(); ArgIdx != ArgEnd; ++ArgIdx) { if (FunctionArgs[ArgIdx] != Arg) @@ -1819,7 +1819,7 @@ class ArrayPropertiesAnalysis { // Check that the argument is passed as an inout or by value type. This // means there are no aliases accessible within this function scope. auto Params = Fun->getLoweredFunctionType()->getParameters(); - ArrayRef FunctionArgs = Fun->begin()->getBBArgs(); + ArrayRef FunctionArgs = Fun->begin()->getArguments(); for (unsigned ArgIdx = 0, ArgEnd = Params.size(); ArgIdx != ArgEnd; ++ArgIdx) { if (FunctionArgs[ArgIdx] != Arg) @@ -1979,7 +1979,7 @@ class RegionCloner : public SILCloner { BBMap[StartBB] = ClonedStartBB; // Clone the arguments. - for (auto &Arg : StartBB->getBBArgs()) { + for (auto &Arg : StartBB->getArguments()) { SILValue MappedArg = new (Mod) SILArgument(ClonedStartBB, getOpType(Arg->getType())); ValueMap.insert(std::make_pair(Arg, MappedArg)); @@ -2091,7 +2091,7 @@ class RegionCloner : public SILCloner { auto *OrigBB = Entry.first; // Update outside used phi values. - for (auto *Arg : OrigBB->getBBArgs()) + for (auto *Arg : OrigBB->getArguments()) updateSSAForValue(OrigBB, Arg, SSAUp); // Update outside used instruction values. diff --git a/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp b/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp index 691512d364f7e..fa4ca54116626 100644 --- a/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp +++ b/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp @@ -169,7 +169,7 @@ rewriteNewLoopEntryCheckBlock(SILBasicBlock *Header, SILSSAUpdater Updater(&InsertedPHIs); // Fix PHIs (incoming arguments). - for (auto *Inst: Header->getBBArgs()) + for (auto *Inst : Header->getArguments()) updateSSAForUseOfInst(Updater, InsertedPHIs, ValueMap, Header, EntryCheckBlock, Inst); @@ -331,7 +331,7 @@ bool swift::rotateLoop(SILLoop *L, DominanceInfo *DT, SILLoopInfo *LI, // The original 'phi' argument values are just the values coming from the // preheader edge. - ArrayRef PHIs = Header->getBBArgs(); + ArrayRef PHIs = Header->getArguments(); OperandValueArrayRef PreheaderArgs = cast(Preheader->getTerminator())->getArgs(); assert(PHIs.size() == PreheaderArgs.size() && diff --git a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp index cc45ecd260aa2..aa88ed94287a8 100644 --- a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp +++ b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp @@ -83,7 +83,7 @@ void LoopCloner::cloneLoop() { BBMap[Header] = ClonedHeader; // Clone the arguments. - for (auto *Arg : Header->getBBArgs()) { + for (auto *Arg : Header->getArguments()) { SILValue MappedArg = new (Mod) SILArgument(ClonedHeader, getOpType(Arg->getType())); ValueMap.insert(std::make_pair(Arg, MappedArg)); @@ -271,7 +271,7 @@ static void collectLoopLiveOutValues( DenseMap &ClonedInstructions) { for (auto *Block : Loop->getBlocks()) { // Look at block arguments. - for (auto *Arg : Block->getBBArgs()) { + for (auto *Arg : Block->getArguments()) { for (auto *Op : Arg->getUses()) { // Is this use outside the loop? if (!Loop->contains(Op->getUser())) { diff --git a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp index 4cf6d70d2b39f..ec697201749fc 100644 --- a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp +++ b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp @@ -1223,7 +1223,7 @@ static bool isFailableInitReturnUseOfEnum(EnumInst *EI) { auto *BI = dyn_cast(EI->use_begin()->getUser()); if (!BI || BI->getNumArgs() != 1) return false; - auto *TargetArg = BI->getDestBB()->getBBArg(0); + auto *TargetArg = BI->getDestBB()->getArgument(0); if (!TargetArg->hasOneUse()) return false; return isa(TargetArg->use_begin()->getUser()); } diff --git a/lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp b/lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp index f395a7c019952..ebfe1ad9e2d0c 100644 --- a/lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp +++ b/lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp @@ -109,7 +109,7 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) { // use(%2 : $Builtin.Int1) // If there are no predecessors or no arguments, there is nothing to do. - if (BB.pred_empty() || BB.bbarg_empty()) + if (BB.pred_empty() || BB.args_empty()) return; // Check if all the predecessors supply the same arguments to the BB. @@ -163,9 +163,8 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) { // Drop the parameters from basic blocks and replace all uses with the passed // in arguments. unsigned Idx = 0; - for (SILBasicBlock::bbarg_iterator AI = BB.bbarg_begin(), - AE = BB.bbarg_end(); - AI != AE; ++AI, ++Idx) { + for (SILBasicBlock::arg_iterator AI = BB.args_begin(), AE = BB.args_end(); + AI != AE; ++AI, ++Idx) { // FIXME: These could be further propagatable now, we might want to move // this to CCP and trigger another round of copy propagation. SILArgument *Arg = *AI; @@ -176,7 +175,7 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) { } // Remove args from the block. - BB.dropAllBBArgs(); + BB.dropAllArguments(); // The old branch instructions are no longer used, erase them. recursivelyDeleteTriviallyDeadInstructions(ToBeDeleted, true); @@ -282,7 +281,7 @@ static bool constantFoldTerminator(SILBasicBlock &BB, // Replace the switch with a branch to the TheSuccessorBlock. SILBuilderWithScope B(&BB, TI); SILLocation Loc = TI->getLoc(); - if (!TheSuccessorBlock->bbarg_empty()) { + if (!TheSuccessorBlock->args_empty()) { assert(TheEnum->hasOperand()); B.createBranch(Loc, TheSuccessorBlock, TheEnum->getOperand()); } else diff --git a/lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp b/lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp index de40e0c0ae6c1..c08fdf845e023 100644 --- a/lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp +++ b/lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp @@ -1211,9 +1211,9 @@ isTryApplyResultNotUsed(UserListTy &AcceptedUses, TryApplyInst *TAI) { } // Check if the normal and error results only have ARC operations as uses. - if (!recursivelyCollectARCUsers(AcceptedUses, NormalBB->getBBArg(0))) + if (!recursivelyCollectARCUsers(AcceptedUses, NormalBB->getArgument(0))) return false; - if (!recursivelyCollectARCUsers(AcceptedUses, ErrorBB->getBBArg(0))) + if (!recursivelyCollectARCUsers(AcceptedUses, ErrorBB->getArgument(0))) return false; SmallPtrSet UsesSet; @@ -1261,8 +1261,8 @@ SILInstruction *SILCombiner::visitTryApplyInst(TryApplyInst *AI) { SILType::getBuiltinIntegerType(1, Builder.getASTContext()), 0); Builder.createCondBranch(Loc, TrueLit, NormalBB, ErrorBB); - NormalBB->eraseBBArg(0); - ErrorBB->eraseBBArg(0); + NormalBB->eraseArgument(0); + ErrorBB->eraseArgument(0); return nullptr; } // We found a user that we can't handle. diff --git a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp index 5a9554ad66640..ace01dc1206bd 100644 --- a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp +++ b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp @@ -272,7 +272,7 @@ static SILArgument *getParameterForOperand(SILFunction *F, Operand *O) { auto &Entry = F->front(); size_t ParamIndex = getParameterIndexForOperand(O); - return Entry.getBBArg(ParamIndex); + return Entry.getArgument(ParamIndex); } /// Return a pointer to the SILFunction called by Call if we can @@ -591,7 +591,7 @@ PromotedParamCloner::populateCloned() { SILBasicBlock *OrigEntryBB = &*Orig->begin(); SILBasicBlock *ClonedEntryBB = Cloned->createBasicBlock(); unsigned ArgNo = 0; - auto I = OrigEntryBB->bbarg_begin(), E = OrigEntryBB->bbarg_end(); + auto I = OrigEntryBB->args_begin(), E = OrigEntryBB->args_end(); while (I != E) { if (count(PromotedParamIndices, ArgNo)) { // Create a new argument with the promoted type. diff --git a/lib/SILOptimizer/Transforms/CSE.cpp b/lib/SILOptimizer/Transforms/CSE.cpp index adf2891bae12a..58d94114b9d19 100644 --- a/lib/SILOptimizer/Transforms/CSE.cpp +++ b/lib/SILOptimizer/Transforms/CSE.cpp @@ -601,7 +601,7 @@ namespace { static void updateBasicBlockArgTypes(SILBasicBlock *BB, TypeSubstitutionMap &TypeSubstMap) { // Check types of all BB arguments. - for (auto &Arg : BB->getBBArgs()) { + for (auto &Arg : BB->getArguments()) { if (!Arg->getType().getSwiftRValueType()->hasOpenedExistential()) continue; // Type of this BB argument uses an opened existential. @@ -623,7 +623,7 @@ static void updateBasicBlockArgTypes(SILBasicBlock *BB, // Then replace all uses by an undef. Arg->replaceAllUsesWith(SILUndef::get(Arg->getType(), BB->getModule())); // Replace the type of the BB argument. - BB->replaceBBArg(Arg->getIndex(), NewArgType, Arg->getDecl()); + BB->replaceArgument(Arg->getIndex(), NewArgType, Arg->getDecl()); // Restore all uses to refer to the BB argument with updated type. for (auto ArgUse : OriginalArgUses) { ArgUse->set(Arg); @@ -667,7 +667,7 @@ bool CSE::processOpenExistentialRef(SILInstruction *Inst, ValueBase *V, // those uses by the new opened archetype. auto Successors = User->getParent()->getSuccessorBlocks(); for (auto Successor : Successors) { - if (Successor->bbarg_empty()) + if (Successor->args_empty()) continue; // If a BB has any arguments, update their types if necessary. updateBasicBlockArgTypes(Successor, TypeSubstMap); diff --git a/lib/SILOptimizer/Transforms/ConditionForwarding.cpp b/lib/SILOptimizer/Transforms/ConditionForwarding.cpp index b89d395a9551b..1b5b132f2c4f3 100644 --- a/lib/SILOptimizer/Transforms/ConditionForwarding.cpp +++ b/lib/SILOptimizer/Transforms/ConditionForwarding.cpp @@ -173,7 +173,7 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) { // No other values, beside the Enum, should be passed from the condition's // destinations to the merging block. SILBasicBlock *BB = Arg->getParent(); - if (BB->getNumBBArg() != 1) + if (BB->getNumArguments() != 1) return false; llvm::SmallVector PredBlocks; @@ -242,11 +242,11 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) { SILArgument *NewArg = nullptr; if (NeedEnumArg.insert(UseBlock).second) { // The first Enum use in this UseBlock. - NewArg = UseBlock->createBBArg(Arg->getType()); + NewArg = UseBlock->createArgument(Arg->getType()); } else { // We already inserted the Enum argument for this UseBlock. - assert(UseBlock->getNumBBArg() >= 1); - NewArg = UseBlock->getBBArg(UseBlock->getNumBBArg() - 1); + assert(UseBlock->getNumArguments() >= 1); + NewArg = UseBlock->getArgument(UseBlock->getNumArguments() - 1); } ArgUse->set(NewArg); continue; @@ -267,7 +267,7 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) { SILBuilder B(BI); llvm::SmallVector BranchArgs; unsigned HasEnumArg = NeedEnumArg.count(SEDest); - if (SEDest->getNumBBArg() == 1 + HasEnumArg) { + if (SEDest->getNumArguments() == 1 + HasEnumArg) { // The successor block has an original argument, which is the Enum's // payload. BranchArgs.push_back(EI->getOperand()); @@ -286,7 +286,7 @@ bool ConditionForwarding::tryOptimize(SwitchEnumInst *SEI) { B.createBranch(Condition->getLoc(), BB); Condition->moveBefore(SEI); SEI->eraseFromParent(); - BB->eraseBBArg(0); + BB->eraseArgument(0); return true; } diff --git a/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp b/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp index 1643c75ffa9b2..3a7516e795d77 100644 --- a/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp +++ b/lib/SILOptimizer/Transforms/DeadCodeElimination.cpp @@ -430,10 +430,10 @@ void DCE::replaceBranchWithJump(SILInstruction *Inst, SILBasicBlock *Block) { "Unexpected dead terminator kind!"); SILInstruction *Branch; - if (!Block->bbarg_empty()) { + if (!Block->args_empty()) { std::vector Args; - auto E = Block->bbarg_end(); - for (auto A = Block->bbarg_begin(); A != E; ++A) { + auto E = Block->args_end(); + for (auto A = Block->args_begin(); A != E; ++A) { assert(!LiveValues.count(*A) && "Unexpected live block argument!"); Args.push_back(SILUndef::get((*A)->getType(), (*A)->getModule())); } @@ -452,7 +452,7 @@ bool DCE::removeDead(SILFunction &F) { bool Changed = false; for (auto &BB : F) { - for (auto I = BB.bbarg_begin(), E = BB.bbarg_end(); I != E; ) { + for (auto I = BB.args_begin(), E = BB.args_end(); I != E;) { auto Inst = *I++; if (LiveValues.count(Inst)) continue; diff --git a/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp b/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp index 4f3904de38a6e..04f029e123d30 100644 --- a/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp +++ b/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp @@ -101,9 +101,9 @@ static bool doesDestructorHaveSideEffects(AllocRefInst *ARI) { return true; // A destructor only has one argument, self. - assert(Fn->begin()->getNumBBArg() == 1 && + assert(Fn->begin()->getNumArguments() == 1 && "Destructor should have only one argument, self."); - SILArgument *Self = Fn->begin()->getBBArg(0); + SILArgument *Self = Fn->begin()->getArgument(0); DEBUG(llvm::dbgs() << " Analyzing destructor.\n"); diff --git a/lib/SILOptimizer/Transforms/DeadStoreElimination.cpp b/lib/SILOptimizer/Transforms/DeadStoreElimination.cpp index 1216310c9723a..ca4e35dc2664a 100644 --- a/lib/SILOptimizer/Transforms/DeadStoreElimination.cpp +++ b/lib/SILOptimizer/Transforms/DeadStoreElimination.cpp @@ -590,7 +590,7 @@ void DSEContext::processBasicBlockForGenKillSet(SILBasicBlock *BB) { } // Handle SILArgument for base invalidation. - ArrayRef Args = BB->getBBArgs(); + ArrayRef Args = BB->getArguments(); for (auto &X : Args) { invalidateBase(X, BBState, DSEKind::BuildGenKillSet); } @@ -633,7 +633,7 @@ void DSEContext::processBasicBlockForDSE(SILBasicBlock *BB, bool Optimistic) { } // Handle SILArgument for base invalidation. - ArrayRef Args = BB->getBBArgs(); + ArrayRef Args = BB->getArguments(); for (auto &X : Args) { invalidateBase(X, S, DSEKind::BuildGenKillSet); } diff --git a/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp b/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp index 7f463b5235a90..b4074900f0e8f 100644 --- a/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp +++ b/lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp @@ -209,13 +209,13 @@ class FunctionSignatureTransform { if (AD.Explode) { llvm::SmallVector LeafValues; AD.ProjTree.createTreeFromValue(Builder, BB->getParent()->getLocation(), - BB->getBBArg(AD.Index), LeafValues); + BB->getArgument(AD.Index), LeafValues); NewArgs.append(LeafValues.begin(), LeafValues.end()); return; } // All other arguments get pushed as what they are. - NewArgs.push_back(BB->getBBArg(AD.Index)); + NewArgs.push_back(BB->getArgument(AD.Index)); } /// Take ArgumentDescList and ResultDescList and create an optimized function @@ -503,7 +503,7 @@ void FunctionSignatureTransform::createFunctionSignatureOptimizedFunction() { F->setInlineStrategy(AlwaysInline); SILBasicBlock *ThunkBody = F->createBasicBlock(); for (auto &ArgDesc : ArgumentDescList) { - ThunkBody->createBBArg(ArgDesc.Arg->getType(), ArgDesc.Decl); + ThunkBody->createArgument(ArgDesc.Arg->getType(), ArgDesc.Decl); } SILLocation Loc = ThunkBody->getParent()->getLocation(); @@ -528,11 +528,11 @@ void FunctionSignatureTransform::createFunctionSignatureOptimizedFunction() { // We need a try_apply to call a function with an error result. SILFunction *Thunk = ThunkBody->getParent(); SILBasicBlock *NormalBlock = Thunk->createBasicBlock(); - ReturnValue = NormalBlock->createBBArg(ResultType, 0); + ReturnValue = NormalBlock->createArgument(ResultType, 0); SILBasicBlock *ErrorBlock = Thunk->createBasicBlock(); SILType Error = SILType::getPrimitiveObjectType(FunctionTy->getErrorResult().getType()); - auto *ErrorArg = ErrorBlock->createBBArg(Error, 0); + auto *ErrorArg = ErrorBlock->createArgument(Error, 0); Builder.createTryApply(Loc, FRI, LoweredType, ArrayRef(), ThunkArgs, NormalBlock, ErrorBlock); @@ -563,7 +563,7 @@ void FunctionSignatureTransform::createFunctionSignatureOptimizedFunction() { bool FunctionSignatureTransform::DeadArgumentAnalyzeParameters() { // Did we decide we should optimize any parameter? bool SignatureOptimize = false; - ArrayRef Args = F->begin()->getBBArgs(); + ArrayRef Args = F->begin()->getArguments(); // Analyze the argument information. for (unsigned i = 0, e = Args.size(); i != e; ++i) { @@ -588,7 +588,7 @@ void FunctionSignatureTransform::DeadArgumentTransformFunction() { for (const ArgumentDescriptor &AD : ArgumentDescList) { if (!AD.IsEntirelyDead) continue; - eraseUsesOfValue(BB->getBBArg(AD.Index)); + eraseUsesOfValue(BB->getArgument(AD.Index)); } } @@ -598,7 +598,7 @@ void FunctionSignatureTransform::DeadArgumentFinalizeOptimizedFunction() { for (const ArgumentDescriptor &AD : reverse(ArgumentDescList)) { if (!AD.IsEntirelyDead) continue; - BB->eraseBBArg(AD.Arg->getIndex()); + BB->eraseArgument(AD.Arg->getIndex()); } } @@ -606,7 +606,7 @@ void FunctionSignatureTransform::DeadArgumentFinalizeOptimizedFunction() { /// Owned to Guaranteed transformation. /// /// ----------------------------------------------------------/// bool FunctionSignatureTransform::OwnedToGuaranteedAnalyzeParameters() { - ArrayRef Args = F->begin()->getBBArgs(); + ArrayRef Args = F->begin()->getArguments(); // A map from consumed SILArguments to the release associated with an // argument. // @@ -773,7 +773,7 @@ OwnedToGuaranteedAddResultRelease(ResultDescriptor &RD, SILBuilder &Builder, SILBasicBlock *NormalBB = dyn_cast(Call)->getNormalBB(); Builder.setInsertionPoint(&*NormalBB->begin()); Builder.createRetainValue(RegularLocation(SourceLoc()), - NormalBB->getBBArg(0), Atomicity::Atomic); + NormalBB->getArgument(0), Atomicity::Atomic); } } @@ -783,7 +783,7 @@ OwnedToGuaranteedAddResultRelease(ResultDescriptor &RD, SILBuilder &Builder, bool FunctionSignatureTransform::ArgumentExplosionAnalyzeParameters() { // Did we decide we should optimize any parameter? bool SignatureOptimize = false; - ArrayRef Args = F->begin()->getBBArgs(); + ArrayRef Args = F->begin()->getArguments(); ConsumedArgToEpilogueReleaseMatcher ArgToReturnReleaseMap(RCIA->get(F), F); // Analyze the argument information. @@ -830,8 +830,9 @@ void FunctionSignatureTransform::ArgumentExplosionFinalizeOptimizedFunction() { llvm::SmallVector LeafNodes; AD.ProjTree.getLeafNodes(LeafNodes); for (auto Node : LeafNodes) { - LeafValues.push_back(BB->insertBBArg(ArgOffset++, Node->getType(), - BB->getBBArg(OldArgIndex)->getDecl())); + LeafValues.push_back( + BB->insertArgument(ArgOffset++, Node->getType(), + BB->getArgument(OldArgIndex)->getDecl())); AIM[TotalArgIndex - 1] = AD.Index; TotalArgIndex ++; } @@ -849,12 +850,12 @@ void FunctionSignatureTransform::ArgumentExplosionFinalizeOptimizedFunction() { LeafValues); // Replace all uses of the original arg with the new value. - SILArgument *OrigArg = BB->getBBArg(OldArgIndex); + SILArgument *OrigArg = BB->getArgument(OldArgIndex); OrigArg->replaceAllUsesWith(NewOrigArgValue); // Now erase the old argument since it does not have any uses. We also // decrement ArgOffset since we have one less argument now. - BB->eraseBBArg(OldArgIndex); + BB->eraseArgument(OldArgIndex); TotalArgIndex --; } } @@ -911,7 +912,7 @@ class FunctionSignatureOpts : public SILFunctionTransform { /// Keep a map between the exploded argument index and the original argument /// index. llvm::SmallDenseMap AIM; - int asize = F->begin()->getBBArgs().size(); + int asize = F->begin()->getArguments().size(); for (auto i = 0; i < asize; ++i) { AIM[i] = i; } @@ -919,7 +920,7 @@ class FunctionSignatureOpts : public SILFunctionTransform { // Allocate the argument and result descriptors. llvm::SmallVector ArgumentDescList; llvm::SmallVector ResultDescList; - ArrayRef Args = F->begin()->getBBArgs(); + ArrayRef Args = F->begin()->getArguments(); for (unsigned i = 0, e = Args.size(); i != e; ++i) { ArgumentDescList.emplace_back(Args[i]); } diff --git a/lib/SILOptimizer/Transforms/SILCodeMotion.cpp b/lib/SILOptimizer/Transforms/SILCodeMotion.cpp index e6e15e9f77486..ce4fa57c1d80f 100644 --- a/lib/SILOptimizer/Transforms/SILCodeMotion.cpp +++ b/lib/SILOptimizer/Transforms/SILCodeMotion.cpp @@ -370,7 +370,7 @@ SILValue getArgForBlock(SILBasicBlock *From, SILBasicBlock *To, // Try to sink values from the Nth argument \p ArgNum. static bool sinkLiteralArguments(SILBasicBlock *BB, unsigned ArgNum) { - assert(ArgNum < BB->getNumBBArg() && "Invalid argument"); + assert(ArgNum < BB->getNumArguments() && "Invalid argument"); // Check if the argument passed to the first predecessor is a literal inst. SILBasicBlock *FirstPred = *BB->pred_begin(); @@ -393,14 +393,14 @@ static bool sinkLiteralArguments(SILBasicBlock *BB, unsigned ArgNum) { // Replace the use of the argument with the cloned literal. auto Cloned = FirstLiteral->clone(&*BB->begin()); - BB->getBBArg(ArgNum)->replaceAllUsesWith(Cloned); + BB->getArgument(ArgNum)->replaceAllUsesWith(Cloned); return true; } // Try to sink values from the Nth argument \p ArgNum. static bool sinkArgument(SILBasicBlock *BB, unsigned ArgNum) { - assert(ArgNum < BB->getNumBBArg() && "Invalid argument"); + assert(ArgNum < BB->getNumArguments() && "Invalid argument"); // Find the first predecessor, the first terminator and the Nth argument. SILBasicBlock *FirstPred = *BB->pred_begin(); @@ -479,10 +479,10 @@ static bool sinkArgument(SILBasicBlock *BB, unsigned ArgNum) { // The instruction we are lowering has an argument which is different // for each predecessor. We need to sink the instruction, then add // arguments for each predecessor. - BB->getBBArg(ArgNum)->replaceAllUsesWith(FSI); + BB->getArgument(ArgNum)->replaceAllUsesWith(FSI); const auto &ArgType = FSI->getOperand(*DifferentOperandIndex)->getType(); - BB->replaceBBArg(ArgNum, ArgType); + BB->replaceArgument(ArgNum, ArgType); // Update all branch instructions in the predecessors to pass the new // argument to this BB. @@ -504,14 +504,14 @@ static bool sinkArgument(SILBasicBlock *BB, unsigned ArgNum) { // The sunk instruction should now read from the argument of the BB it // was moved to. - FSI->setOperand(*DifferentOperandIndex, BB->getBBArg(ArgNum)); + FSI->setOperand(*DifferentOperandIndex, BB->getArgument(ArgNum)); return true; } // Sink one of the copies of the instruction. FirstPredArg->replaceAllUsesWith(Undef); FSI->moveBefore(&*BB->begin()); - BB->getBBArg(ArgNum)->replaceAllUsesWith(FirstPredArg); + BB->getArgument(ArgNum)->replaceAllUsesWith(FirstPredArg); // The argument is no longer in use. Replace all incoming inputs with undef // and try to delete the instruction. @@ -537,7 +537,7 @@ static bool sinkLiteralsFromPredecessors(SILBasicBlock *BB) { // Try to sink values from each of the arguments to the basic block. bool Changed = false; - for (int i = 0, e = BB->getNumBBArg(); i < e; ++i) + for (int i = 0, e = BB->getNumArguments(); i < e; ++i) Changed |= sinkLiteralArguments(BB, i); return Changed; @@ -555,7 +555,7 @@ static bool sinkArgumentsFromPredecessors(SILBasicBlock *BB) { // Try to sink values from each of the arguments to the basic block. bool Changed = false; - for (int i = 0, e = BB->getNumBBArg(); i < e; ++i) + for (int i = 0, e = BB->getNumArguments(); i < e; ++i) Changed |= sinkArgument(BB, i); return Changed; @@ -666,7 +666,7 @@ static bool sinkCodeFromPredecessors(SILBasicBlock *BB) { ValueInBlock OpInFirstPred(InstToSink->getOperand(idx), FirstPred); assert(valueToArgIdxMap.count(OpInFirstPred) != 0); int argIdx = valueToArgIdxMap[OpInFirstPred]; - InstToSink->setOperand(idx, BB->getBBArg(argIdx)); + InstToSink->setOperand(idx, BB->getArgument(argIdx)); } } Changed = true; diff --git a/lib/SILOptimizer/Transforms/SILMem2Reg.cpp b/lib/SILOptimizer/Transforms/SILMem2Reg.cpp index 29f16d3b5c7e2..1302f22435289 100644 --- a/lib/SILOptimizer/Transforms/SILMem2Reg.cpp +++ b/lib/SILOptimizer/Transforms/SILMem2Reg.cpp @@ -537,7 +537,7 @@ StackAllocationPromoter::getLiveOutValue(BlockSet &PhiBlocks, if (PhiBlocks.count(BB)) { // Return the dummy instruction that represents the new value that we will // add to the basic block. - SILValue Phi = BB->getBBArg(BB->getNumBBArg()-1); + SILValue Phi = BB->getArgument(BB->getNumArguments() - 1); DEBUG(llvm::dbgs() << "*** Found a dummy Phi def " << *Phi); return Phi; } @@ -558,7 +558,7 @@ StackAllocationPromoter::getLiveInValue(BlockSet &PhiBlocks, // chain. if (PhiBlocks.count(BB)) { DEBUG(llvm::dbgs() << "*** Found a local Phi definition.\n"); - return BB->getBBArg(BB->getNumBBArg()-1); + return BB->getArgument(BB->getNumArguments() - 1); } if (BB->pred_empty() || !DT->getNode(BB)) diff --git a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp index b7683778d6253..78a4430ac0147 100644 --- a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp +++ b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp @@ -346,7 +346,7 @@ class ThreadInfo { // Instantiate the payload if necessary. SILBuilderWithScope Builder(SEI); - if (!ThreadedSuccessorBlock->bbarg_empty()) { + if (!ThreadedSuccessorBlock->args_empty()) { auto EnumVal = SEI->getOperand(); auto EnumTy = EnumVal->getType(); auto Loc = SEI->getLoc(); @@ -354,7 +354,7 @@ class ThreadInfo { SILValue UED( Builder.createUncheckedEnumData(Loc, EnumVal, EnumCase, Ty)); assert(UED->getType() == - (*ThreadedSuccessorBlock->bbarg_begin())->getType() && + (*ThreadedSuccessorBlock->args_begin())->getType() && "Argument types must match"); Builder.createBranch(SEI->getLoc(), ThreadedSuccessorBlock, {UED}); } else @@ -605,7 +605,7 @@ bool SimplifyCFG::simplifyThreadedTerminators() { if (auto *EI = dyn_cast(SEI->getOperand())) { DEBUG(llvm::dbgs() << "simplify threaded " << *SEI); auto *LiveBlock = SEI->getCaseDestination(EI->getElement()); - if (EI->hasOperand() && !LiveBlock->bbarg_empty()) + if (EI->hasOperand() && !LiveBlock->args_empty()) SILBuilderWithScope(SEI) .createBranch(SEI->getLoc(), LiveBlock, EI->getOperand()); else @@ -897,7 +897,7 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) { bool NeedToUpdateSSA = false; // Are the arguments to this block used outside of the block. - for (auto Arg : DestBB->getBBArgs()) + for (auto Arg : DestBB->getArguments()) if ((NeedToUpdateSSA |= isUsedOutsideOfBlock(Arg, DestBB))) { break; } @@ -920,7 +920,7 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) { if (!WantToThread) { for (unsigned i = 0, e = BI->getArgs().size(); i != e; ++i) - if (couldSimplifyUsers(DestBB->getBBArg(i), BI, BI->getArg(i))) { + if (couldSimplifyUsers(DestBB->getArgument(i), BI, BI->getArg(i))) { WantToThread = true; break; } @@ -1034,12 +1034,12 @@ static SILBasicBlock *getTrampolineDest(SILBasicBlock *SBB) { return nullptr; auto BrArgs = BI->getArgs(); - if (BrArgs.size() != SBB->getNumBBArg()) + if (BrArgs.size() != SBB->getNumArguments()) return nullptr; // Check that the arguments are the same and in the right order. - for (int i = 0, e = SBB->getNumBBArg(); i < e; ++i) { - SILArgument *BBArg = SBB->getBBArg(i); + for (int i = 0, e = SBB->getNumArguments(); i < e; ++i) { + SILArgument *BBArg = SBB->getArgument(i); if (BrArgs[i] != BBArg) return nullptr; @@ -1056,7 +1056,7 @@ static SILBasicBlock *getTrampolineDest(SILBasicBlock *SBB) { /// \return If this is a basic block without any arguments and it has /// a single br instruction, return this br. static BranchInst *getTrampolineWithoutBBArgsTerminator(SILBasicBlock *SBB) { - if (!SBB->bbarg_empty()) + if (!SBB->args_empty()) return nullptr; // Ignore blocks with more than one instruction. @@ -1118,8 +1118,8 @@ bool SimplifyCFG::simplifyBranchBlock(BranchInst *BI) { // If there are any BB arguments in the destination, replace them with the // branch operands, since they must dominate the dest block. for (unsigned i = 0, e = BI->getArgs().size(); i != e; ++i) { - if (DestBB->getBBArg(i) != BI->getArg(i)) - DestBB->getBBArg(i)->replaceAllUsesWith(BI->getArg(i)); + if (DestBB->getArgument(i) != BI->getArg(i)) + DestBB->getArgument(i)->replaceAllUsesWith(BI->getArg(i)); else { // We must be processing an unreachable part of the cfg with a cycle. // bb1(arg1): // preds: bb3 @@ -1580,8 +1580,8 @@ bool SimplifyCFG::simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI) { return true; } - if (!Element || !Element->hasArgumentType() || Dest->bbarg_empty()) { - assert(Dest->bbarg_empty() && "Unexpected argument at destination!"); + if (!Element || !Element->hasArgumentType() || Dest->args_empty()) { + assert(Dest->args_empty() && "Unexpected argument at destination!"); SILBuilderWithScope(SEI).createBranch(SEI->getLoc(), Dest); @@ -1600,7 +1600,7 @@ bool SimplifyCFG::simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI) { auto *UED = SILBuilderWithScope(SEI) .createUncheckedEnumData(SEI->getLoc(), SEI->getOperand(), Element, Ty); - assert(Dest->bbarg_size() == 1 && "Expected only one argument!"); + assert(Dest->args_size() == 1 && "Expected only one argument!"); SmallVector Args; Args.push_back(UED); SILBuilderWithScope(SEI).createBranch(SEI->getLoc(), Dest, Args); @@ -1638,7 +1638,7 @@ bool SimplifyCFG::simplifySwitchEnumBlock(SwitchEnumInst *SEI) { auto *EI = dyn_cast(SEI->getOperand()); SILBuilderWithScope Builder(SEI); - if (!LiveBlock->bbarg_empty()) { + if (!LiveBlock->args_empty()) { SILValue PayLoad; if (EI) { PayLoad = EI->getOperand(); @@ -1933,7 +1933,7 @@ bool SimplifyCFG::simplifyTryApplyBlock(TryApplyInst *TAI) { auto CalleeFnTy = cast(CalleeType.getSwiftRValueType()); auto ResultTy = CalleeFnTy->getSILResult(); - auto OrigResultTy = TAI->getNormalBB()->getBBArg(0)->getType(); + auto OrigResultTy = TAI->getNormalBB()->getArgument(0)->getType(); // Bail if the cast between the actual and expected return types cannot // be handled. @@ -2012,7 +2012,7 @@ bool SimplifyCFG::simplifyTryApplyBlock(TryApplyInst *TAI) { bool SimplifyCFG::simplifyTermWithIdenticalDestBlocks(SILBasicBlock *BB) { SILBasicBlock *commonDest = nullptr; for (auto *SuccBlock : BB->getSuccessorBlocks()) { - if (SuccBlock->getNumBBArg() != 0) + if (SuccBlock->getNumArguments() != 0) return false; SILBasicBlock *DestBlock = getTrampolineDest(SuccBlock); if (!DestBlock) @@ -2025,10 +2025,10 @@ bool SimplifyCFG::simplifyTermWithIdenticalDestBlocks(SILBasicBlock *BB) { } if (!commonDest) return false; - - assert(commonDest->getNumBBArg() == 0 && + + assert(commonDest->getNumArguments() == 0 && "getTrampolineDest should have checked that commonDest has no args"); - + TermInst *Term = BB->getTerminator(); DEBUG(llvm::dbgs() << "replace term with identical dests: " << *Term); SILBuilderWithScope(Term).createBranch(Term->getLoc(), commonDest, {}); @@ -2413,7 +2413,7 @@ static void removeArgumentFromTerminator(SILBasicBlock *BB, SILBasicBlock *Dest, static void removeArgument(SILBasicBlock *BB, unsigned i) { NumDeadArguments++; - BB->eraseBBArg(i); + BB->eraseArgument(i); // Determine the set of predecessors in case any predecessor has // two edges to this block (e.g. a conditional branch where both @@ -2541,13 +2541,13 @@ bool ArgumentSplitter::createNewArguments() { // We subtract one since this will be the number of the first new argument // *AFTER* we remove the old argument. - FirstNewArgIndex = ParentBB->getNumBBArg() - 1; + FirstNewArgIndex = ParentBB->getNumArguments() - 1; // For now for simplicity, we put all new arguments on the end and delete the // old one. llvm::SmallVector NewArgumentValues; for (auto &P : Projections) { - auto *NewArg = ParentBB->createBBArg(P.getType(Ty, Mod), nullptr); + auto *NewArg = ParentBB->createArgument(P.getType(Ty, Mod), nullptr); // This is unfortunate, but it feels wrong to put in an API into SILBuilder // that only takes in arguments. // @@ -2635,7 +2635,7 @@ bool ArgumentSplitter::split() { // Delete the old argument. We need to do this before trying to remove any // dead arguments that we added since otherwise the number of incoming values // to the phi nodes will differ from the number of values coming - ParentBB->eraseBBArg(ArgIndex); + ParentBB->eraseArgument(ArgIndex); ++NumSROAArguments; // This is here for testing purposes via sil-opt @@ -2651,9 +2651,9 @@ bool ArgumentSplitter::split() { // Do a quick pass over the new arguments to see if any of them are dead. We // can do this unconditionally in a safe way since we are only dealing with // cond_br, br. - for (int i = ParentBB->getNumBBArg() - 1, e = *FirstNewArgIndex; i >= e; + for (int i = ParentBB->getNumArguments() - 1, e = *FirstNewArgIndex; i >= e; --i) { - SILArgument *A = ParentBB->getBBArg(i); + SILArgument *A = ParentBB->getArgument(i); if (!A->use_empty()) { // We know that the argument is not dead, so add it to the worklist for // recursive processing. @@ -2677,7 +2677,7 @@ static bool splitBBArguments(SILFunction &Fn) { // We know that we have at least one BB, so this is safe since in such a case // std::next(Fn->begin()) == Fn->end(), the exit case of iteration on a range. for (auto &BB : make_range(std::next(Fn.begin()), Fn.end())) { - for (auto *Arg : BB.getBBArgs()) { + for (auto *Arg : BB.getArguments()) { SILType ArgTy = Arg->getType(); if (!ArgTy.isObject() || @@ -2889,7 +2889,7 @@ static bool simplifySwitchEnumToSelectEnum(SILBasicBlock *BB, unsigned ArgNum, // Don't know which values should be passed if there is more // than one basic block argument. - if (BB->bbarg_size() > 1) + if (BB->args_size() > 1) return false; // Mapping from case values to the results corresponding to this case value. @@ -3261,8 +3261,8 @@ bool simplifyToSelectValue(SILBasicBlock *MergeBlock, unsigned ArgNum, } moveIfNotDominating(EI2, insertPos, DT); } - - SILArgument *bbArg = MergeBlock->getBBArg(ArgNum); + + SILArgument *bbArg = MergeBlock->getArgument(ArgNum); auto SelectInst = B.createSelectValue(dominatingBlock->getTerminator()->getLoc(), Input, bbArg->getType(), defaultResult, Cases); @@ -3278,7 +3278,7 @@ bool simplifyToSelectValue(SILBasicBlock *MergeBlock, unsigned ArgNum, // a struct, tuple or enum and where the predecessors all build the struct, // tuple or enum and pass it directly. bool SimplifyCFG::simplifyArgument(SILBasicBlock *BB, unsigned i) { - auto *A = BB->getBBArg(i); + auto *A = BB->getArgument(i); // Try to create a select_value. if (simplifyToSelectValue(BB, i, DT)) @@ -3323,7 +3323,7 @@ bool SimplifyCFG::simplifyArgument(SILBasicBlock *BB, unsigned i) { // the uses in this block, and then rewrite the branch operands. DEBUG(llvm::dbgs() << "unwrap argument:" << *A); A->replaceAllUsesWith(SILUndef::get(A->getType(), BB->getModule())); - auto *NewArg = BB->replaceBBArg(i, User->getType()); + auto *NewArg = BB->replaceArgument(i, User->getType()); User->replaceAllUsesWith(NewArg); // Rewrite the branch operand for each incoming branch. @@ -3343,7 +3343,7 @@ bool SimplifyCFG::simplifyArgument(SILBasicBlock *BB, unsigned i) { static void tryToReplaceArgWithIncomingValue(SILBasicBlock *BB, unsigned i, DominanceInfo *DT) { - auto *A = BB->getBBArg(i); + auto *A = BB->getArgument(i); SmallVector Incoming; if (!A->getIncomingValues(Incoming) || Incoming.empty()) return; @@ -3368,7 +3368,7 @@ static void tryToReplaceArgWithIncomingValue(SILBasicBlock *BB, unsigned i, bool SimplifyCFG::simplifyArgs(SILBasicBlock *BB) { // Ignore blocks with no arguments. - if (BB->bbarg_empty()) + if (BB->args_empty()) return false; // Ignore the entry block. @@ -3382,8 +3382,8 @@ bool SimplifyCFG::simplifyArgs(SILBasicBlock *BB) { } bool Changed = false; - for (int i = BB->getNumBBArg() - 1; i >= 0; --i) { - SILArgument *A = BB->getBBArg(i); + for (int i = BB->getNumArguments() - 1; i >= 0; --i) { + SILArgument *A = BB->getArgument(i); // Replace a block argument if all incoming values are equal. If this // succeeds, argument A will have no uses afterwards. diff --git a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp index 7a83bf3eef19e..2b97f735b829f 100644 --- a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp +++ b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp @@ -107,7 +107,7 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI, SILBasicBlock *Iden = F->createBasicBlock(); // Virt is the block containing the slow virtual call. SILBasicBlock *Virt = F->createBasicBlock(); - Iden->createBBArg(SubType); + Iden->createArgument(SubType); SILBasicBlock *Continue = Entry->splitBasicBlock(It); @@ -125,7 +125,7 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI, SILBuilderWithScope VirtBuilder(Virt, AI.getInstruction()); SILBuilderWithScope IdenBuilder(Iden, AI.getInstruction()); // This is the class reference downcasted into subclass SubType. - SILValue DownCastedClassInstance = Iden->getBBArg(0); + SILValue DownCastedClassInstance = Iden->getArgument(0); // Copy the two apply instructions into the two blocks. FullApplySite IdenAI = CloneApply(AI, IdenBuilder); @@ -147,7 +147,7 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI, // Create a PHInode for returning the return value from both apply // instructions. - SILArgument *Arg = Continue->createBBArg(AI.getType()); + SILArgument *Arg = Continue->createArgument(AI.getType()); if (!isa(AI)) { IdenBuilder.createBranch(AI.getLoc(), Continue, ArrayRef(IdenAI.getInstruction())); @@ -181,16 +181,16 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI, // Split critical edges resulting from VirtAI. if (auto *TAI = dyn_cast(VirtAI)) { auto *ErrorBB = TAI->getFunction()->createBasicBlock(); - ErrorBB->createBBArg(TAI->getErrorBB()->getBBArg(0)->getType()); + ErrorBB->createArgument(TAI->getErrorBB()->getArgument(0)->getType()); Builder.setInsertionPoint(ErrorBB); Builder.createBranch(TAI->getLoc(), TAI->getErrorBB(), - {ErrorBB->getBBArg(0)}); + {ErrorBB->getArgument(0)}); auto *NormalBB = TAI->getFunction()->createBasicBlock(); - NormalBB->createBBArg(TAI->getNormalBB()->getBBArg(0)->getType()); + NormalBB->createArgument(TAI->getNormalBB()->getArgument(0)->getType()); Builder.setInsertionPoint(NormalBB); Builder.createBranch(TAI->getLoc(), TAI->getNormalBB(), - {NormalBB->getBBArg(0) }); + {NormalBB->getArgument(0)}); Builder.setInsertionPoint(VirtAI.getInstruction()); SmallVector Args; diff --git a/lib/SILOptimizer/Transforms/StackPromotion.cpp b/lib/SILOptimizer/Transforms/StackPromotion.cpp index 8260f9e37d61e..185a4dbc65195 100644 --- a/lib/SILOptimizer/Transforms/StackPromotion.cpp +++ b/lib/SILOptimizer/Transforms/StackPromotion.cpp @@ -416,7 +416,7 @@ SILInstruction *StackPromoter::findDeallocPoint(SILInstruction *StartInst, Iter = StartInst->getIterator(); } else { // Track all uses in the block arguments. - for (SILArgument *BBArg : BB->getBBArgs()) { + for (SILArgument *BBArg : BB->getArguments()) { if (ConGraph->isUsePoint(BBArg, Node)) NumUsePointsToFind--; } diff --git a/lib/SILOptimizer/UtilityPasses/AADumper.cpp b/lib/SILOptimizer/UtilityPasses/AADumper.cpp index aa8cac6501b55..29df26c5727c2 100644 --- a/lib/SILOptimizer/UtilityPasses/AADumper.cpp +++ b/lib/SILOptimizer/UtilityPasses/AADumper.cpp @@ -38,7 +38,7 @@ using namespace swift; // least two values to compare. static bool gatherValues(SILFunction &Fn, std::vector &Values) { for (auto &BB : Fn) { - for (auto *Arg : BB.getBBArgs()) + for (auto *Arg : BB.getArguments()) Values.push_back(SILValue(Arg)); for (auto &II : BB) if (II.hasValue()) diff --git a/lib/SILOptimizer/UtilityPasses/IVInfoPrinter.cpp b/lib/SILOptimizer/UtilityPasses/IVInfoPrinter.cpp index 6764f99f177f7..ec27a6b0c1db3 100644 --- a/lib/SILOptimizer/UtilityPasses/IVInfoPrinter.cpp +++ b/lib/SILOptimizer/UtilityPasses/IVInfoPrinter.cpp @@ -47,7 +47,7 @@ class IVInfoPrinter : public SILModuleTransform { bool FoundIV = false; for (auto &BB : F) { - for (auto A : BB.getBBArgs()) + for (auto A : BB.getArguments()) if (Info.isInductionVariable(A)) { if (!FoundIV) llvm::errs() << "Induction variables for function: " << diff --git a/lib/SILOptimizer/UtilityPasses/MemBehaviorDumper.cpp b/lib/SILOptimizer/UtilityPasses/MemBehaviorDumper.cpp index 897fc86f30240..a55bc3d5be8ca 100644 --- a/lib/SILOptimizer/UtilityPasses/MemBehaviorDumper.cpp +++ b/lib/SILOptimizer/UtilityPasses/MemBehaviorDumper.cpp @@ -31,7 +31,7 @@ using namespace swift; // least two values to compare. static bool gatherValues(SILFunction &Fn, std::vector &Values) { for (auto &BB : Fn) { - for (auto *Arg : BB.getBBArgs()) + for (auto *Arg : BB.getArguments()) Values.push_back(SILValue(Arg)); for (auto &II : BB) if (II.hasValue()) diff --git a/lib/SILOptimizer/UtilityPasses/RCIdentityDumper.cpp b/lib/SILOptimizer/UtilityPasses/RCIdentityDumper.cpp index 6b063df460c3a..950627504f86c 100644 --- a/lib/SILOptimizer/UtilityPasses/RCIdentityDumper.cpp +++ b/lib/SILOptimizer/UtilityPasses/RCIdentityDumper.cpp @@ -45,7 +45,7 @@ class RCIdentityDumper : public SILFunctionTransform { llvm::outs() << "@" << Fn->getName() << "@\n"; for (auto &BB : *Fn) { - for (auto *Arg : BB.getBBArgs()) { + for (auto *Arg : BB.getArguments()) { ValueToValueIDMap[Arg] = ValueCount++; Results.push_back({Arg, RCId->getRCIdentityRoot(Arg)}); } diff --git a/lib/SILOptimizer/Utils/CFG.cpp b/lib/SILOptimizer/Utils/CFG.cpp index f9d45e4f06071..67d674b4bb81f 100644 --- a/lib/SILOptimizer/Utils/CFG.cpp +++ b/lib/SILOptimizer/Utils/CFG.cpp @@ -43,11 +43,11 @@ TermInst *swift::addNewEdgeValueToBranch(TermInst *Branch, SILBasicBlock *Dest, if (Dest == CBI->getTrueBB()) { TrueArgs.push_back(Val); - assert(TrueArgs.size() == Dest->getNumBBArg()); + assert(TrueArgs.size() == Dest->getNumArguments()); } if (Dest == CBI->getFalseBB()) { FalseArgs.push_back(Val); - assert(FalseArgs.size() == Dest->getNumBBArg()); + assert(FalseArgs.size() == Dest->getNumArguments()); } NewBr = Builder.createCondBranch(CBI->getLoc(), CBI->getCondition(), @@ -60,7 +60,7 @@ TermInst *swift::addNewEdgeValueToBranch(TermInst *Branch, SILBasicBlock *Dest, Args.push_back(A); Args.push_back(Val); - assert(Args.size() == Dest->getNumBBArg()); + assert(Args.size() == Dest->getNumArguments()); NewBr = Builder.createBranch(BI->getLoc(), BI->getDestBB(), Args); } else { // At the moment we can only add arguments to br and cond_br. @@ -103,7 +103,7 @@ TermInst *swift::changeEdgeValue(TermInst *Branch, SILBasicBlock *Dest, else TrueArgs.push_back(OldTrueArgs[i]); } - assert(TrueArgs.size() == CBI->getTrueBB()->getNumBBArg() && + assert(TrueArgs.size() == CBI->getTrueBB()->getNumArguments() && "Destination block's number of arguments must match"); OperandValueArrayRef OldFalseArgs = CBI->getFalseArgs(); @@ -117,7 +117,7 @@ TermInst *swift::changeEdgeValue(TermInst *Branch, SILBasicBlock *Dest, else FalseArgs.push_back(OldFalseArgs[i]); } - assert(FalseArgs.size() == CBI->getFalseBB()->getNumBBArg() && + assert(FalseArgs.size() == CBI->getFalseBB()->getNumArguments() && "Destination block's number of arguments must match"); CBI = Builder.createCondBranch(CBI->getLoc(), CBI->getCondition(), @@ -141,7 +141,7 @@ TermInst *swift::changeEdgeValue(TermInst *Branch, SILBasicBlock *Dest, else Args.push_back(OldArgs[i]); } - assert(Args.size() == Dest->getNumBBArg()); + assert(Args.size() == Dest->getNumArguments()); BI = Builder.createBranch(BI->getLoc(), BI->getDestBB(), Args); Branch->dropAllReferences(); @@ -481,7 +481,7 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB, if (auto SEI = dyn_cast(T)) { auto *SuccBB = getNthEdgeBlock(SEI, EdgeIdx); - assert(SuccBB->getNumBBArg() == 0 && "Can't take an argument"); + assert(SuccBB->getNumArguments() == 0 && "Can't take an argument"); (void) SuccBB; return; } @@ -490,10 +490,11 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB, // destination block to figure this out. if (auto SEI = dyn_cast(T)) { auto *SuccBB = getNthEdgeBlock(SEI, EdgeIdx); - assert(SuccBB->getNumBBArg() < 2 && "Can take at most one argument"); - if (!SuccBB->getNumBBArg()) + assert(SuccBB->getNumArguments() < 2 && "Can take at most one argument"); + if (!SuccBB->getNumArguments()) return; - Args.push_back(NewEdgeBB->createBBArg(SuccBB->getBBArg(0)->getType())); + Args.push_back( + NewEdgeBB->createArgument(SuccBB->getArgument(0)->getType())); return; } @@ -501,33 +502,37 @@ static void getEdgeArgs(TermInst *T, unsigned EdgeIdx, SILBasicBlock *NewEdgeBB, if (auto DMBI = dyn_cast(T)) { auto *SuccBB = (EdgeIdx == 0) ? DMBI->getHasMethodBB() : DMBI->getNoMethodBB(); - if (!SuccBB->getNumBBArg()) + if (!SuccBB->getNumArguments()) return; - Args.push_back(NewEdgeBB->createBBArg(SuccBB->getBBArg(0)->getType())); + Args.push_back( + NewEdgeBB->createArgument(SuccBB->getArgument(0)->getType())); return; } /// A checked_cast_br passes the result of the cast to the first basic block. if (auto CBI = dyn_cast(T)) { auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB() : CBI->getFailureBB(); - if (!SuccBB->getNumBBArg()) + if (!SuccBB->getNumArguments()) return; - Args.push_back(NewEdgeBB->createBBArg(SuccBB->getBBArg(0)->getType())); + Args.push_back( + NewEdgeBB->createArgument(SuccBB->getArgument(0)->getType())); return; } if (auto CBI = dyn_cast(T)) { auto SuccBB = EdgeIdx == 0 ? CBI->getSuccessBB() : CBI->getFailureBB(); - if (!SuccBB->getNumBBArg()) + if (!SuccBB->getNumArguments()) return; - Args.push_back(NewEdgeBB->createBBArg(SuccBB->getBBArg(0)->getType())); + Args.push_back( + NewEdgeBB->createArgument(SuccBB->getArgument(0)->getType())); return; } if (auto *TAI = dyn_cast(T)) { auto *SuccBB = EdgeIdx == 0 ? TAI->getNormalBB() : TAI->getErrorBB(); - if (!SuccBB->getNumBBArg()) + if (!SuccBB->getNumArguments()) return; - Args.push_back(NewEdgeBB->createBBArg(SuccBB->getBBArg(0)->getType())); + Args.push_back( + NewEdgeBB->createArgument(SuccBB->getArgument(0)->getType())); return; } @@ -742,7 +747,7 @@ bool swift::mergeBasicBlockWithSuccessor(SILBasicBlock *BB, DominanceInfo *DT, // If there are any BB arguments in the destination, replace them with the // branch operands, since they must dominate the dest block. for (unsigned i = 0, e = Branch->getArgs().size(); i != e; ++i) - SuccBB->getBBArg(i)->replaceAllUsesWith(Branch->getArg(i)); + SuccBB->getArgument(i)->replaceAllUsesWith(Branch->getArg(i)); Branch->eraseFromParent(); diff --git a/lib/SILOptimizer/Utils/CheckedCastBrJumpThreading.cpp b/lib/SILOptimizer/Utils/CheckedCastBrJumpThreading.cpp index 5d7b438dd9da6..4393457b6162d 100644 --- a/lib/SILOptimizer/Utils/CheckedCastBrJumpThreading.cpp +++ b/lib/SILOptimizer/Utils/CheckedCastBrJumpThreading.cpp @@ -618,8 +618,8 @@ bool CheckedCastBrJumpThreading::trySimplify(CheckedCastBranchInst *CCBI) { // Record what we want to change. Edit *edit = new (EditAllocator.Allocate()) - Edit(BB, InvertSuccess, SuccessPreds, FailurePreds, numUnknownPreds != 0, - DomCCBI->getSuccessBB()->getBBArg(0)); + Edit(BB, InvertSuccess, SuccessPreds, FailurePreds, + numUnknownPreds != 0, DomCCBI->getSuccessBB()->getArgument(0)); Edits.push_back(edit); return true; diff --git a/lib/SILOptimizer/Utils/Devirtualize.cpp b/lib/SILOptimizer/Utils/Devirtualize.cpp index ddfbca4c40005..46f76049c3ba8 100644 --- a/lib/SILOptimizer/Utils/Devirtualize.cpp +++ b/lib/SILOptimizer/Utils/Devirtualize.cpp @@ -668,7 +668,7 @@ DevirtualizationResult swift::devirtualizeClassMethod(FullApplySite AI, ResultBB = TAI->getNormalBB(); else { ResultBB = B.getFunction().createBasicBlock(); - ResultBB->createBBArg(ResultTy); + ResultBB->createArgument(ResultTy); } NormalBB = TAI->getNormalBB(); @@ -678,7 +678,7 @@ DevirtualizationResult swift::devirtualizeClassMethod(FullApplySite AI, ErrorBB = TAI->getErrorBB(); else { ErrorBB = B.getFunction().createBasicBlock(); - ErrorBB->createBBArg(TAI->getErrorBB()->getBBArg(0)->getType()); + ErrorBB->createArgument(TAI->getErrorBB()->getArgument(0)->getType()); } NewAI = B.createTryApply(AI.getLoc(), FRI, SubstCalleeSILType, @@ -687,26 +687,27 @@ DevirtualizationResult swift::devirtualizeClassMethod(FullApplySite AI, if (ErrorBB != TAI->getErrorBB()) { B.setInsertionPoint(ErrorBB); B.createBranch(TAI->getLoc(), TAI->getErrorBB(), - {ErrorBB->getBBArg(0)}); + {ErrorBB->getArgument(0)}); } // Does the result value need to be casted? - ResultCastRequired = ResultTy != NormalBB->getBBArg(0)->getType(); + ResultCastRequired = ResultTy != NormalBB->getArgument(0)->getType(); if (ResultBB != NormalBB) B.setInsertionPoint(ResultBB); else if (ResultCastRequired) { B.setInsertionPoint(NormalBB->begin()); // Collect all uses, before casting. - for (auto *Use : NormalBB->getBBArg(0)->getUses()) { + for (auto *Use : NormalBB->getArgument(0)->getUses()) { OriginalResultUses.push_back(Use); } - NormalBB->getBBArg(0)->replaceAllUsesWith(SILUndef::get(AI.getType(), Mod)); - NormalBB->replaceBBArg(0, ResultTy, nullptr); + NormalBB->getArgument(0)->replaceAllUsesWith( + SILUndef::get(AI.getType(), Mod)); + NormalBB->replaceArgument(0, ResultTy, nullptr); } // The result value is passed as a parameter to the normal block. - ResultValue = ResultBB->getBBArg(0); + ResultValue = ResultBB->getArgument(0); } // Check if any casting is required for the return value. diff --git a/lib/SILOptimizer/Utils/GenericCloner.cpp b/lib/SILOptimizer/Utils/GenericCloner.cpp index 0c71e5dd00e96..72940f924d48f 100644 --- a/lib/SILOptimizer/Utils/GenericCloner.cpp +++ b/lib/SILOptimizer/Utils/GenericCloner.cpp @@ -68,7 +68,7 @@ void GenericCloner::populateCloned() { AllocStackInst *ReturnValueAddr = nullptr; // Create the entry basic block with the function arguments. - auto I = OrigEntryBB->bbarg_begin(), E = OrigEntryBB->bbarg_end(); + auto I = OrigEntryBB->args_begin(), E = OrigEntryBB->args_end(); int ArgIdx = 0; while (I != E) { SILArgument *OrigArg = *I; diff --git a/lib/SILOptimizer/Utils/Generics.cpp b/lib/SILOptimizer/Utils/Generics.cpp index 471e639a5692c..d34e90b582441 100644 --- a/lib/SILOptimizer/Utils/Generics.cpp +++ b/lib/SILOptimizer/Utils/Generics.cpp @@ -289,13 +289,12 @@ static ApplySite replaceWithSpecializedCallee(ApplySite AI, Arguments, ResultBB, TAI->getErrorBB()); if (StoreResultTo) { // The original normal result of the try_apply is an empty tuple. - assert(ResultBB->getNumBBArg() == 1); + assert(ResultBB->getNumArguments() == 1); Builder.setInsertionPoint(ResultBB->begin()); - fixUsedVoidType(ResultBB->getBBArg(0), Loc, Builder); + fixUsedVoidType(ResultBB->getArgument(0), Loc, Builder); - - SILArgument *Arg = - ResultBB->replaceBBArg(0, StoreResultTo->getType().getObjectType()); + SILArgument *Arg = ResultBB->replaceArgument( + 0, StoreResultTo->getType().getObjectType()); // Store the direct result to the original result address. Builder.createStore(Loc, Arg, StoreResultTo, StoreOwnershipQualifier::Unqualified); @@ -391,7 +390,7 @@ static SILFunction *createReabstractionThunk(const ReabstractionInfo &ReInfo, // Convert indirect to direct parameters/results. SmallVector Arguments; - auto SpecArgIter = SpecEntryBB->bbarg_begin(); + auto SpecArgIter = SpecEntryBB->args_begin(); for (unsigned Idx = 0; Idx < ReInfo.getNumArguments(); Idx++) { if (ReInfo.isArgConverted(Idx)) { if (ReInfo.isResultIndex(Idx)) { diff --git a/lib/SILOptimizer/Utils/Local.cpp b/lib/SILOptimizer/Utils/Local.cpp index 2805c040b3d20..423d1cc2bdda5 100644 --- a/lib/SILOptimizer/Utils/Local.cpp +++ b/lib/SILOptimizer/Utils/Local.cpp @@ -407,10 +407,10 @@ TermInst *swift::addArgumentToBranch(SILValue Val, SILBasicBlock *Dest, if (Dest == CBI->getTrueBB()) { TrueArgs.push_back(Val); - assert(TrueArgs.size() == Dest->getNumBBArg()); + assert(TrueArgs.size() == Dest->getNumArguments()); } else { FalseArgs.push_back(Val); - assert(FalseArgs.size() == Dest->getNumBBArg()); + assert(FalseArgs.size() == Dest->getNumArguments()); } return Builder.createCondBranch(CBI->getLoc(), CBI->getCondition(), @@ -425,7 +425,7 @@ TermInst *swift::addArgumentToBranch(SILValue Val, SILBasicBlock *Dest, Args.push_back(A); Args.push_back(Val); - assert(Args.size() == Dest->getNumBBArg()); + assert(Args.size() == Dest->getNumArguments()); return Builder.createBranch(BI->getLoc(), BI->getDestBB(), Args); } @@ -581,7 +581,7 @@ Optional swift::castValueToABICompatibleType(SILBuilder *B, SILLocatio auto *CurBB = B->getInsertionPoint()->getParent(); auto *ContBB = CurBB->splitBasicBlock(B->getInsertionPoint()); - ContBB->createBBArg(DestTy,nullptr); + ContBB->createArgument(DestTy, nullptr); SmallVector, 1> CaseBBs; CaseBBs.push_back(std::make_pair(SomeDecl, SomeBB)); @@ -607,7 +607,7 @@ Optional swift::castValueToABICompatibleType(SILBuilder *B, SILLocatio B->createBranch(Loc, ContBB, {CastedValue}); B->setInsertionPoint(ContBB->begin()); - CastedValue = ContBB->getBBArg(0); + CastedValue = ContBB->getArgument(0); return CastedValue; } @@ -1444,20 +1444,20 @@ optimizeBridgedObjCToSwiftCast(SILInstruction *Inst, // from ObjCTy to _ObjectiveCBridgeable._ObjectiveCType. if (isConditional) { SILBasicBlock *CastSuccessBB = Inst->getFunction()->createBasicBlock(); - CastSuccessBB->createBBArg(SILBridgedTy); + CastSuccessBB->createArgument(SILBridgedTy); Builder.createBranch(Loc, CastSuccessBB, SILValue(Load)); Builder.setInsertionPoint(CastSuccessBB); - SrcOp = CastSuccessBB->getBBArg(0); + SrcOp = CastSuccessBB->getArgument(0); } else { SrcOp = Load; } } else if (isConditional) { SILBasicBlock *CastSuccessBB = Inst->getFunction()->createBasicBlock(); - CastSuccessBB->createBBArg(SILBridgedTy); + CastSuccessBB->createArgument(SILBridgedTy); NewI = Builder.createCheckedCastBranch(Loc, false, Load, SILBridgedTy, CastSuccessBB, ConvFailBB); Builder.setInsertionPoint(CastSuccessBB); - SrcOp = CastSuccessBB->getBBArg(0); + SrcOp = CastSuccessBB->getArgument(0); } else { NewI = Builder.createUnconditionalCheckedCast(Loc, Load, SILBridgedTy); @@ -2044,7 +2044,7 @@ CastOptimizer::simplifyCheckedCastBranchInst(CheckedCastBranchInst *Inst) { // Replace by unconditional_cast, followed by a branch. // The unconditional_cast can be skipped, if the result of a cast // is not used afterwards. - bool ResultNotUsed = SuccessBB->getBBArg(0)->use_empty(); + bool ResultNotUsed = SuccessBB->getArgument(0)->use_empty(); SILValue CastedValue; if (Op->getType() != LoweredTargetType) { if (!ResultNotUsed) { @@ -2144,10 +2144,10 @@ optimizeCheckedCastAddrBranchInst(CheckedCastAddrBranchInst *Inst) { auto NewI = B.createCheckedCastBranch( Loc, false /*isExact*/, MI, Dest->getType().getObjectType(), SuccessBB, FailureBB); - SuccessBB->createBBArg(Dest->getType().getObjectType(), nullptr); + SuccessBB->createArgument(Dest->getType().getObjectType(), nullptr); B.setInsertionPoint(SuccessBB->begin()); // Store the result - B.createStore(Loc, SuccessBB->getBBArg(0), Dest, + B.createStore(Loc, SuccessBB->getArgument(0), Dest, StoreOwnershipQualifier::Unqualified); EraseInstAction(Inst); return NewI; diff --git a/lib/SILOptimizer/Utils/LoopUtils.cpp b/lib/SILOptimizer/Utils/LoopUtils.cpp index 5da66ed1d006e..ec8a85200670e 100644 --- a/lib/SILOptimizer/Utils/LoopUtils.cpp +++ b/lib/SILOptimizer/Utils/LoopUtils.cpp @@ -29,8 +29,8 @@ static SILBasicBlock *createInitialPreheader(SILBasicBlock *Header) { // Clone the arguments from header into the pre-header. llvm::SmallVector Args; - for (auto *HeaderArg : Header->getBBArgs()) { - Args.push_back(Preheader->createBBArg(HeaderArg->getType(), nullptr)); + for (auto *HeaderArg : Header->getArguments()) { + Args.push_back(Preheader->createArgument(HeaderArg->getType(), nullptr)); } // Create the branch to the header. @@ -124,8 +124,9 @@ static SILBasicBlock *insertBackedgeBlock(SILLoop *L, DominanceInfo *DT, // Now that the block has been inserted into the function, create PHI nodes in // the backedge block which correspond to any PHI nodes in the header block. SmallVector BBArgs; - for (auto *BBArg : Header->getBBArgs()) { - BBArgs.push_back(BEBlock->createBBArg(BBArg->getType(), /*Decl=*/nullptr)); + for (auto *BBArg : Header->getArguments()) { + BBArgs.push_back( + BEBlock->createArgument(BBArg->getType(), /*Decl=*/nullptr)); } // Arbitrarily pick one of the predecessor's branch locations. diff --git a/lib/SILOptimizer/Utils/SILInliner.cpp b/lib/SILOptimizer/Utils/SILInliner.cpp index 22d76e4c8da5b..bd6f15c364c7c 100644 --- a/lib/SILOptimizer/Utils/SILInliner.cpp +++ b/lib/SILOptimizer/Utils/SILInliner.cpp @@ -89,9 +89,9 @@ bool SILInliner::inlineFunction(FullApplySite AI, ArrayRef Args) { // Clear argument map and map ApplyInst arguments to the arguments of the // callee's entry block. ValueMap.clear(); - assert(CalleeEntryBB->bbarg_size() == Args.size() && + assert(CalleeEntryBB->args_size() == Args.size() && "Unexpected number of arguments to entry block of function?"); - auto BAI = CalleeEntryBB->bbarg_begin(); + auto BAI = CalleeEntryBB->args_begin(); for (auto AI = Args.begin(), AE = Args.end(); AI != AE; ++AI, ++BAI) ValueMap.insert(std::make_pair(*BAI, *AI)); diff --git a/lib/SILOptimizer/Utils/SILSSAUpdater.cpp b/lib/SILOptimizer/Utils/SILSSAUpdater.cpp index 7d19f9d0f9a14..875f98f0b45ec 100644 --- a/lib/SILOptimizer/Utils/SILSSAUpdater.cpp +++ b/lib/SILOptimizer/Utils/SILSSAUpdater.cpp @@ -199,10 +199,10 @@ SILValue SILSSAUpdater::GetValueInMiddleOfBlock(SILBasicBlock *BB) { return SingularValue; // Check if we already have an equivalent phi. - if (!BB->getBBArgs().empty()) { + if (!BB->getArguments().empty()) { llvm::SmallDenseMap ValueMap(PredVals.begin(), PredVals.end()); - for (auto *Arg : BB->getBBArgs()) + for (auto *Arg : BB->getArguments()) if (isEquivalentPHI(Arg, ValueMap)) return Arg; @@ -238,12 +238,13 @@ class SSAUpdaterTraits { /// can be used in the SSAUpdaterImpl. class PhiIt { private: - SILBasicBlock::bbarg_iterator It; + SILBasicBlock::arg_iterator It; + public: explicit PhiIt(SILBasicBlock *B) // begin iterator - : It(B->bbarg_begin()) {} + : It(B->args_begin()) {} PhiIt(SILBasicBlock *B, bool) // end iterator - : It(B->bbarg_end()) {} + : It(B->args_end()) {} PhiIt &operator++() { ++It; return *this; } operator SILArgument *() { return *It; } @@ -489,7 +490,7 @@ static StructInst *replaceBBArgWithStruct( SmallVector ArgIdxForOper; for (unsigned OperIdx : indices(FirstSI->getElements())) { bool FoundMatchingArgIdx = false; - for (unsigned ArgIdx : indices(PhiBB->getBBArgs())) { + for (unsigned ArgIdx : indices(PhiBB->getArguments())) { SmallVectorImpl::const_iterator AVIter = ArgValues.begin(); bool TryNextArgIdx = false; for (SILBasicBlock *PredBB : PhiBB->getPreds()) { @@ -517,7 +518,7 @@ static StructInst *replaceBBArgWithStruct( SmallVector StructArgs; for (auto ArgIdx : ArgIdxForOper) - StructArgs.push_back(PhiBB->getBBArg(ArgIdx)); + StructArgs.push_back(PhiBB->getArgument(ArgIdx)); SILBuilder Builder(PhiBB, PhiBB->begin()); return Builder.createStruct(cast(ArgValues[0])->getLoc(), diff --git a/lib/Serialization/SerializeSIL.cpp b/lib/Serialization/SerializeSIL.cpp index 47ad248a1f67b..e4f89d43a3363 100644 --- a/lib/Serialization/SerializeSIL.cpp +++ b/lib/Serialization/SerializeSIL.cpp @@ -391,7 +391,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) { auto &BB = **Iter; BasicBlockMap.insert(std::make_pair(&BB, BasicID++)); - for (auto I = BB.bbarg_begin(), E = BB.bbarg_end(); I != E; ++I) + for (auto I = BB.args_begin(), E = BB.args_end(); I != E; ++I) ValueIDs[static_cast(*I)] = ++ValueID; for (const SILInstruction &SI : BB) @@ -414,7 +414,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) { void SILSerializer::writeSILBasicBlock(const SILBasicBlock &BB) { SmallVector Args; - for (auto I = BB.bbarg_begin(), E = BB.bbarg_end(); I != E; ++I) { + for (auto I = BB.args_begin(), E = BB.args_end(); I != E; ++I) { SILArgument *SA = *I; DeclID tId = S.addTypeRef(SA->getType().getSwiftRValueType()); DeclID vId = addValueRef(static_cast(SA)); From c3d5ace299d3924c7886aa253b970c373f0d41dc Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Fri, 25 Nov 2016 00:36:39 -0600 Subject: [PATCH 3/6] [gardening] Move SILBasicBlock::dropAllReferences() out of the argument list manipulation section. I am not sure why it was put here originally, but I believe it is still there due to bitrot. --- include/swift/SIL/SILBasicBlock.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/swift/SIL/SILBasicBlock.h b/include/swift/SIL/SILBasicBlock.h index ea8fa04025af7..23b3a8ce1eb33 100644 --- a/include/swift/SIL/SILBasicBlock.h +++ b/include/swift/SIL/SILBasicBlock.h @@ -184,13 +184,6 @@ public llvm::ilist_node, public SILAllocated { /// \brief Remove all block arguments. void dropAllArguments() { ArgumentList.clear(); } - /// \brief Drops all uses that belong to this basic block. - void dropAllReferences() { - dropAllArguments(); - for (SILInstruction &I : *this) - I.dropAllReferences(); - } - //===--------------------------------------------------------------------===// // Predecessors and Successors //===--------------------------------------------------------------------===// @@ -296,6 +289,13 @@ public llvm::ilist_node, public SILAllocated { return &SILBasicBlock::InstList; } + /// \brief Drops all uses that belong to this basic block. + void dropAllReferences() { + dropAllArguments(); + for (SILInstruction &I : *this) + I.dropAllReferences(); + } + private: friend class SILArgument; From e936de7b04cacc9519a5d466a062e255f3406281 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Fri, 25 Nov 2016 00:37:46 -0600 Subject: [PATCH 4/6] [gardening] 0 => nullptr. NFC. --- include/swift/SIL/SILBasicBlock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/swift/SIL/SILBasicBlock.h b/include/swift/SIL/SILBasicBlock.h index 23b3a8ce1eb33..c8a3e11be1259 100644 --- a/include/swift/SIL/SILBasicBlock.h +++ b/include/swift/SIL/SILBasicBlock.h @@ -47,7 +47,7 @@ public llvm::ilist_node, public SILAllocated { friend struct llvm::ilist_sentinel_traits; friend struct llvm::ilist_traits; - SILBasicBlock() : Parent(0) {} + SILBasicBlock() : Parent(nullptr) {} void operator=(const SILBasicBlock &) = delete; void operator delete(void *Ptr, size_t) = delete; From a998d989249149a2ba23fa5e81be48436c9f5929 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Fri, 25 Nov 2016 00:31:33 -0600 Subject: [PATCH 5/6] [gardening] SILBasicBlock::splitBasicBlock() => *::split(). The BasicBlock suffix is redundant. --- include/swift/SIL/SILBasicBlock.h | 2 +- lib/SIL/SILBasicBlock.cpp | 2 +- lib/SIL/SILBuilder.cpp | 2 +- lib/SILOptimizer/IPO/EagerSpecializer.cpp | 6 +++--- lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp | 4 ++-- lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp | 2 +- lib/SILOptimizer/Utils/CFG.cpp | 2 +- lib/SILOptimizer/Utils/Local.cpp | 2 +- lib/SILOptimizer/Utils/SILInliner.cpp | 2 +- tools/sil-extract/SILExtract.cpp | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/swift/SIL/SILBasicBlock.h b/include/swift/SIL/SILBasicBlock.h index c8a3e11be1259..7d309b8eeb70a 100644 --- a/include/swift/SIL/SILBasicBlock.h +++ b/include/swift/SIL/SILBasicBlock.h @@ -132,7 +132,7 @@ public llvm::ilist_node, public SILAllocated { /// Note that all the instructions BEFORE the specified iterator /// stay as part of the original basic block. The old basic block is left /// without a terminator. - SILBasicBlock *splitBasicBlock(iterator I); + SILBasicBlock *split(iterator I); /// \brief Move the basic block to after the specified basic block in the IR. /// The basic blocks must reside in the same function. diff --git a/lib/SIL/SILBasicBlock.cpp b/lib/SIL/SILBasicBlock.cpp index f77ae17ba7443..111e62c8b4862 100644 --- a/lib/SIL/SILBasicBlock.cpp +++ b/lib/SIL/SILBasicBlock.cpp @@ -146,7 +146,7 @@ void SILBasicBlock::eraseArgument(int Index) { /// Note that all the instructions BEFORE the specified iterator /// stay as part of the original basic block. The old basic block is left /// without a terminator. -SILBasicBlock *SILBasicBlock::splitBasicBlock(iterator I) { +SILBasicBlock *SILBasicBlock::split(iterator I) { SILBasicBlock *New = new (Parent->getModule()) SILBasicBlock(Parent); SILFunction::iterator Where = std::next(SILFunction::iterator(this)); SILFunction::iterator First = SILFunction::iterator(New); diff --git a/lib/SIL/SILBuilder.cpp b/lib/SIL/SILBuilder.cpp index 7213aeb8e9e99..3e92e086a425c 100644 --- a/lib/SIL/SILBuilder.cpp +++ b/lib/SIL/SILBuilder.cpp @@ -142,7 +142,7 @@ SILBasicBlock *SILBuilder::splitBlockForFallthrough() { } // Otherwise we need to split the current block at the insertion point. - auto *NewBB = BB->splitBasicBlock(InsertPt); + auto *NewBB = BB->split(InsertPt); InsertPt = BB->end(); return NewBB; } diff --git a/lib/SILOptimizer/IPO/EagerSpecializer.cpp b/lib/SILOptimizer/IPO/EagerSpecializer.cpp index 19d9284695d8e..6f167379ad805 100644 --- a/lib/SILOptimizer/IPO/EagerSpecializer.cpp +++ b/lib/SILOptimizer/IPO/EagerSpecializer.cpp @@ -106,12 +106,12 @@ static void addReturnValueImpl(SILBasicBlock *RetBB, SILBasicBlock *NewRetBB, TupleI = TupleI->clone(RetInst); RetInst->setOperand(0, TupleI); } - MergedBB = RetBB->splitBasicBlock(TupleI->getIterator()); + MergedBB = RetBB->split(TupleI->getIterator()); Builder.setInsertionPoint(RetBB); Builder.createBranch(Loc, MergedBB); } else { // Forward the existing return argument to a new BBArg. - MergedBB = RetBB->splitBasicBlock(RetInst->getIterator()); + MergedBB = RetBB->split(RetInst->getIterator()); SILValue OldRetVal = RetInst->getOperand(0); RetInst->setOperand(0, MergedBB->createArgument(OldRetVal->getType())); Builder.setInsertionPoint(RetBB); @@ -255,7 +255,7 @@ void EagerDispatch::emitDispatchTo(SILFunction *NewFunc) { // First split the entry BB, moving all instructions to the FailedTypeCheckBB. auto &EntryBB = GenericFunc->front(); - SILBasicBlock *FailedTypeCheckBB = EntryBB.splitBasicBlock(EntryBB.begin()); + SILBasicBlock *FailedTypeCheckBB = EntryBB.split(EntryBB.begin()); Builder.setInsertionPoint(&EntryBB, EntryBB.begin()); // Iterate over all dependent types in the generic signature, which will match diff --git a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp index ec697201749fc..1efbe55bf92b4 100644 --- a/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp +++ b/lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp @@ -127,8 +127,8 @@ static void InsertCFGDiamond(SILValue Cond, SILLocation Loc, SILBuilder &B, SILBasicBlock *StartBB = B.getInsertionBB(); // Start by splitting the current block. - ContBB = StartBB->splitBasicBlock(B.getInsertionPoint()); - + ContBB = StartBB->split(B.getInsertionPoint()); + // Create the true block if requested. SILBasicBlock *TrueDest; if (!createTrueBB) { diff --git a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp index 2b97f735b829f..e76b70005c4c2 100644 --- a/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp +++ b/lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp @@ -109,7 +109,7 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI, SILBasicBlock *Virt = F->createBasicBlock(); Iden->createArgument(SubType); - SILBasicBlock *Continue = Entry->splitBasicBlock(It); + SILBasicBlock *Continue = Entry->split(It); SILBuilderWithScope Builder(Entry, AI.getInstruction()); // Create the checked_cast_branch instruction that checks at runtime if the diff --git a/lib/SILOptimizer/Utils/CFG.cpp b/lib/SILOptimizer/Utils/CFG.cpp index 67d674b4bb81f..2fdb61072445c 100644 --- a/lib/SILOptimizer/Utils/CFG.cpp +++ b/lib/SILOptimizer/Utils/CFG.cpp @@ -548,7 +548,7 @@ SILBasicBlock *swift::splitBasicBlockAndBranch(SILBuilder &B, DominanceInfo *DT, SILLoopInfo *LI) { auto *OrigBB = SplitBeforeInst->getParent(); - auto *NewBB = OrigBB->splitBasicBlock(SplitBeforeInst->getIterator()); + auto *NewBB = OrigBB->split(SplitBeforeInst->getIterator()); B.setInsertionPoint(OrigBB); B.createBranch(SplitBeforeInst->getLoc(), NewBB); diff --git a/lib/SILOptimizer/Utils/Local.cpp b/lib/SILOptimizer/Utils/Local.cpp index 423d1cc2bdda5..444eaad5a0dc4 100644 --- a/lib/SILOptimizer/Utils/Local.cpp +++ b/lib/SILOptimizer/Utils/Local.cpp @@ -580,7 +580,7 @@ Optional swift::castValueToABICompatibleType(SILBuilder *B, SILLocatio auto *SomeBB = B->getFunction().createBasicBlock(); auto *CurBB = B->getInsertionPoint()->getParent(); - auto *ContBB = CurBB->splitBasicBlock(B->getInsertionPoint()); + auto *ContBB = CurBB->split(B->getInsertionPoint()); ContBB->createArgument(DestTy, nullptr); SmallVector, 1> CaseBBs; diff --git a/lib/SILOptimizer/Utils/SILInliner.cpp b/lib/SILOptimizer/Utils/SILInliner.cpp index bd6f15c364c7c..2a0bb203ed16e 100644 --- a/lib/SILOptimizer/Utils/SILInliner.cpp +++ b/lib/SILOptimizer/Utils/SILInliner.cpp @@ -127,7 +127,7 @@ bool SILInliner::inlineFunction(FullApplySite AI, ArrayRef Args) { SILBasicBlock *CallerBB = AI.getParent(); // Split the BB and do NOT create a branch between the old and new // BBs; we will create the appropriate terminator manually later. - ReturnToBB = CallerBB->splitBasicBlock(InsertPoint); + ReturnToBB = CallerBB->split(InsertPoint); // Place the return-to BB after all the other mapped BBs. if (InsertBeforeBB) F.getBlocks().splice(SILFunction::iterator(InsertBeforeBB), F.getBlocks(), diff --git a/tools/sil-extract/SILExtract.cpp b/tools/sil-extract/SILExtract.cpp index 6e7f3937b6488..7effaa979fd9c 100644 --- a/tools/sil-extract/SILExtract.cpp +++ b/tools/sil-extract/SILExtract.cpp @@ -116,7 +116,7 @@ removeUnwantedFunctions(SILModule *M, llvm::StringRef Name) { SILBasicBlock &BB = F.front(); SILLocation Loc = BB.back().getLoc(); - BB.splitBasicBlock(BB.begin()); + BB.split(BB.begin()); // Make terminator unreachable. SILBuilder(&BB).createUnreachable(Loc); From 0a8c54d04f4b0860a7d0aadcc5922b80308e980b Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Fri, 25 Nov 2016 00:58:49 -0600 Subject: [PATCH 6/6] [gardening] Always create new SILArguments using SILBasicBlock::createArgument instead of inline placement new. The reasoning here is the same as in e42bf07. --- include/swift/SIL/SILArgument.h | 20 ++++++-------- include/swift/SIL/SILCloner.h | 2 +- lib/Parse/ParseSIL.cpp | 2 +- lib/SIL/DynamicCasts.cpp | 7 +++-- lib/SILGen/Condition.cpp | 2 +- lib/SILGen/RValue.cpp | 4 +-- lib/SILGen/SILGen.cpp | 6 ++--- lib/SILGen/SILGenApply.cpp | 6 ++--- lib/SILGen/SILGenBridging.cpp | 25 ++++++++---------- lib/SILGen/SILGenConstructor.cpp | 26 ++++++++----------- lib/SILGen/SILGenConvert.cpp | 3 +-- lib/SILGen/SILGenDecl.cpp | 2 +- lib/SILGen/SILGenDynamicCast.cpp | 9 +++---- lib/SILGen/SILGenEpilog.cpp | 4 +-- lib/SILGen/SILGenExpr.cpp | 2 +- lib/SILGen/SILGenFunction.cpp | 6 ++--- lib/SILGen/SILGenMaterializeForSet.cpp | 2 +- lib/SILGen/SILGenPattern.cpp | 2 +- lib/SILGen/SILGenPoly.cpp | 5 ++-- lib/SILGen/SILGenProlog.cpp | 24 +++++++---------- lib/SILGen/SILGenStmt.cpp | 2 +- lib/SILOptimizer/IPO/CapturePromotion.cpp | 5 ++-- lib/SILOptimizer/IPO/CapturePropagation.cpp | 5 ++-- lib/SILOptimizer/IPO/ClosureSpecializer.cpp | 6 ++--- .../LoopTransforms/COWArrayOpt.cpp | 4 +-- .../LoopTransforms/LoopUnroll.cpp | 3 +-- .../Transforms/AllocBoxToStack.cpp | 7 +++-- lib/SILOptimizer/Transforms/SILMem2Reg.cpp | 6 ++--- lib/SILOptimizer/Utils/GenericCloner.cpp | 5 ++-- lib/SILOptimizer/Utils/Generics.cpp | 15 +++++------ lib/SILOptimizer/Utils/SILInliner.cpp | 3 +-- lib/SILOptimizer/Utils/SILSSAUpdater.cpp | 4 +-- lib/Serialization/DeserializeSIL.cpp | 5 ++-- 33 files changed, 97 insertions(+), 132 deletions(-) diff --git a/include/swift/SIL/SILArgument.h b/include/swift/SIL/SILArgument.h index 8cfd2700edb2f..7011d191fe91b 100644 --- a/include/swift/SIL/SILArgument.h +++ b/include/swift/SIL/SILArgument.h @@ -117,18 +117,8 @@ class SILArgument : public ValueBase { SILBasicBlock *ParentBB; const ValueDecl *Decl; -public: - SILArgument(SILBasicBlock *ParentBB, SILType Ty, const ValueDecl *D=nullptr); - SILArgument(SILBasicBlock *ParentBB, SILBasicBlock::arg_iterator Pos, - SILType Ty, const ValueDecl *D = nullptr); - - SILArgument(SILFunction::iterator ParentBB, SILType Ty, - const ValueDecl *D = nullptr) - : SILArgument(&*ParentBB, Ty, D) {} - SILArgument(SILFunction::iterator ParentBB, SILBasicBlock::arg_iterator Pos, - SILType Ty, const ValueDecl *D = nullptr) - : SILArgument(&*ParentBB, Pos, Ty, D) {} +public: SILBasicBlock *getParent() { return ParentBB; } const SILBasicBlock *getParent() const { return ParentBB; } @@ -230,10 +220,16 @@ class SILArgument : public ValueBase { } private: + friend class SILBasicBlock; + + SILArgument(SILBasicBlock *ParentBB, SILType Ty, + const ValueDecl *D = nullptr); + SILArgument(SILBasicBlock *ParentBB, SILBasicBlock::arg_iterator Pos, + SILType Ty, const ValueDecl *D = nullptr); + // A special constructor, only intended for use in SILBasicBlock::replaceBBArg. explicit SILArgument(SILType Ty, const ValueDecl *D =nullptr) : ValueBase(ValueKind::SILArgument, Ty), ParentBB(nullptr), Decl(D) {} - friend class SILBasicBlock; void setParent(SILBasicBlock *P) { ParentBB = P; } }; diff --git a/include/swift/SIL/SILCloner.h b/include/swift/SIL/SILCloner.h index 0a99d7f0d1cc1..863f3f83ebc47 100644 --- a/include/swift/SIL/SILCloner.h +++ b/include/swift/SIL/SILCloner.h @@ -402,7 +402,7 @@ SILCloner::visitSILBasicBlock(SILBasicBlock* BB) { // Create new arguments for each of the original block's arguments. for (auto &Arg : Succ.getBB()->getArguments()) { SILValue MappedArg = - new (F.getModule()) SILArgument(MappedBB, getOpType(Arg->getType())); + MappedBB->createArgument(getOpType(Arg->getType())); ValueMap.insert(std::make_pair(Arg, MappedArg)); } diff --git a/lib/Parse/ParseSIL.cpp b/lib/Parse/ParseSIL.cpp index 59480e25c8406..e421b6b89265e 100644 --- a/lib/Parse/ParseSIL.cpp +++ b/lib/Parse/ParseSIL.cpp @@ -3957,7 +3957,7 @@ bool SILParser::parseSILBasicBlock(SILBuilder &B) { P.parseToken(tok::colon, diag::expected_sil_colon_value_ref) || parseSILType(Ty)) return true; - auto Arg = new (SILMod) SILArgument(BB, Ty); + auto Arg = BB->createArgument(Ty); setLocalValue(Arg, Name, NameLoc); } while (P.consumeIf(tok::comma)); diff --git a/lib/SIL/DynamicCasts.cpp b/lib/SIL/DynamicCasts.cpp index 995a50cc6305d..6e9a65d7d1671 100644 --- a/lib/SIL/DynamicCasts.cpp +++ b/lib/SIL/DynamicCasts.cpp @@ -930,7 +930,7 @@ namespace { CastConsumptionKind::TakeAlways); } else { SILValue sourceObjectValue = - new (M) SILArgument(someBB, loweredSourceObjectType); + someBB->createArgument(loweredSourceObjectType); objectSource = Source(sourceObjectValue, sourceObjectType, source.Consumption); } @@ -968,7 +968,7 @@ namespace { if (target.isAddress()) { return target.asAddressSource(); } else { - SILValue result = new (M) SILArgument(contBB, target.LoweredType); + SILValue result = contBB->createArgument(target.LoweredType); return target.asScalarSource(result); } } @@ -1214,8 +1214,7 @@ emitIndirectConditionalCastWithScalar(SILBuilder &B, Module *M, // Emit the success block. B.setInsertionPoint(scalarSuccBB); { auto &targetTL = B.getModule().Types.getTypeLowering(targetValueType); - SILValue succValue = - new (B.getModule()) SILArgument(scalarSuccBB, targetValueType); + SILValue succValue = scalarSuccBB->createArgument(targetValueType); if (!shouldTakeOnSuccess(consumption)) targetTL.emitCopyValue(B, loc, succValue); targetTL.emitStoreOfCopy(B, loc, succValue, dest, IsInitialization); diff --git a/lib/SILGen/Condition.cpp b/lib/SILGen/Condition.cpp index d7f3f5e786dda..4e0a709b09b04 100644 --- a/lib/SILGen/Condition.cpp +++ b/lib/SILGen/Condition.cpp @@ -155,7 +155,7 @@ ConditionalValue::ConditionalValue(SILGenFunction &gen, SGFContext C, } else { // Otherwise, add a BB arg to the continuation block to receive loadable // result. - result = new (gen.F.getModule()) SILArgument(contBB, tl.getLoweredType()); + result = contBB->createArgument(tl.getLoweredType()); } } diff --git a/lib/SILGen/RValue.cpp b/lib/SILGen/RValue.cpp index f4e7e88fbfa4a..896ea33666ee2 100644 --- a/lib/SILGen/RValue.cpp +++ b/lib/SILGen/RValue.cpp @@ -254,8 +254,8 @@ class EmitBBArguments : public CanTypeVisitor()); + SILValue arg = parent->createArgument(gen.getLoweredType(t), + loc.getAsASTNode()); ManagedValue mv = isa(t) ? ManagedValue::forLValue(arg) : gen.emitManagedRValueWithCleanup(arg); diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 48940abeb19ae..b65aa8341c3a7 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -1230,10 +1230,8 @@ static void emitTopLevelProlog(SILGenFunction &gen, SILLocation loc) { // Create the argc and argv arguments. auto &C = gen.getASTContext(); auto FnTy = gen.F.getLoweredFunctionType(); - auto argc = new (gen.F.getModule()) SILArgument( - entry, FnTy->getParameters()[0].getSILType()); - auto argv = new (gen.F.getModule()) SILArgument( - entry, FnTy->getParameters()[1].getSILType()); + auto *argc = entry->createArgument(FnTy->getParameters()[0].getSILType()); + auto *argv = entry->createArgument(FnTy->getParameters()[1].getSILType()); // If the standard library provides a _stdlib_didEnterMain intrinsic, call it // first thing. diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index 9ddec0ca9087f..894b142ff1127 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -5541,8 +5541,7 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e, auto dynamicMethodTy = getDynamicMethodLoweredType(*this, operand, member, memberFnTy); auto loweredMethodTy = SILType::getPrimitiveObjectType(dynamicMethodTy); - SILValue memberArg = new (F.getModule()) SILArgument(hasMemberBB, - loweredMethodTy); + SILValue memberArg = hasMemberBB->createArgument(loweredMethodTy); // Create the result value. SILValue result = emitDynamicPartialApply(*this, e, memberArg, operand, @@ -5637,8 +5636,7 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e, auto dynamicMethodTy = getDynamicMethodLoweredType(*this, base, member, functionTy); auto loweredMethodTy = SILType::getPrimitiveObjectType(dynamicMethodTy); - SILValue memberArg = new (F.getModule()) SILArgument(hasMemberBB, - loweredMethodTy); + SILValue memberArg = hasMemberBB->createArgument(loweredMethodTy); // Emit the application of 'self'. SILValue result = emitDynamicPartialApply(*this, e, memberArg, base, cast(methodTy)); diff --git a/lib/SILGen/SILGenBridging.cpp b/lib/SILGen/SILGenBridging.cpp index de25865067f7c..bec7982766443 100644 --- a/lib/SILGen/SILGenBridging.cpp +++ b/lib/SILGen/SILGenBridging.cpp @@ -244,7 +244,7 @@ static void buildFuncToBlockInvokeBody(SILGenFunction &gen, // Get the captured native function value out of the block. auto storageAddrTy = SILType::getPrimitiveAddressType(blockStorageTy); - auto storage = new (gen.SGM.M) SILArgument(entry, storageAddrTy); + auto storage = entry->createArgument(storageAddrTy); auto capture = gen.B.createProjectBlockStorage(loc, storage); auto &funcTL = gen.getTypeLowering(funcTy); auto fn = gen.emitLoad(loc, capture, funcTL, SGFContext(), IsNotTake); @@ -258,7 +258,7 @@ static void buildFuncToBlockInvokeBody(SILGenFunction &gen, for (unsigned i : indices(funcTy->getParameters())) { auto &funcParam = funcTy->getParameters()[i]; auto ¶m = blockTy->getParameters()[i]; - SILValue v = new (gen.SGM.M) SILArgument(entry, param.getSILType()); + SILValue v = entry->createArgument(param.getSILType()); ManagedValue mv; @@ -603,7 +603,7 @@ static void buildBlockToFuncThunkBody(SILGenFunction &gen, if (tl.isAddressOnly()) { assert(result.getConvention() == ResultConvention::Indirect); - indirectResult = new (gen.SGM.M) SILArgument(entry, result.getSILType()); + indirectResult = entry->createArgument(result.getSILType()); } } @@ -612,7 +612,7 @@ static void buildBlockToFuncThunkBody(SILGenFunction &gen, auto &blockParam = blockTy->getParameters()[i]; auto &tl = gen.getTypeLowering(param.getSILType()); - SILValue v = new (gen.SGM.M) SILArgument(entry, param.getSILType()); + SILValue v = entry->createArgument(param.getSILType()); auto mv = gen.emitManagedRValueWithCleanup(v, tl); args.push_back(gen.emitNativeToBridgedValue(loc, mv, SILFunctionTypeRepresentation::Block, @@ -620,9 +620,8 @@ static void buildBlockToFuncThunkBody(SILGenFunction &gen, } // Add the block argument. - SILValue blockV - = new (gen.SGM.M) SILArgument(entry, - SILType::getPrimitiveObjectType(blockTy)); + SILValue blockV = + entry->createArgument(SILType::getPrimitiveObjectType(blockTy)); ManagedValue block = gen.emitManagedRValueWithCleanup(blockV); // Call the block. @@ -928,7 +927,7 @@ static SILFunctionType *emitObjCThunkArguments(SILGenFunction &gen, nativeInputs.size() + unsigned(foreignError.hasValue())); for (unsigned i = 0, e = inputs.size(); i < e; ++i) { SILType argTy = inputs[i].getSILType(); - SILValue arg = new(gen.F.getModule()) SILArgument(gen.F.begin(), argTy); + SILValue arg = gen.F.begin()->createArgument(argTy); // If this parameter is the foreign error slot, pull it out. // It does not correspond to a native argument. @@ -1204,8 +1203,8 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) { if (!nativeFnTy->getIndirectResults().empty()) { assert(nativeFnTy->getIndirectResults().size() == 1 && "bridged exploded result?!"); - indirectResult = new (F.getModule()) SILArgument(F.begin(), - nativeFnTy->getIndirectResults()[0].getSILType()); + indirectResult = F.begin()->createArgument( + nativeFnTy->getIndirectResults()[0].getSILType()); } for (auto *paramList : reversed(forwardedParameters)) @@ -1214,10 +1213,8 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) { if (allocatorSelfType) { auto selfMetatype = CanMetatypeType::get(allocatorSelfType->getCanonicalType()); - auto selfArg = new (F.getModule()) SILArgument( - F.begin(), - getLoweredLoadableType(selfMetatype), - fd->getImplicitSelfDecl()); + auto selfArg = F.begin()->createArgument( + getLoweredLoadableType(selfMetatype), fd->getImplicitSelfDecl()); params.push_back(selfArg); } diff --git a/lib/SILGen/SILGenConstructor.cpp b/lib/SILGen/SILGenConstructor.cpp index 349771b8ae752..1ae21685bf478 100644 --- a/lib/SILGen/SILGenConstructor.cpp +++ b/lib/SILGen/SILGenConstructor.cpp @@ -38,8 +38,8 @@ static SILValue emitConstructorMetatypeArg(SILGenFunction &gen, AC.getIdentifier("$metatype"), SourceLoc(), AC.getIdentifier("$metatype"), metatype, ctor->getDeclContext()); - gen.AllocatorMetatype = new (gen.F.getModule()) SILArgument(gen.F.begin(), - gen.getLoweredType(metatype), VD); + gen.AllocatorMetatype = + gen.F.begin()->createArgument(gen.getLoweredType(metatype), VD); return gen.AllocatorMetatype; } @@ -60,9 +60,7 @@ static RValue emitImplicitValueConstructorArg(SILGenFunction &gen, AC.getIdentifier("$implicit_value"), SourceLoc(), AC.getIdentifier("$implicit_value"), ty, DC); - SILValue arg = new (gen.F.getModule()) SILArgument(gen.F.begin(), - gen.getLoweredType(ty), - VD); + SILValue arg = gen.F.begin()->createArgument(gen.getLoweredType(ty), VD); return RValue(gen, loc, ty, gen.emitManagedRValueWithCleanup(arg)); } } @@ -85,7 +83,7 @@ static void emitImplicitValueConstructor(SILGenFunction &gen, SourceLoc(), AC.getIdentifier("$return_value"), selfTyCan, ctor); - resultSlot = new (gen.F.getModule()) SILArgument(gen.F.begin(), selfTy, VD); + resultSlot = gen.F.begin()->createArgument(selfTy, VD); } // Emit the elementwise arguments. @@ -237,8 +235,8 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) { B.createReturn(ctor, emitEmptyTuple(ctor)); } else { // Pass 'nil' as the return value to the exit BB. - failureExitArg = new (F.getModule()) - SILArgument(failureExitBB, resultLowering.getLoweredType()); + failureExitArg = + failureExitBB->createArgument(resultLowering.getLoweredType()); SILValue nilResult = B.createEnum(ctor, {}, getASTContext().getOptionalNoneDecl(), resultLowering.getLoweredType()); @@ -365,9 +363,7 @@ void SILGenFunction::emitEnumConstructor(EnumElementDecl *element) { AC.getIdentifier("$return_value"), CanInOutType::get(enumTy), element->getDeclContext()); - auto resultSlot = new (SGM.M) SILArgument(F.begin(), - enumTI.getLoweredType(), - VD); + auto resultSlot = F.begin()->createArgument(enumTI.getLoweredType(), VD); dest = std::unique_ptr( new KnownAddressInitialization(resultSlot)); } @@ -563,7 +559,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) { TupleType::getEmpty(F.getASTContext()), ctor, ctor->hasThrows()); SILType selfTy = getLoweredLoadableType(selfDecl->getType()); - SILValue selfArg = new (SGM.M) SILArgument(F.begin(), selfTy, selfDecl); + SILValue selfArg = F.begin()->createArgument(selfTy, selfDecl); if (!NeedsBoxForSelf) { SILLocation PrologueLoc(selfDecl); @@ -612,8 +608,8 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) { SavedInsertionPoint savedIP(*this, failureBB, FunctionSection::Postmatter); failureExitBB = createBasicBlock(); - failureExitArg = new (F.getModule()) - SILArgument(failureExitBB, resultLowering.getLoweredType()); + failureExitArg = + failureExitBB->createArgument(resultLowering.getLoweredType()); Cleanups.emitCleanupsForReturn(ctor); SILValue nilResult = B.createEnum(loc, {}, @@ -942,7 +938,7 @@ void SILGenFunction::emitIVarInitializer(SILDeclRef ivarInitializer) { // Emit 'self', then mark it uninitialized. auto selfDecl = cd->getDestructor()->getImplicitSelfDecl(); SILType selfTy = getLoweredLoadableType(selfDecl->getType()); - SILValue selfArg = new (SGM.M) SILArgument(F.begin(), selfTy, selfDecl); + SILValue selfArg = F.begin()->createArgument(selfTy, selfDecl); SILLocation PrologueLoc(selfDecl); PrologueLoc.markAsPrologue(); B.createDebugValue(PrologueLoc, selfArg); diff --git a/lib/SILGen/SILGenConvert.cpp b/lib/SILGen/SILGenConvert.cpp index 1b4d545aa243a..60cf0b7fac99d 100644 --- a/lib/SILGen/SILGenConvert.cpp +++ b/lib/SILGen/SILGenConvert.cpp @@ -281,9 +281,8 @@ SILGenFunction::emitOptionalToOptional(SILLocation loc, if (resultTL.isAddressOnly()) result = emitTemporaryAllocation(loc, resultTy); else - result = new (F.getModule()) SILArgument(contBB, resultTL.getLoweredType()); + result = contBB->createArgument(resultTL.getLoweredType()); - // Branch on whether the input is optional, this doesn't consume the value. auto isPresent = emitDoesOptionalHaveValue(loc, input.getValue()); B.createCondBranch(loc, isPresent, isPresentBB, isNotPresentBB); diff --git a/lib/SILGen/SILGenDecl.cpp b/lib/SILGen/SILGenDecl.cpp index 9fb05634eb9df..a007b1ff7081d 100644 --- a/lib/SILGen/SILGenDecl.cpp +++ b/lib/SILGen/SILGenDecl.cpp @@ -697,7 +697,7 @@ emitEnumMatch(ManagedValue value, EnumElementDecl *ElementDecl, // is not address-only. SILValue eltValue; if (!value.getType().isAddress()) - eltValue = new (SGF.F.getModule()) SILArgument(contBB, eltTy); + eltValue = contBB->createArgument(eltTy); if (subInit == nullptr) { // If there is no subinitialization, then we are done matching. Don't diff --git a/lib/SILGen/SILGenDynamicCast.cpp b/lib/SILGen/SILGenDynamicCast.cpp index 270c93511e66b..7709b3975b354 100644 --- a/lib/SILGen/SILGenDynamicCast.cpp +++ b/lib/SILGen/SILGenDynamicCast.cpp @@ -158,8 +158,8 @@ namespace { result = finishFromResultBuffer(hasAbstraction, resultBuffer, abstraction, origTargetTL, ctx); } else { - SILValue argument = new (SGF.F.getModule()) - SILArgument(trueBB, origTargetTL.getLoweredType()); + SILValue argument = + trueBB->createArgument(origTargetTL.getLoweredType()); result = finishFromResultScalar(hasAbstraction, argument, consumption, abstraction, origTargetTL, ctx); } @@ -499,8 +499,7 @@ RValue Lowering::emitConditionalCheckedCast(SILGenFunction &SGF, if (resultObjectTemp) { result = SGF.manageBufferForExprResult(resultBuffer, resultTL, C); } else { - auto argument = - new (SGF.F.getModule()) SILArgument(contBB, resultTL.getLoweredType()); + auto argument = contBB->createArgument(resultTL.getLoweredType()); result = SGF.emitManagedRValueWithCleanup(argument, resultTL); } @@ -549,7 +548,7 @@ SILValue Lowering::emitIsa(SILGenFunction &SGF, SILLocation loc, }); auto contBB = scope.exit(); - auto isa = new (SGF.SGM.M) SILArgument(contBB, i1Ty); + auto isa = contBB->createArgument(i1Ty); return isa; } diff --git a/lib/SILGen/SILGenEpilog.cpp b/lib/SILGen/SILGenEpilog.cpp index 8decaf9b73d89..753319fabc247 100644 --- a/lib/SILGen/SILGenEpilog.cpp +++ b/lib/SILGen/SILGenEpilog.cpp @@ -28,7 +28,7 @@ void SILGenFunction::prepareEpilog(Type resultType, bool isThrowing, NeedsReturn = (F.getLoweredFunctionType()->getNumAllResults() != 0); for (auto directResult : F.getLoweredFunctionType()->getDirectResults()) { SILType resultType = F.mapTypeIntoContext(directResult.getSILType()); - new (F.getModule()) SILArgument(epilogBB, resultType); + epilogBB->createArgument(resultType); } } @@ -42,7 +42,7 @@ void SILGenFunction::prepareEpilog(Type resultType, bool isThrowing, void SILGenFunction::prepareRethrowEpilog(CleanupLocation cleanupLoc) { auto exnType = SILType::getExceptionType(getASTContext()); SILBasicBlock *rethrowBB = createBasicBlock(FunctionSection::Postmatter); - new (F.getModule()) SILArgument(rethrowBB, exnType); + rethrowBB->createArgument(exnType); ThrowDest = JumpDest(rethrowBB, getCleanupsDepth(), cleanupLoc); } diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index 797f3a244608c..729062296fae4 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -3040,7 +3040,7 @@ RValue RValueEmitter::visitOptionalEvaluationExpr(OptionalEvaluationExpr *E, // If this was done in SSA registers, then the value is provided as an // argument to the block. if (!isByAddress) { - auto arg = new (SGF.SGM.M) SILArgument(contBB, optTL.getLoweredType()); + auto arg = contBB->createArgument(optTL.getLoweredType()); return RValue(SGF, E, SGF.emitManagedRValueWithCleanup(arg, optTL)); } diff --git a/lib/SILGen/SILGenFunction.cpp b/lib/SILGen/SILGenFunction.cpp index ec95897fc8654..8fe8dc9351954 100644 --- a/lib/SILGen/SILGenFunction.cpp +++ b/lib/SILGen/SILGenFunction.cpp @@ -690,7 +690,7 @@ static void forwardCaptureArgs(SILGenFunction &gen, SmallVectorImpl &args, CapturedValue capture) { auto addSILArgument = [&](SILType t, ValueDecl *d) { - args.push_back(new (gen.SGM.M) SILArgument(gen.F.begin(), t, d)); + args.push_back(gen.F.begin()->createArgument(t, d)); }; auto *vd = capture.getDecl(); @@ -786,8 +786,8 @@ void SILGenFunction::emitCurryThunk(ValueDecl *vd, && "currying constructor at level other than one?!"); F.setBare(IsBare); auto selfMetaTy = vd->getType()->getAs()->getInput(); - auto metatypeVal = new (F.getModule()) SILArgument(F.begin(), - getLoweredLoadableType(selfMetaTy)); + auto metatypeVal = + F.begin()->createArgument(getLoweredLoadableType(selfMetaTy)); curriedArgs.push_back(metatypeVal); } else if (auto fd = dyn_cast(vd)) { diff --git a/lib/SILGen/SILGenMaterializeForSet.cpp b/lib/SILGen/SILGenMaterializeForSet.cpp index 2e5adb0f09cad..e0d00133808c9 100644 --- a/lib/SILGen/SILGenMaterializeForSet.cpp +++ b/lib/SILGen/SILGenMaterializeForSet.cpp @@ -557,7 +557,7 @@ SILFunction *MaterializeForSetEmitter::createCallback(SILFunction &F, auto makeParam = [&](unsigned index) -> SILArgument* { SILType type = gen.F.mapTypeIntoContext( callbackType->getParameters()[index].getSILType()); - return new (SGM.M) SILArgument(gen.F.begin(), type); + return gen.F.begin()->createArgument(type); }; // Add arguments for all the parameters. diff --git a/lib/SILGen/SILGenPattern.cpp b/lib/SILGen/SILGenPattern.cpp index 6261ead0107d7..0e8540361bb11 100644 --- a/lib/SILGen/SILGenPattern.cpp +++ b/lib/SILGen/SILGenPattern.cpp @@ -1777,7 +1777,7 @@ emitEnumElementDispatch(ArrayRef rows, eltValue = eltTL->emitLoad(SGF.B, loc, eltValue, LoadOwnershipQualifier::Take); } else { - eltValue = new (SGF.F.getModule()) SILArgument(caseBB, eltTy); + eltValue = caseBB->createArgument(eltTy); } origCMV = getManagedSubobject(SGF, eltValue, *eltTL, eltConsumption); diff --git a/lib/SILGen/SILGenPoly.cpp b/lib/SILGen/SILGenPoly.cpp index 4ac62f0b47026..2317f18127c10 100644 --- a/lib/SILGen/SILGenPoly.cpp +++ b/lib/SILGen/SILGenPoly.cpp @@ -770,14 +770,15 @@ void SILGenFunction::collectThunkParams(SILLocation loc, // Add the indirect results. for (auto result : F.getLoweredFunctionType()->getIndirectResults()) { auto paramTy = F.mapTypeIntoContext(result.getSILType()); - (void) new (SGM.M) SILArgument(F.begin(), paramTy); + SILArgument *arg = F.begin()->createArgument(paramTy); + (void)arg; } // Add the parameters. auto paramTypes = F.getLoweredFunctionType()->getParameters(); for (auto param : paramTypes) { auto paramTy = F.mapTypeIntoContext(param.getSILType()); - auto paramValue = new (SGM.M) SILArgument(F.begin(), paramTy); + auto paramValue = F.begin()->createArgument(paramTy); auto paramMV = manageParam(*this, loc, paramValue, param, allowPlusZero); params.push_back(paramMV); } diff --git a/lib/SILGen/SILGenProlog.cpp b/lib/SILGen/SILGenProlog.cpp index ac19b54b60a16..af5c6affe3bb5 100644 --- a/lib/SILGen/SILGenProlog.cpp +++ b/lib/SILGen/SILGenProlog.cpp @@ -24,7 +24,7 @@ using namespace Lowering; SILValue SILGenFunction::emitSelfDecl(VarDecl *selfDecl) { // Emit the implicit 'self' argument. SILType selfType = getLoweredLoadableType(selfDecl->getType()); - SILValue selfValue = new (SGM.M) SILArgument(F.begin(), selfType, selfDecl); + SILValue selfValue = F.begin()->createArgument(selfType, selfDecl); VarLocs[selfDecl] = VarLoc::get(selfValue); SILLocation PrologueLoc(selfDecl); PrologueLoc.markAsPrologue(); @@ -128,8 +128,8 @@ class EmitBBArguments : public CanTypeVisitormapTypeIntoContext(parameterInfo.getSILType()) && "argument does not have same type as specified by parameter info"); - SILValue arg = new (gen.SGM.M) - SILArgument(parent, argType, loc.getAsASTNode()); + SILValue arg = + parent->createArgument(argType, loc.getAsASTNode()); ManagedValue mv = getManagedValue(arg, t, parameterInfo); // If the value is a (possibly optional) ObjC block passed into the entry @@ -329,8 +329,7 @@ static void makeArgument(Type ty, ParamDecl *decl, for (auto fieldType : tupleTy->getElementTypes()) makeArgument(fieldType, decl, args, gen); } else { - auto arg = new (gen.F.getModule()) SILArgument(gen.F.begin(), - gen.getLoweredType(ty),decl); + auto arg = gen.F.begin()->createArgument(gen.getLoweredType(ty), decl); args.push_back(arg); } } @@ -358,7 +357,7 @@ static void emitCaptureArguments(SILGenFunction &gen, CapturedValue capture, auto &lowering = gen.getTypeLowering(VD->getType()); // Constant decls are captured by value. SILType ty = lowering.getLoweredType(); - SILValue val = new (gen.SGM.M) SILArgument(gen.F.begin(), ty, VD); + SILValue val = gen.F.begin()->createArgument(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 @@ -389,7 +388,7 @@ static void emitCaptureArguments(SILGenFunction &gen, CapturedValue capture, SILType ty = gen.getLoweredType(type).getAddressType(); SILType boxTy = SILType::getPrimitiveObjectType( SILBoxType::get(ty.getSwiftRValueType())); - SILValue box = new (gen.SGM.M) SILArgument(gen.F.begin(), boxTy, VD); + SILValue box = gen.F.begin()->createArgument(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}); @@ -400,7 +399,7 @@ static void emitCaptureArguments(SILGenFunction &gen, CapturedValue capture, case CaptureKind::StorageAddress: { // Non-escaping stored decls are captured as the address of the value. SILType ty = gen.getLoweredType(type).getAddressType(); - SILValue addr = new (gen.SGM.M) SILArgument(gen.F.begin(), ty, VD); + SILValue addr = gen.F.begin()->createArgument(ty, VD); gen.VarLocs[VD] = SILGenFunction::VarLoc::get(addr); gen.B.createDebugValueAddr(Loc, addr, {/*Constant*/true, ArgNo}); break; @@ -424,7 +423,7 @@ void SILGenFunction::emitProlog(AnyFunctionRef TheClosure, MetatypeRepresentation::Thick) ->getCanonicalType(); SILType ty = SILType::getPrimitiveObjectType(selfMetatype); - SILValue val = new (SGM.M) SILArgument(F.begin(), ty); + SILValue val = F.begin()->createArgument(ty); (void) val; return; @@ -454,11 +453,8 @@ static void emitIndirectResultParameters(SILGenFunction &gen, Type resultType, ctx.getIdentifier("$return_value"), resultType, DC); - auto arg = - new (gen.SGM.M) SILArgument(gen.F.begin(), resultTI.getLoweredType(), var); - (void) arg; - - + auto *arg = gen.F.begin()->createArgument(resultTI.getLoweredType(), var); + (void)arg; } unsigned SILGenFunction::emitProlog(ArrayRef paramLists, diff --git a/lib/SILGen/SILGenStmt.cpp b/lib/SILGen/SILGenStmt.cpp index afb2e7401ec74..7d2ae9c73ea58 100644 --- a/lib/SILGen/SILGenStmt.cpp +++ b/lib/SILGen/SILGenStmt.cpp @@ -166,7 +166,7 @@ Condition SILGenFunction::emitCondition(SILValue V, SILLocation Loc, SILBasicBlock *ContBB = createBasicBlock(); for (SILType argTy : contArgs) { - new (F.getModule()) SILArgument(ContBB, argTy); + ContBB->createArgument(argTy); } SILBasicBlock *FalseBB, *FalseDestBB; diff --git a/lib/SILOptimizer/IPO/CapturePromotion.cpp b/lib/SILOptimizer/IPO/CapturePromotion.cpp index 5139febc48e23..62d019fbccc9e 100644 --- a/lib/SILOptimizer/IPO/CapturePromotion.cpp +++ b/lib/SILOptimizer/IPO/CapturePromotion.cpp @@ -463,7 +463,6 @@ ClosureCloner::initCloned(SILFunction *Orig, IsFragile_t Fragile, void ClosureCloner::populateCloned() { SILFunction *Cloned = getCloned(); - SILModule &M = Cloned->getModule(); // Create arguments for the entry block SILBasicBlock *OrigEntryBB = &*Orig->begin(); @@ -476,7 +475,7 @@ ClosureCloner::populateCloned() { auto BoxedTy = (*I)->getType().castTo()->getBoxedAddressType() .getObjectType(); SILValue MappedValue = - new (M) SILArgument(ClonedEntryBB, BoxedTy, (*I)->getDecl()); + ClonedEntryBB->createArgument(BoxedTy, (*I)->getDecl()); BoxArgumentMap.insert(std::make_pair(*I, MappedValue)); // Track the projections of the box. @@ -488,7 +487,7 @@ ClosureCloner::populateCloned() { } else { // Otherwise, create a new argument which copies the original argument SILValue MappedValue = - new (M) SILArgument(ClonedEntryBB, (*I)->getType(), (*I)->getDecl()); + ClonedEntryBB->createArgument((*I)->getType(), (*I)->getDecl()); ValueMap.insert(std::make_pair(*I, MappedValue)); } ++ArgNo; diff --git a/lib/SILOptimizer/IPO/CapturePropagation.cpp b/lib/SILOptimizer/IPO/CapturePropagation.cpp index 934a27ebd2003..0471b299e7cc7 100644 --- a/lib/SILOptimizer/IPO/CapturePropagation.cpp +++ b/lib/SILOptimizer/IPO/CapturePropagation.cpp @@ -161,7 +161,6 @@ void CapturePropagationCloner::cloneBlocks( OperandValueArrayRef PartialApplyArgs) { SILFunction &CloneF = getBuilder().getFunction(); - SILModule &M = CloneF.getModule(); // Create the entry basic block with the function arguments. SILBasicBlock *OrigEntryBB = &*OrigF->begin(); @@ -177,8 +176,8 @@ void CapturePropagationCloner::cloneBlocks( SILArgument *Arg = OrigEntryBB->getArgument(ParamIdx); - SILValue MappedValue = new (M) - SILArgument(ClonedEntryBB, remapType(Arg->getType()), Arg->getDecl()); + SILValue MappedValue = ClonedEntryBB->createArgument( + remapType(Arg->getType()), Arg->getDecl()); ValueMap.insert(std::make_pair(Arg, MappedValue)); } assert(OrigEntryBB->args_size() - ParamIdx == PartialApplyArgs.size() && diff --git a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp index 917b7493e0dad..f333a79216cfe 100644 --- a/lib/SILOptimizer/IPO/ClosureSpecializer.cpp +++ b/lib/SILOptimizer/IPO/ClosureSpecializer.cpp @@ -585,8 +585,7 @@ void ClosureSpecCloner::populateCloned() { // Otherwise, create a new argument which copies the original argument SILValue MappedValue = - new (M) SILArgument(ClonedEntryBB, Arg->getType(), Arg->getDecl()); - + ClonedEntryBB->createArgument(Arg->getType(), Arg->getDecl()); ValueMap.insert(std::make_pair(Arg, MappedValue)); } @@ -603,8 +602,7 @@ void ClosureSpecCloner::populateCloned() { unsigned NumNotCaptured = NumTotalParams - CallSiteDesc.getNumArguments(); llvm::SmallVector NewPAIArgs; for (auto &PInfo : ClosedOverFunTy->getParameters().slice(NumNotCaptured)) { - SILValue MappedValue = - new (M) SILArgument(ClonedEntryBB, PInfo.getSILType()); + SILValue MappedValue = ClonedEntryBB->createArgument(PInfo.getSILType()); NewPAIArgs.push_back(MappedValue); } diff --git a/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp b/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp index 59223b0383376..51d4460ce7068 100644 --- a/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp +++ b/lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp @@ -1952,9 +1952,7 @@ class RegionCloner : public SILCloner { SILBasicBlock *cloneRegion() { assert (DomTree.getNode(StartBB) != nullptr && "Can't cloned dead code"); - auto CurFun = StartBB->getParent(); - auto &Mod = CurFun->getModule(); // We don't want to visit blocks outside of the region. visitSILBasicBlocks // checks BBMap before it clones a block. So we mark exiting blocks as @@ -1981,7 +1979,7 @@ class RegionCloner : public SILCloner { // Clone the arguments. for (auto &Arg : StartBB->getArguments()) { SILValue MappedArg = - new (Mod) SILArgument(ClonedStartBB, getOpType(Arg->getType())); + ClonedStartBB->createArgument(getOpType(Arg->getType())); ValueMap.insert(std::make_pair(Arg, MappedArg)); } diff --git a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp index aa88ed94287a8..cdba69ae97362 100644 --- a/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp +++ b/lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp @@ -72,7 +72,6 @@ class LoopCloner : public SILCloner { void LoopCloner::cloneLoop() { auto *Header = Loop->getHeader(); auto *CurFun = Loop->getHeader()->getParent(); - auto &Mod = CurFun->getModule(); SmallVector ExitBlocks; Loop->getExitBlocks(ExitBlocks); @@ -85,7 +84,7 @@ void LoopCloner::cloneLoop() { // Clone the arguments. for (auto *Arg : Header->getArguments()) { SILValue MappedArg = - new (Mod) SILArgument(ClonedHeader, getOpType(Arg->getType())); + ClonedHeader->createArgument(getOpType(Arg->getType())); ValueMap.insert(std::make_pair(Arg, MappedArg)); } diff --git a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp index ace01dc1206bd..9588624aa1972 100644 --- a/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp +++ b/lib/SILOptimizer/Transforms/AllocBoxToStack.cpp @@ -585,7 +585,6 @@ PromotedParamCloner::initCloned(SILFunction *Orig, IsFragile_t Fragile, void PromotedParamCloner::populateCloned() { SILFunction *Cloned = getCloned(); - SILModule &M = Cloned->getModule(); // Create arguments for the entry block SILBasicBlock *OrigEntryBB = &*Orig->begin(); @@ -597,8 +596,8 @@ PromotedParamCloner::populateCloned() { // Create a new argument with the promoted type. auto promotedTy = (*I)->getType().castTo() ->getBoxedAddressType(); - auto promotedArg = new (M) - SILArgument(ClonedEntryBB, promotedTy, (*I)->getDecl()); + auto *promotedArg = + ClonedEntryBB->createArgument(promotedTy, (*I)->getDecl()); PromotedParameters.insert(*I); // Map any projections of the box to the promoted argument. @@ -611,7 +610,7 @@ PromotedParamCloner::populateCloned() { } else { // Create a new argument which copies the original argument. SILValue MappedValue = - new (M) SILArgument(ClonedEntryBB, (*I)->getType(), (*I)->getDecl()); + ClonedEntryBB->createArgument((*I)->getType(), (*I)->getDecl()); ValueMap.insert(std::make_pair(*I, MappedValue)); } ++ArgNo; diff --git a/lib/SILOptimizer/Transforms/SILMem2Reg.cpp b/lib/SILOptimizer/Transforms/SILMem2Reg.cpp index 1302f22435289..ba96266169e2f 100644 --- a/lib/SILOptimizer/Transforms/SILMem2Reg.cpp +++ b/lib/SILOptimizer/Transforms/SILMem2Reg.cpp @@ -511,10 +511,8 @@ void MemoryToRegisters::removeSingleBlockAllocation(AllocStackInst *ASI) { void StackAllocationPromoter::addBlockArguments(BlockSet &PhiBlocks) { DEBUG(llvm::dbgs() << "*** Adding new block arguments.\n"); - SILModule &M = ASI->getModule(); - - for (auto Block : PhiBlocks) - new (M) SILArgument(Block, ASI->getElementType()); + for (auto *Block : PhiBlocks) + Block->createArgument(ASI->getElementType()); } SILValue diff --git a/lib/SILOptimizer/Utils/GenericCloner.cpp b/lib/SILOptimizer/Utils/GenericCloner.cpp index 72940f924d48f..40d0adccc7ac6 100644 --- a/lib/SILOptimizer/Utils/GenericCloner.cpp +++ b/lib/SILOptimizer/Utils/GenericCloner.cpp @@ -57,7 +57,6 @@ SILFunction *GenericCloner::initCloned(SILFunction *Orig, void GenericCloner::populateCloned() { SILFunction *Cloned = getCloned(); - SILModule &M = Cloned->getModule(); // Create arguments for the entry block. SILBasicBlock *OrigEntryBB = &*Original.begin(); @@ -90,7 +89,7 @@ void GenericCloner::populateCloned() { } else { // Store the new direct parameter to the alloc_stack. auto *NewArg = - new (M) SILArgument(ClonedEntryBB, mappedType, OrigArg->getDecl()); + ClonedEntryBB->createArgument(mappedType, OrigArg->getDecl()); getBuilder().createStore(Loc, NewArg, ASI, StoreOwnershipQualifier::Unqualified); @@ -105,7 +104,7 @@ void GenericCloner::populateCloned() { } } else { auto *NewArg = - new (M) SILArgument(ClonedEntryBB, mappedType, OrigArg->getDecl()); + ClonedEntryBB->createArgument(mappedType, OrigArg->getDecl()); ValueMap[OrigArg] = NewArg; } ++I; diff --git a/lib/SILOptimizer/Utils/Generics.cpp b/lib/SILOptimizer/Utils/Generics.cpp index d34e90b582441..740e0612daf69 100644 --- a/lib/SILOptimizer/Utils/Generics.cpp +++ b/lib/SILOptimizer/Utils/Generics.cpp @@ -396,13 +396,12 @@ static SILFunction *createReabstractionThunk(const ReabstractionInfo &ReInfo, if (ReInfo.isResultIndex(Idx)) { // Store the result later. SILType Ty = SpecType->getSILResult().getAddressType(); - ReturnValueAddr = new (M) SILArgument(EntryBB, Ty); + ReturnValueAddr = EntryBB->createArgument(Ty); } else { // Instead of passing the address, pass the loaded value. SILArgument *SpecArg = *SpecArgIter++; SILType Ty = SpecArg->getType().getAddressType(); - SILArgument *NewArg = new (M) SILArgument(EntryBB, Ty, - SpecArg->getDecl()); + SILArgument *NewArg = EntryBB->createArgument(Ty, SpecArg->getDecl()); auto *ArgVal = Builder.createLoad(Loc, NewArg, LoadOwnershipQualifier::Unqualified); Arguments.push_back(ArgVal); @@ -410,8 +409,8 @@ static SILFunction *createReabstractionThunk(const ReabstractionInfo &ReInfo, } else { // No change to the argument. SILArgument *SpecArg = *SpecArgIter++; - SILArgument *NewArg = new (M) SILArgument(EntryBB, SpecArg->getType(), - SpecArg->getDecl()); + SILArgument *NewArg = + EntryBB->createArgument(SpecArg->getType(), SpecArg->getDecl()); Arguments.push_back(NewArg); } } @@ -424,11 +423,11 @@ static SILFunction *createReabstractionThunk(const ReabstractionInfo &ReInfo, SILBasicBlock *ErrorBB = Thunk->createBasicBlock(); Builder.createTryApply(Loc, FRI, SpecializedFunc->getLoweredType(), {}, Arguments, NormalBB, ErrorBB); - auto *ErrorVal = new (M) SILArgument(ErrorBB, - SpecType->getErrorResult().getSILType()); + auto *ErrorVal = + ErrorBB->createArgument(SpecType->getErrorResult().getSILType()); Builder.setInsertionPoint(ErrorBB); Builder.createThrow(Loc, ErrorVal); - ReturnValue = new (M) SILArgument(NormalBB, SpecType->getSILResult()); + ReturnValue = NormalBB->createArgument(SpecType->getSILResult()); Builder.setInsertionPoint(NormalBB); } else { ReturnValue = Builder.createApply(Loc, FRI, SpecializedFunc->getLoweredType(), diff --git a/lib/SILOptimizer/Utils/SILInliner.cpp b/lib/SILOptimizer/Utils/SILInliner.cpp index 2a0bb203ed16e..ac29b8fa288da 100644 --- a/lib/SILOptimizer/Utils/SILInliner.cpp +++ b/lib/SILOptimizer/Utils/SILInliner.cpp @@ -137,8 +137,7 @@ bool SILInliner::inlineFunction(FullApplySite AI, ArrayRef Args) { SILFunction::iterator(ReturnToBB)); // Create an argument on the return-to BB representing the returned value. - auto *RetArg = new (F.getModule()) SILArgument(ReturnToBB, - AI.getInstruction()->getType()); + auto *RetArg = ReturnToBB->createArgument(AI.getInstruction()->getType()); // Replace all uses of the ApplyInst with the new argument. AI.getInstruction()->replaceAllUsesWith(RetArg); } diff --git a/lib/SILOptimizer/Utils/SILSSAUpdater.cpp b/lib/SILOptimizer/Utils/SILSSAUpdater.cpp index 875f98f0b45ec..3b9ddcc50f52d 100644 --- a/lib/SILOptimizer/Utils/SILSSAUpdater.cpp +++ b/lib/SILOptimizer/Utils/SILSSAUpdater.cpp @@ -209,7 +209,7 @@ SILValue SILSSAUpdater::GetValueInMiddleOfBlock(SILBasicBlock *BB) { } // Create a new phi node. - SILArgument *PHI(new (BB->getModule()) SILArgument(BB, ValType)); + SILArgument *PHI(BB->createArgument(ValType)); for (auto &EV : PredVals) addNewEdgeValueToBranch(EV.first->getTerminator(), BB, EV.second); @@ -314,7 +314,7 @@ class SSAUpdaterTraits { static SILValue CreateEmptyPHI(SILBasicBlock *BB, unsigned NumPreds, SILSSAUpdater *Updater) { // Add the argument to the block. - SILValue PHI(new (BB->getModule()) SILArgument(BB, Updater->ValType)); + SILValue PHI(BB->createArgument(Updater->ValType)); // Mark all predecessor blocks with the sentinel undef value. SmallVector Preds(BB->pred_begin(), BB->pred_end()); diff --git a/lib/Serialization/DeserializeSIL.cpp b/lib/Serialization/DeserializeSIL.cpp index 24b2fcebe85cc..be846798c37de 100644 --- a/lib/Serialization/DeserializeSIL.cpp +++ b/lib/Serialization/DeserializeSIL.cpp @@ -626,9 +626,8 @@ SILBasicBlock *SILDeserializer::readSILBasicBlock(SILFunction *Fn, if (!ValId) return nullptr; auto ArgTy = MF->getType(TyID); - auto Arg = new (SILMod) SILArgument(CurrentBB, - getSILType(ArgTy, - (SILValueCategory)Args[I+1])); + auto Arg = CurrentBB->createArgument( + getSILType(ArgTy, (SILValueCategory)Args[I + 1])); LastValueID = LastValueID + 1; setLocalValue(Arg, LastValueID); }