Skip to content

Commit d74b512

Browse files
authored
Merge pull request #27771 from gottesmm/pr-d94d2ddde5fb71505e74c2de5d0e951939faed35
2 parents 6942d36 + 3e79381 commit d74b512

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static bool useCaptured(Operand *UI) {
7070

7171
// Is any successor of BB in the LiveIn set?
7272
static bool successorHasLiveIn(SILBasicBlock *BB,
73-
llvm::SmallPtrSetImpl<SILBasicBlock *> &LiveIn) {
73+
SmallPtrSetImpl<SILBasicBlock *> &LiveIn) {
7474
for (auto &Succ : BB->getSuccessors())
7575
if (LiveIn.count(Succ))
7676
return true;
@@ -80,11 +80,11 @@ static bool successorHasLiveIn(SILBasicBlock *BB,
8080

8181
// Propagate liveness backwards from an initial set of blocks in our
8282
// LiveIn set.
83-
static void propagateLiveness(llvm::SmallPtrSetImpl<SILBasicBlock*> &LiveIn,
83+
static void propagateLiveness(SmallPtrSetImpl<SILBasicBlock *> &LiveIn,
8484
SILBasicBlock *DefBB) {
8585

8686
// First populate a worklist of predecessors.
87-
llvm::SmallVector<SILBasicBlock*, 64> Worklist;
87+
SmallVector<SILBasicBlock *, 64> Worklist;
8888
for (auto *BB : LiveIn)
8989
for (auto Pred : BB->getPredecessorBlocks())
9090
Worklist.push_back(Pred);
@@ -106,7 +106,7 @@ static void propagateLiveness(llvm::SmallPtrSetImpl<SILBasicBlock*> &LiveIn,
106106
// Walk backwards in BB looking for strong_release, destroy_value, or
107107
// dealloc_box of the given value, and add it to releases.
108108
static bool addLastRelease(SILValue V, SILBasicBlock *BB,
109-
llvm::SmallVectorImpl<SILInstruction*> &Releases) {
109+
SmallVectorImpl<SILInstruction *> &Releases) {
110110
for (auto I = BB->rbegin(); I != BB->rend(); ++I) {
111111
if (isa<StrongReleaseInst>(*I) || isa<DeallocBoxInst>(*I) ||
112112
isa<DestroyValueInst>(*I)) {
@@ -124,11 +124,10 @@ static bool addLastRelease(SILValue V, SILBasicBlock *BB,
124124
// Find the final releases of the alloc_box along any given path.
125125
// These can include paths from a release back to the alloc_box in a
126126
// loop.
127-
static bool
128-
getFinalReleases(SILValue Box,
129-
llvm::SmallVectorImpl<SILInstruction *> &Releases) {
130-
llvm::SmallPtrSet<SILBasicBlock*, 16> LiveIn;
131-
llvm::SmallPtrSet<SILBasicBlock*, 16> UseBlocks;
127+
static bool getFinalReleases(SILValue Box,
128+
SmallVectorImpl<SILInstruction *> &Releases) {
129+
SmallPtrSet<SILBasicBlock *, 16> LiveIn;
130+
SmallPtrSet<SILBasicBlock *, 16> UseBlocks;
132131

133132
auto *DefBB = Box->getParentBlock();
134133

@@ -138,7 +137,7 @@ getFinalReleases(SILValue Box,
138137
// We'll treat this like a liveness problem where the alloc_box is
139138
// the def. Each block that has a use of the owning pointer has the
140139
// value live-in unless it is the block with the alloc_box.
141-
llvm::SmallVector<Operand *, 32> Worklist(Box->use_begin(), Box->use_end());
140+
SmallVector<Operand *, 32> Worklist(Box->use_begin(), Box->use_end());
142141
while (!Worklist.empty()) {
143142
auto *Op = Worklist.pop_back_val();
144143
auto *User = Op->getUser();
@@ -200,7 +199,7 @@ getFinalReleases(SILValue Box,
200199
/// sorting, uniquing at the appropriate time. The reason why it makes sense to
201200
/// just use a sorted vector with std::count is because generally functions do
202201
/// not have that many arguments and even fewer promoted arguments.
203-
using ArgIndexList = llvm::SmallVector<unsigned, 8>;
202+
using ArgIndexList = SmallVector<unsigned, 8>;
204203

205204
static bool partialApplyEscapes(SILValue V, bool examineApply);
206205

@@ -220,7 +219,7 @@ static bool applyArgumentEscapes(FullApplySite Apply, Operand *O) {
220219

221220
static bool partialApplyEscapes(SILValue V, bool examineApply) {
222221
SILModuleConventions ModConv(*V->getModule());
223-
llvm::SmallVector<Operand *, 32> Worklist(V->use_begin(), V->use_end());
222+
SmallVector<Operand *, 32> Worklist(V->use_begin(), V->use_end());
224223
while (!Worklist.empty()) {
225224
Operand *Op = Worklist.pop_back_val();
226225

@@ -277,7 +276,7 @@ static bool partialApplyEscapes(SILValue V, bool examineApply) {
277276
static SILInstruction *findUnexpectedBoxUse(SILValue Box,
278277
bool examinePartialApply,
279278
bool inAppliedFunction,
280-
llvm::SmallVectorImpl<Operand *> &);
279+
SmallVectorImpl<Operand *> &);
281280

282281
/// checkPartialApplyBody - Check the body of a partial apply to see
283282
/// if the box pointer argument passed to it has uses that would
@@ -291,7 +290,7 @@ static bool checkPartialApplyBody(Operand *O) {
291290

292291
// We don't actually use these because we're not recursively
293292
// rewriting the partial applies we find.
294-
llvm::SmallVector<Operand *, 1> PromotedOperands;
293+
SmallVector<Operand *, 1> PromotedOperands;
295294
auto calleeArg = F->getArgument(ApplySite(O->getUser()).getCalleeArgIndex(*O));
296295
return !findUnexpectedBoxUse(calleeArg, /* examinePartialApply = */ false,
297296
/* inAppliedFunction = */ true,
@@ -305,18 +304,18 @@ static bool checkPartialApplyBody(Operand *O) {
305304
static SILInstruction *
306305
findUnexpectedBoxUse(SILValue Box, bool examinePartialApply,
307306
bool inAppliedFunction,
308-
llvm::SmallVectorImpl<Operand *> &PromotedOperands) {
307+
SmallVectorImpl<Operand *> &PromotedOperands) {
309308
assert((Box->getType().is<SILBoxType>()
310309
|| Box->getType()
311310
== SILType::getNativeObjectType(Box->getType().getASTContext()))
312311
&& "Expected an object pointer!");
313312

314-
llvm::SmallVector<Operand *, 4> LocalPromotedOperands;
313+
SmallVector<Operand *, 4> LocalPromotedOperands;
315314

316315
// Scan all of the uses of the retain count value, collecting all
317316
// the releases and validating that we don't have an unexpected
318317
// user.
319-
llvm::SmallVector<Operand *, 32> Worklist(Box->use_begin(), Box->use_end());
318+
SmallVector<Operand *, 32> Worklist(Box->use_begin(), Box->use_end());
320319
while (!Worklist.empty()) {
321320
auto *Op = Worklist.pop_back_val();
322321
auto *User = Op->getUser();
@@ -357,7 +356,7 @@ findUnexpectedBoxUse(SILValue Box, bool examinePartialApply,
357356

358357
/// canPromoteAllocBox - Can we promote this alloc_box to an alloc_stack?
359358
static bool canPromoteAllocBox(AllocBoxInst *ABI,
360-
llvm::SmallVectorImpl<Operand *> &PromotedOperands){
359+
SmallVectorImpl<Operand *> &PromotedOperands) {
361360
// Scan all of the uses of the address of the box to see if any
362361
// disqualifies the box from being promoted to the stack.
363362
if (auto *User = findUnexpectedBoxUse(ABI,
@@ -387,16 +386,15 @@ struct AllocBoxToStackState {
387386
SILFunctionTransform *T;
388387
bool CFGChanged = false;
389388

390-
llvm::SmallVector<AllocBoxInst *, 8> Promotable;
391-
llvm::SmallVector<Operand *, 8> PromotedOperands;
389+
SmallVector<AllocBoxInst *, 8> Promotable;
390+
SmallVector<Operand *, 8> PromotedOperands;
392391

393392
AllocBoxToStackState(SILFunctionTransform *T) : T(T) {}
394393
};
395394
} // anonymous namespace
396395

397396
static void replaceProjectBoxUsers(SILValue HeapBox, SILValue StackBox) {
398-
llvm::SmallVector<Operand *, 8> Worklist(HeapBox->use_begin(),
399-
HeapBox->use_end());
397+
SmallVector<Operand *, 8> Worklist(HeapBox->use_begin(), HeapBox->use_end());
400398
while (!Worklist.empty()) {
401399
auto *Op = Worklist.pop_back_val();
402400
if (auto *PBI = dyn_cast<ProjectBoxInst>(Op->getUser())) {
@@ -427,7 +425,7 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
427425
}
428426
}
429427

430-
llvm::SmallVector<SILInstruction *, 4> FinalReleases;
428+
SmallVector<SILInstruction *, 4> FinalReleases;
431429
if (!getFinalReleases(HeapBox, FinalReleases))
432430
return false;
433431

@@ -472,7 +470,7 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
472470
// Remove any retain and release instructions. Since all uses of project_box
473471
// are gone, this only walks through uses of the box itself (the retain count
474472
// pointer).
475-
llvm::SmallVector<SILInstruction *, 8> Worklist;
473+
SmallVector<SILInstruction *, 8> Worklist;
476474
std::transform(ABI->use_begin(), ABI->use_end(), std::back_inserter(Worklist),
477475
[](Operand *Op) -> SILInstruction * { return Op->getUser(); });
478476
while (!Worklist.empty()) {
@@ -514,12 +512,12 @@ class PromotedParamCloner : public SILClonerWithScopes<PromotedParamCloner> {
514512

515513
// The values in the original function that are promoted to stack
516514
// references.
517-
llvm::SmallSet<SILValue, 4> OrigPromotedParameters;
515+
SmallPtrSet<SILValue, 4> OrigPromotedParameters;
518516

519517
public:
520-
PromotedParamCloner(SILOptFunctionBuilder &FuncBuilder, SILFunction *Orig, IsSerialized_t Serialized,
521-
ArgIndexList &PromotedArgIndices,
522-
llvm::StringRef ClonedName);
518+
PromotedParamCloner(SILOptFunctionBuilder &FuncBuilder, SILFunction *Orig,
519+
IsSerialized_t Serialized,
520+
ArgIndexList &PromotedArgIndices, StringRef ClonedName);
523521

524522
void populateCloned();
525523

@@ -529,7 +527,7 @@ class PromotedParamCloner : public SILClonerWithScopes<PromotedParamCloner> {
529527
static SILFunction *initCloned(SILOptFunctionBuilder &FuncBuilder,
530528
SILFunction *Orig, IsSerialized_t Serialized,
531529
ArgIndexList &PromotedArgIndices,
532-
llvm::StringRef ClonedName);
530+
StringRef ClonedName);
533531

534532
void visitStrongReleaseInst(StrongReleaseInst *Inst);
535533
void visitDestroyValueInst(DestroyValueInst *Inst);
@@ -543,10 +541,9 @@ PromotedParamCloner::PromotedParamCloner(SILOptFunctionBuilder &FuncBuilder,
543541
SILFunction *Orig,
544542
IsSerialized_t Serialized,
545543
ArgIndexList &PromotedArgIndices,
546-
llvm::StringRef ClonedName)
547-
: SILClonerWithScopes<PromotedParamCloner>(
548-
*initCloned(FuncBuilder, Orig, Serialized, PromotedArgIndices,
549-
ClonedName)),
544+
StringRef ClonedName)
545+
: SILClonerWithScopes<PromotedParamCloner>(*initCloned(
546+
FuncBuilder, Orig, Serialized, PromotedArgIndices, ClonedName)),
550547
Orig(Orig), PromotedArgIndices(PromotedArgIndices) {
551548
NewPromotedArgs.reserve(PromotedArgIndices.size());
552549
assert(Orig->getDebugScope()->getParentFunction() !=
@@ -566,10 +563,11 @@ static std::string getClonedName(SILFunction *F, IsSerialized_t Serialized,
566563
/// Create the function corresponding to the clone of the
567564
/// original closure with the signature modified to reflect promoted
568565
/// parameters (which are specified by PromotedArgIndices).
569-
SILFunction *PromotedParamCloner::
570-
initCloned(SILOptFunctionBuilder &FuncBuilder, SILFunction *Orig,
571-
IsSerialized_t Serialized, ArgIndexList &PromotedArgIndices,
572-
llvm::StringRef ClonedName) {
566+
SILFunction *PromotedParamCloner::initCloned(SILOptFunctionBuilder &FuncBuilder,
567+
SILFunction *Orig,
568+
IsSerialized_t Serialized,
569+
ArgIndexList &PromotedArgIndices,
570+
StringRef ClonedName) {
573571
SILModule &M = Orig->getModule();
574572

575573
SmallVector<SILParameterInfo, 4> ClonedInterfaceArgTys;
@@ -776,7 +774,7 @@ specializePartialApply(SILOptFunctionBuilder &FuncBuilder,
776774
}
777775

778776
// Now create the new partial_apply using the cloned function.
779-
llvm::SmallVector<SILValue, 16> Args;
777+
SmallVector<SILValue, 16> Args;
780778

781779
ValueLifetimeAnalysis::Frontier PAFrontier;
782780

0 commit comments

Comments
 (0)