Skip to content

Commit 96837ba

Browse files
authored
Merge pull request #5920 from gottesmm/vacation_gardening
Vacation gardening
2 parents 2127cea + 0a8c54d commit 96837ba

File tree

78 files changed

+552
-571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+552
-571
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,8 @@ class SILArgument : public ValueBase {
117117

118118
SILBasicBlock *ParentBB;
119119
const ValueDecl *Decl;
120-
public:
121-
SILArgument(SILBasicBlock *ParentBB, SILType Ty, const ValueDecl *D=nullptr);
122-
SILArgument(SILBasicBlock *ParentBB, SILBasicBlock::bbarg_iterator Pos,
123-
SILType Ty, const ValueDecl *D=nullptr);
124-
125-
SILArgument(SILFunction::iterator ParentBB, SILType Ty,
126-
const ValueDecl *D = nullptr)
127-
: SILArgument(&*ParentBB, Ty, D) {}
128-
SILArgument(SILFunction::iterator ParentBB, SILBasicBlock::bbarg_iterator Pos,
129-
SILType Ty, const ValueDecl *D = nullptr)
130-
: SILArgument(&*ParentBB, Pos, Ty, D) {}
131120

121+
public:
132122
SILBasicBlock *getParent() { return ParentBB; }
133123
const SILBasicBlock *getParent() const { return ParentBB; }
134124

@@ -149,7 +139,7 @@ class SILArgument : public ValueBase {
149139
}
150140

151141
unsigned getIndex() const {
152-
ArrayRef<SILArgument *> Args = getParent()->getBBArgs();
142+
ArrayRef<SILArgument *> Args = getParent()->getArguments();
153143
for (unsigned i = 0, e = Args.size(); i != e; ++i)
154144
if (Args[i] == this)
155145
return i;
@@ -230,10 +220,16 @@ class SILArgument : public ValueBase {
230220
}
231221

232222
private:
223+
friend class SILBasicBlock;
224+
225+
SILArgument(SILBasicBlock *ParentBB, SILType Ty,
226+
const ValueDecl *D = nullptr);
227+
SILArgument(SILBasicBlock *ParentBB, SILBasicBlock::arg_iterator Pos,
228+
SILType Ty, const ValueDecl *D = nullptr);
229+
233230
// A special constructor, only intended for use in SILBasicBlock::replaceBBArg.
234231
explicit SILArgument(SILType Ty, const ValueDecl *D =nullptr) :
235232
ValueBase(ValueKind::SILArgument, Ty), ParentBB(nullptr), Decl(D) {}
236-
friend class SILBasicBlock;
237233
void setParent(SILBasicBlock *P) { ParentBB = P; }
238234
};
239235

include/swift/SIL/SILBasicBlock.h

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,21 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
3939
/// automatically managed by the SILSuccessor class.
4040
SILSuccessor *PredList;
4141

42-
/// BBArgList - This is the list of basic block arguments for this block.
43-
std::vector<SILArgument*> BBArgList;
42+
/// This is the list of basic block arguments for this block.
43+
std::vector<SILArgument *> ArgumentList;
4444

4545
/// The ordered set of instructions in the SILBasicBlock.
4646
InstListType InstList;
4747

4848
friend struct llvm::ilist_sentinel_traits<SILBasicBlock>;
4949
friend struct llvm::ilist_traits<SILBasicBlock>;
50-
SILBasicBlock() : Parent(0) {}
50+
SILBasicBlock() : Parent(nullptr) {}
5151
void operator=(const SILBasicBlock &) = delete;
5252
void operator delete(void *Ptr, size_t) = delete;
5353

54-
public:
5554
SILBasicBlock(SILFunction *F, SILBasicBlock *afterBB = nullptr);
55+
56+
public:
5657
~SILBasicBlock();
5758

5859
/// Gets the ID (= index in the function's block list) of the block.
@@ -131,7 +132,7 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
131132
/// Note that all the instructions BEFORE the specified iterator
132133
/// stay as part of the original basic block. The old basic block is left
133134
/// without a terminator.
134-
SILBasicBlock *splitBasicBlock(iterator I);
135+
SILBasicBlock *split(iterator I);
135136

136137
/// \brief Move the basic block to after the specified basic block in the IR.
137138
/// The basic blocks must reside in the same function.
@@ -141,53 +142,47 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
141142
// SILBasicBlock Argument List Inspection and Manipulation
142143
//===--------------------------------------------------------------------===//
143144

144-
using bbarg_iterator = std::vector<SILArgument *>::iterator;
145-
using const_bbarg_iterator = std::vector<SILArgument *>::const_iterator;
145+
using arg_iterator = std::vector<SILArgument *>::iterator;
146+
using const_arg_iterator = std::vector<SILArgument *>::const_iterator;
146147

147-
bool bbarg_empty() const { return BBArgList.empty(); }
148-
size_t bbarg_size() const { return BBArgList.size(); }
149-
bbarg_iterator bbarg_begin() { return BBArgList.begin(); }
150-
bbarg_iterator bbarg_end() { return BBArgList.end(); }
151-
const_bbarg_iterator bbarg_begin() const { return BBArgList.begin(); }
152-
const_bbarg_iterator bbarg_end() const { return BBArgList.end(); }
148+
bool args_empty() const { return ArgumentList.empty(); }
149+
size_t args_size() const { return ArgumentList.size(); }
150+
arg_iterator args_begin() { return ArgumentList.begin(); }
151+
arg_iterator args_end() { return ArgumentList.end(); }
152+
const_arg_iterator args_begin() const { return ArgumentList.begin(); }
153+
const_arg_iterator args_end() const { return ArgumentList.end(); }
153154

154-
ArrayRef<SILArgument*> getBBArgs() const { return BBArgList; }
155+
ArrayRef<SILArgument *> getArguments() const { return ArgumentList; }
155156

156-
unsigned getNumBBArg() const { return BBArgList.size(); }
157-
const SILArgument *getBBArg(unsigned i) const { return BBArgList[i]; }
158-
SILArgument *getBBArg(unsigned i) { return BBArgList[i]; }
157+
unsigned getNumArguments() const { return ArgumentList.size(); }
158+
const SILArgument *getArgument(unsigned i) const { return ArgumentList[i]; }
159+
SILArgument *getArgument(unsigned i) { return ArgumentList[i]; }
159160

160161
/// Replace the \p{i}th BB arg with a new BBArg with SILType \p Ty and ValueDecl
161162
/// \p D.
162-
SILArgument *replaceBBArg(unsigned i, SILType Ty, const ValueDecl *D=nullptr);
163+
SILArgument *replaceArgument(unsigned i, SILType Ty,
164+
const ValueDecl *D = nullptr);
163165

164166
/// Erase a specific argument from the arg list.
165-
void eraseBBArg(int Index);
167+
void eraseArgument(int Index);
166168

167169
/// Allocate a new argument of type \p Ty and append it to the argument
168170
/// list. Optionally you can pass in a value decl parameter.
169-
SILArgument *createBBArg(SILType Ty, const ValueDecl *D=nullptr);
171+
SILArgument *createArgument(SILType Ty, const ValueDecl *D = nullptr);
170172

171173
/// Insert a new SILArgument with type \p Ty and \p Decl at position \p Pos.
172-
SILArgument *insertBBArg(bbarg_iterator Pos, SILType Ty,
173-
const ValueDecl *D=nullptr);
174+
SILArgument *insertArgument(arg_iterator Pos, SILType Ty,
175+
const ValueDecl *D = nullptr);
174176

175-
SILArgument *insertBBArg(unsigned Index, SILType Ty,
176-
const ValueDecl *D=nullptr) {
177-
bbarg_iterator Pos = BBArgList.begin();
177+
SILArgument *insertArgument(unsigned Index, SILType Ty,
178+
const ValueDecl *D = nullptr) {
179+
arg_iterator Pos = ArgumentList.begin();
178180
std::advance(Pos, Index);
179-
return insertBBArg(Pos, Ty, D);
181+
return insertArgument(Pos, Ty, D);
180182
}
181183

182184
/// \brief Remove all block arguments.
183-
void dropAllBBArgs() { BBArgList.clear(); }
184-
185-
/// \brief Drops all uses that belong to this basic block.
186-
void dropAllReferences() {
187-
dropAllBBArgs();
188-
for (SILInstruction &I : *this)
189-
I.dropAllReferences();
190-
}
185+
void dropAllArguments() { ArgumentList.clear(); }
191186

192187
//===--------------------------------------------------------------------===//
193188
// Predecessors and Successors
@@ -294,12 +289,19 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
294289
return &SILBasicBlock::InstList;
295290
}
296291

292+
/// \brief Drops all uses that belong to this basic block.
293+
void dropAllReferences() {
294+
dropAllArguments();
295+
for (SILInstruction &I : *this)
296+
I.dropAllReferences();
297+
}
298+
297299
private:
298300
friend class SILArgument;
299301

300302
/// BBArgument's ctor adds it to the argument list of this block.
301-
void insertArgument(bbarg_iterator Iter, SILArgument *Arg) {
302-
BBArgList.insert(Iter, Arg);
303+
void insertArgument(arg_iterator Iter, SILArgument *Arg) {
304+
ArgumentList.insert(Iter, Arg);
303305
}
304306
};
305307

include/swift/SIL/SILCloner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,12 @@ SILCloner<ImplClass>::visitSILBasicBlock(SILBasicBlock* BB) {
397397
// Only visit a successor that has not already been visited.
398398
if (BBI == BBMap.end()) {
399399
// Map the successor to a new BB.
400-
auto MappedBB = new (F.getModule()) SILBasicBlock(&F);
400+
auto *MappedBB = F.createBasicBlock();
401401
BBMap.insert(std::make_pair(Succ.getBB(), MappedBB));
402402
// Create new arguments for each of the original block's arguments.
403-
for (auto &Arg : Succ.getBB()->getBBArgs()) {
403+
for (auto &Arg : Succ.getBB()->getArguments()) {
404404
SILValue MappedArg =
405-
new (F.getModule()) SILArgument(MappedBB, getOpType(Arg->getType()));
405+
MappedBB->createArgument(getOpType(Arg->getType()));
406406

407407
ValueMap.insert(std::make_pair(Arg, MappedArg));
408408
}

include/swift/SIL/SILFunction.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ class SILFunction
619619
const SILBasicBlock &front() const { return *begin(); }
620620

621621
SILBasicBlock *createBasicBlock();
622+
SILBasicBlock *createBasicBlock(SILBasicBlock *After);
622623

623624
/// Splice the body of \p F into this function at end.
624625
void spliceBody(SILFunction *F) {
@@ -671,29 +672,29 @@ class SILFunction
671672

672673
SILArgument *getArgument(unsigned i) {
673674
assert(!empty() && "Cannot get argument of a function without a body");
674-
return begin()->getBBArg(i);
675+
return begin()->getArgument(i);
675676
}
676677

677678
const SILArgument *getArgument(unsigned i) const {
678679
assert(!empty() && "Cannot get argument of a function without a body");
679-
return begin()->getBBArg(i);
680+
return begin()->getArgument(i);
680681
}
681682

682683
ArrayRef<SILArgument *> getArguments() const {
683684
assert(!empty() && "Cannot get arguments of a function without a body");
684-
return begin()->getBBArgs();
685+
return begin()->getArguments();
685686
}
686687

687688
ArrayRef<SILArgument *> getIndirectResults() const {
688689
assert(!empty() && "Cannot get arguments of a function without a body");
689-
return begin()->getBBArgs().slice(0,
690-
getLoweredFunctionType()->getNumIndirectResults());
690+
return begin()->getArguments().slice(
691+
0, getLoweredFunctionType()->getNumIndirectResults());
691692
}
692693

693694
ArrayRef<SILArgument *> getArgumentsWithoutIndirectResults() const {
694695
assert(!empty() && "Cannot get arguments of a function without a body");
695-
return begin()->getBBArgs().slice(
696-
getLoweredFunctionType()->getNumIndirectResults());
696+
return begin()->getArguments().slice(
697+
getLoweredFunctionType()->getNumIndirectResults());
697698
}
698699

699700
const SILArgument *getSelfArgument() const {

include/swift/SIL/SILVisitor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class SILVisitor {
6868
}
6969

7070
void visitBasicBlockArguments(SILBasicBlock *BB) {
71-
for (auto argI = BB->bbarg_begin(), argEnd = BB->bbarg_end();
72-
argI != argEnd;
71+
for (auto argI = BB->args_begin(), argEnd = BB->args_end(); argI != argEnd;
7372
++argI)
7473
asImpl().visit(*argI);
7574
}

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,17 @@ class EdgeThreadingCloner : public BaseThreadingCloner {
368368
auto *Fn = BI->getFunction();
369369
auto *SrcBB = BI->getParent();
370370
auto *DestBB = BI->getDestBB();
371-
auto *EdgeBB = new (Fn->getModule()) SILBasicBlock(Fn, SrcBB);
371+
auto *EdgeBB = Fn->createBasicBlock(SrcBB);
372372

373373
// Create block arguments.
374374
unsigned ArgIdx = 0;
375375
for (auto Arg : BI->getArgs()) {
376-
assert(Arg->getType() == DestBB->getBBArg(ArgIdx)->getType() &&
376+
assert(Arg->getType() == DestBB->getArgument(ArgIdx)->getType() &&
377377
"Types must match");
378-
auto *BlockArg = EdgeBB->createBBArg(Arg->getType());
379-
ValueMap[DestBB->getBBArg(ArgIdx)] = SILValue(BlockArg);
380-
AvailVals.push_back(std::make_pair(DestBB->getBBArg(ArgIdx), BlockArg));
378+
auto *BlockArg = EdgeBB->createArgument(Arg->getType());
379+
ValueMap[DestBB->getArgument(ArgIdx)] = SILValue(BlockArg);
380+
AvailVals.push_back(
381+
std::make_pair(DestBB->getArgument(ArgIdx), BlockArg));
381382
++ArgIdx;
382383
}
383384

@@ -406,18 +407,18 @@ class BasicBlockCloner : public BaseThreadingCloner {
406407
// Create a new BB that is to be used as a target
407408
// for cloning.
408409
To = From->getParent()->createBasicBlock();
409-
for (auto *Arg : FromBB->getBBArgs()) {
410-
To->createBBArg(Arg->getType(), Arg->getDecl());
410+
for (auto *Arg : FromBB->getArguments()) {
411+
To->createArgument(Arg->getType(), Arg->getDecl());
411412
}
412413
}
413414
DestBB = To;
414415

415416
// Populate the value map so that uses of the BBArgs in the SrcBB are
416417
// replaced with the BBArgs of the DestBB.
417-
for (unsigned i = 0, e = FromBB->bbarg_size(); i != e; ++i) {
418-
ValueMap[FromBB->getBBArg(i)] = DestBB->getBBArg(i);
418+
for (unsigned i = 0, e = FromBB->args_size(); i != e; ++i) {
419+
ValueMap[FromBB->getArgument(i)] = DestBB->getArgument(i);
419420
AvailVals.push_back(
420-
std::make_pair(FromBB->getBBArg(i), DestBB->getBBArg(i)));
421+
std::make_pair(FromBB->getArgument(i), DestBB->getArgument(i)));
421422
}
422423
}
423424

lib/IRGen/IRGenSIL.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ emitPHINodesForBBArgs(IRGenSILFunction &IGF,
10411041
}
10421042
}
10431043

1044-
for (SILArgument *arg : make_range(silBB->bbarg_begin(), silBB->bbarg_end())) {
1044+
for (SILArgument *arg : make_range(silBB->args_begin(), silBB->args_end())) {
10451045
size_t first = phis.size();
10461046

10471047
const TypeInfo &ti = IGF.getTypeInfo(arg->getType());
@@ -1086,7 +1086,7 @@ static ArrayRef<SILArgument*> emitEntryPointIndirectReturn(
10861086
IGF.IndirectReturn = retTI.getAddressForPointer(params.claimNext());
10871087
}
10881088

1089-
auto bbargs = entry->getBBArgs();
1089+
auto bbargs = entry->getArguments();
10901090

10911091
// Map the indirect returns if present.
10921092
unsigned numIndirectResults = funcTy->getNumIndirectResults();
@@ -1289,11 +1289,12 @@ static void emitEntryPointArgumentsCOrObjC(IRGenSILFunction &IGF,
12891289
// Bind polymorphic arguments. This can only be done after binding
12901290
// all the value parameters, and must be done even for non-polymorphic
12911291
// functions because of imported Objective-C generics.
1292-
emitPolymorphicParameters(IGF, *IGF.CurSILFn, params, nullptr,
1293-
[&](unsigned paramIndex) -> llvm::Value* {
1294-
SILValue parameter = entry->getBBArgs()[paramIndex];
1295-
return IGF.getLoweredSingletonExplosion(parameter);
1296-
});
1292+
emitPolymorphicParameters(
1293+
IGF, *IGF.CurSILFn, params, nullptr,
1294+
[&](unsigned paramIndex) -> llvm::Value * {
1295+
SILValue parameter = entry->getArguments()[paramIndex];
1296+
return IGF.getLoweredSingletonExplosion(parameter);
1297+
});
12971298
}
12981299

12991300
/// Get metadata for the dynamic Self type if we have it.
@@ -2462,7 +2463,7 @@ static llvm::BasicBlock *emitBBMapForSwitchEnum(
24622463
//
24632464
// FIXME: This is cheesy when the destination BB has only the switch
24642465
// as a predecessor.
2465-
if (!casePair.second->bbarg_empty())
2466+
if (!casePair.second->args_empty())
24662467
dests.push_back({casePair.first,
24672468
llvm::BasicBlock::Create(IGF.IGM.getLLVMContext())});
24682469
else
@@ -2490,8 +2491,8 @@ void IRGenSILFunction::visitSwitchEnumInst(SwitchEnumInst *inst) {
24902491
// Bind arguments for cases that want them.
24912492
for (unsigned i = 0, e = inst->getNumCases(); i < e; ++i) {
24922493
auto casePair = inst->getCase(i);
2493-
2494-
if (!casePair.second->bbarg_empty()) {
2494+
2495+
if (!casePair.second->args_empty()) {
24952496
auto waypointBB = dests[i].second;
24962497
auto &destLBB = getLoweredBB(casePair.second);
24972498

@@ -2858,7 +2859,7 @@ void IRGenSILFunction::visitDynamicMethodBranchInst(DynamicMethodBranchInst *i){
28582859
&& "lowering dynamic_method_br with multiple preds for destination "
28592860
"not implemented");
28602861
// Kill the existing lowered value for the bb arg and its phi nodes.
2861-
SILValue methodArg = i->getHasMethodBB()->bbarg_begin()[0];
2862+
SILValue methodArg = i->getHasMethodBB()->args_begin()[0];
28622863
Explosion formerLLArg = getLoweredExplosion(methodArg);
28632864
for (llvm::Value *val : formerLLArg.claimAll()) {
28642865
auto phi = cast<llvm::PHINode>(val);

0 commit comments

Comments
 (0)