Skip to content

Commit 72b2c48

Browse files
authored
Merge pull request swiftlang#5769 from gottesmm/small_gardening_fixups
2 parents ea29123 + a8c4cc6 commit 72b2c48

18 files changed

+73
-65
lines changed

include/swift/SIL/SILValue.h

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,28 @@
2525
#include "llvm/Support/raw_ostream.h"
2626

2727
namespace swift {
28-
class Operand;
29-
class ValueBaseUseIterator;
30-
class ValueUseIterator;
31-
class SILBasicBlock;
32-
class SILFunction;
33-
class SILModule;
34-
class SILInstruction;
35-
class SILLocation;
36-
class DominanceInfo;
37-
38-
enum class ValueKind {
28+
29+
class DominanceInfo;
30+
class Operand;
31+
class SILBasicBlock;
32+
class SILFunction;
33+
class SILInstruction;
34+
class SILLocation;
35+
class SILModule;
36+
class ValueBaseUseIterator;
37+
class ValueUseIterator;
38+
39+
enum class ValueKind {
3940
#define VALUE(Id, Parent) Id,
40-
#define VALUE_RANGE(Id, FirstId, LastId) \
41-
First_##Id = FirstId, Last_##Id = LastId,
41+
#define VALUE_RANGE(Id, FirstId, LastId) \
42+
First_##Id = FirstId, Last_##Id = LastId,
4243
#include "swift/SIL/SILNodes.def"
43-
};
44+
};
4445

45-
/// ValueKind hashes to its underlying integer representation.
46-
static inline llvm::hash_code hash_value(ValueKind K) {
47-
return llvm::hash_value(size_t(K));
48-
}
46+
/// ValueKind hashes to its underlying integer representation.
47+
static inline llvm::hash_code hash_value(ValueKind K) {
48+
return llvm::hash_value(size_t(K));
49+
}
4950

5051
/// ValueBase - This is the base class of the SIL value hierarchy, which
5152
/// represents a runtime computed value. Things like SILInstruction derive
@@ -120,25 +121,27 @@ class alignas(8) ValueBase : public SILAllocated<ValueBase> {
120121

121122
/// If this is a SILArgument or a SILInstruction get its parent basic block,
122123
/// otherwise return null.
123-
SILBasicBlock *getParentBB();
124+
SILBasicBlock *getParentBlock() const;
124125

125126
/// If this is a SILArgument or a SILInstruction get its parent function,
126127
/// otherwise return null.
127-
SILFunction *getFunction();
128+
SILFunction *getFunction() const;
128129

129130
/// If this is a SILArgument or a SILInstruction get its parent module,
130131
/// otherwise return null.
131-
SILModule *getModule();
132+
SILModule *getModule() const;
132133
};
133134

134135
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
135136
const ValueBase &V) {
136137
V.print(OS);
137138
return OS;
138139
}
140+
139141
} // end namespace swift
140142

141143
namespace llvm {
144+
142145
/// ValueBase * is always at least eight-byte aligned; make the three tag bits
143146
/// available through PointerLikeTypeTraits.
144147
template<>
@@ -152,6 +155,7 @@ class PointerLikeTypeTraits<swift::ValueBase *> {
152155
}
153156
enum { NumLowBitsAvailable = 3 };
154157
};
158+
155159
} // end namespace llvm
156160

157161
namespace swift {

include/swift/SILOptimizer/Analysis/EpilogueARCAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ class EpilogueARCAnalysis : public FunctionAnalysisBase<EpilogueARCFunctionInfo>
279279
virtual void handleDeleteNotification(ValueBase *V) override {
280280
// If the parent function of this instruction was just turned into an
281281
// external declaration, bail. This happens during SILFunction destruction.
282-
SILFunction *F = V->getParentBB()->getParent();
282+
SILFunction *F = V->getFunction();
283283
if (F->isExternalDeclaration()) {
284284
return;
285285
}

include/swift/SILOptimizer/Analysis/RCIdentityAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class RCIdentityAnalysis : public FunctionAnalysisBase<RCIdentityFunctionInfo> {
8787
virtual void handleDeleteNotification(ValueBase *V) override {
8888
// If the parent function of this instruction was just turned into an
8989
// external declaration, bail. This happens during SILFunction destruction.
90-
SILFunction *F = V->getParentBB()->getParent();
90+
SILFunction *F = V->getFunction();
9191
if (F->isExternalDeclaration()) {
9292
return;
9393
}

lib/SIL/SILArgument.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static SILValue getIncomingValueForPred(const SILBasicBlock *BB,
6565
case TermKind::UnreachableInst:
6666
case TermKind::ReturnInst:
6767
case TermKind::ThrowInst:
68+
llvm_unreachable("Have terminator that implies no successors?!");
6869
case TermKind::TryApplyInst:
6970
case TermKind::SwitchValueInst:
7071
case TermKind::SwitchEnumAddrInst:

lib/SIL/SILPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ ID SILPrinter::getID(SILValue V) {
16831683

16841684
// Lazily initialize the instruction -> ID mapping.
16851685
if (ValueToIDMap.empty()) {
1686-
V->getParentBB()->getParent()->numberValues(ValueToIDMap);
1686+
V->getParentBlock()->getParent()->numberValues(ValueToIDMap);
16871687
}
16881688

16891689
ID R = { ID::SSAValue, ValueToIDMap[V] };

lib/SIL/SILValue.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,29 @@ static_assert(sizeof(SILValue) == sizeof(uintptr_t),
3131
// Utility Methods
3232
//===----------------------------------------------------------------------===//
3333

34-
SILBasicBlock *ValueBase::getParentBB() {
35-
if (auto Inst = dyn_cast<SILInstruction>(this))
34+
SILBasicBlock *ValueBase::getParentBlock() const {
35+
auto *NonConstThis = const_cast<ValueBase *>(this);
36+
if (auto *Inst = dyn_cast<SILInstruction>(NonConstThis))
3637
return Inst->getParent();
37-
if (auto Arg = dyn_cast<SILArgument>(this))
38+
if (auto *Arg = dyn_cast<SILArgument>(NonConstThis))
3839
return Arg->getParent();
3940
return nullptr;
4041
}
4142

42-
SILFunction *ValueBase::getFunction() {
43-
if (auto Inst = dyn_cast<SILInstruction>(this))
43+
SILFunction *ValueBase::getFunction() const {
44+
auto *NonConstThis = const_cast<ValueBase *>(this);
45+
if (auto *Inst = dyn_cast<SILInstruction>(NonConstThis))
4446
return Inst->getFunction();
45-
if (auto Arg = dyn_cast<SILArgument>(this))
47+
if (auto *Arg = dyn_cast<SILArgument>(NonConstThis))
4648
return Arg->getFunction();
4749
return nullptr;
4850
}
4951

50-
SILModule *ValueBase::getModule() {
51-
if (auto Inst = dyn_cast<SILInstruction>(this))
52+
SILModule *ValueBase::getModule() const {
53+
auto *NonConstThis = const_cast<ValueBase *>(this);
54+
if (auto *Inst = dyn_cast<SILInstruction>(NonConstThis))
5255
return &Inst->getModule();
53-
if (auto Arg = dyn_cast<SILArgument>(this))
56+
if (auto *Arg = dyn_cast<SILArgument>(NonConstThis))
5457
return &Arg->getModule();
5558
return nullptr;
5659
}

lib/SILOptimizer/Analysis/ARCAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ bool swift::getFinalReleasesForValue(SILValue V, ReleaseTracker &Tracker) {
925925
llvm::SmallPtrSet<SILBasicBlock *, 16> UseBlocks;
926926

927927
// First attempt to get the BB where this value resides.
928-
auto *DefBB = V->getParentBB();
928+
auto *DefBB = V->getParentBlock();
929929
if (!DefBB)
930930
return false;
931931

lib/SILOptimizer/Analysis/ArraySemantic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static bool canHoistArrayArgument(ApplyInst *SemanticsCall, SILValue Arr,
257257
return false;
258258

259259
ValueBase *SelfVal = Arr;
260-
auto *SelfBB = SelfVal->getParentBB();
260+
auto *SelfBB = SelfVal->getParentBlock();
261261
if (DT->dominates(SelfBB, InsertBefore->getParent()))
262262
return true;
263263

@@ -267,7 +267,7 @@ static bool canHoistArrayArgument(ApplyInst *SemanticsCall, SILValue Arr,
267267
auto Val = LI->getOperand();
268268
bool DoesNotDominate;
269269
StructElementAddrInst *SEI;
270-
while ((DoesNotDominate = !DT->dominates(Val->getParentBB(),
270+
while ((DoesNotDominate = !DT->dominates(Val->getParentBlock(),
271271
InsertBefore->getParent())) &&
272272
(SEI = dyn_cast<StructElementAddrInst>(Val)))
273273
Val = SEI->getOperand();
@@ -325,7 +325,7 @@ bool swift::ArraySemanticsCall::canHoist(SILInstruction *InsertBefore,
325325
static SILValue copyArrayLoad(SILValue ArrayStructValue,
326326
SILInstruction *InsertBefore,
327327
DominanceInfo *DT) {
328-
if (DT->dominates(ArrayStructValue->getParentBB(),
328+
if (DT->dominates(ArrayStructValue->getParentBlock(),
329329
InsertBefore->getParent()))
330330
return ArrayStructValue;
331331

@@ -334,7 +334,7 @@ static SILValue copyArrayLoad(SILValue ArrayStructValue,
334334
// Recursively move struct_element_addr.
335335
ValueBase *Val = LI->getOperand();
336336
auto *InsertPt = InsertBefore;
337-
while (!DT->dominates(Val->getParentBB(), InsertBefore->getParent())) {
337+
while (!DT->dominates(Val->getParentBlock(), InsertBefore->getParent())) {
338338
auto *Inst = cast<StructElementAddrInst>(Val);
339339
Inst->moveBefore(InsertPt);
340340
Val = Inst->getOperand();

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,8 +1842,8 @@ bool EscapeAnalysis::canEscapeTo(SILValue V, RefCountingInst *RI) {
18421842

18431843
/// Utility to get the function which contains both values \p V1 and \p V2.
18441844
static SILFunction *getCommonFunction(SILValue V1, SILValue V2) {
1845-
SILBasicBlock *BB1 = V1->getParentBB();
1846-
SILBasicBlock *BB2 = V2->getParentBB();
1845+
SILBasicBlock *BB1 = V1->getParentBlock();
1846+
SILBasicBlock *BB2 = V2->getParentBlock();
18471847
if (!BB1 || !BB2)
18481848
return nullptr;
18491849

@@ -1968,7 +1968,7 @@ void EscapeAnalysis::invalidate(SILFunction *F, InvalidationKind K) {
19681968
}
19691969

19701970
void EscapeAnalysis::handleDeleteNotification(ValueBase *I) {
1971-
if (SILBasicBlock *Parent = I->getParentBB()) {
1971+
if (SILBasicBlock *Parent = I->getParentBlock()) {
19721972
SILFunction *F = Parent->getParent();
19731973
if (FunctionInfo *FInfo = Function2Info.lookup(F)) {
19741974
if (FInfo->isValid()) {

lib/SILOptimizer/Analysis/RCIdentityAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static SILValue stripRCIdentityPreservingInsts(SILValue V) {
131131
/// dominates the BB of A.
132132
static bool dominatesArgument(DominanceInfo *DI, SILArgument *A,
133133
SILValue FirstIV) {
134-
SILBasicBlock *OtherBB = FirstIV->getParentBB();
134+
SILBasicBlock *OtherBB = FirstIV->getParentBlock();
135135
if (!OtherBB || OtherBB == A->getParent())
136136
return false;
137137
return DI->dominates(OtherBB, A->getParent());
@@ -190,7 +190,7 @@ findDominatingNonPayloadedEdge(SILBasicBlock *IncomingEdgeBB,
190190
SILValue RCIdentity) {
191191
// First grab the NonPayloadedEnumBB and RCIdentityBB. If we cannot find
192192
// either of them, return false.
193-
SILBasicBlock *RCIdentityBB = RCIdentity->getParentBB();
193+
SILBasicBlock *RCIdentityBB = RCIdentity->getParentBlock();
194194
if (!RCIdentityBB)
195195
return false;
196196

lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static bool isRangeChecked(SILValue Start, SILValue End,
689689
}
690690

691691
static bool dominates(DominanceInfo *DT, SILValue V, SILBasicBlock *B) {
692-
if (auto ValueBB = V->getParentBB())
692+
if (auto ValueBB = V->getParentBlock())
693693
return DT->dominates(ValueBB, B);
694694
return false;
695695
}

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,11 +1012,11 @@ struct HoistableMakeMutable {
10121012
MakeMutable = M;
10131013

10141014
// The function_ref needs to be invariant.
1015-
if (Loop->contains(MakeMutable->getCallee()->getParentBB()))
1015+
if (Loop->contains(MakeMutable->getCallee()->getParentBlock()))
10161016
return;
10171017

10181018
// The array reference is invariant.
1019-
if (!L->contains(M.getSelf()->getParentBB())) {
1019+
if (!L->contains(M.getSelf()->getParentBlock())) {
10201020
IsHoistable = true;
10211021
return;
10221022
}
@@ -1094,7 +1094,7 @@ struct HoistableMakeMutable {
10941094

10951095
SILValue ArrayBuffer = stripValueProjections(UncheckedRefCast->getOperand(), DepInsts);
10961096
auto *BaseLoad = dyn_cast<LoadInst>(ArrayBuffer);
1097-
if (!BaseLoad || Loop->contains(BaseLoad->getOperand()->getParentBB()))
1097+
if (!BaseLoad || Loop->contains(BaseLoad->getOperand()->getParentBlock()))
10981098
return false;
10991099
DepInsts.push_back(BaseLoad);
11001100

@@ -1105,15 +1105,15 @@ struct HoistableMakeMutable {
11051105
GetElementAddrCall.getKind() != ArrayCallKind::kGetElementAddress)
11061106
return false;
11071107
if (Loop->contains(
1108-
((ApplyInst *)GetElementAddrCall)->getCallee()->getParentBB()))
1108+
((ApplyInst *)GetElementAddrCall)->getCallee()->getParentBlock()))
11091109
return false;
1110-
if (Loop->contains(GetElementAddrCall.getIndex()->getParentBB()))
1110+
if (Loop->contains(GetElementAddrCall.getIndex()->getParentBlock()))
11111111
return false;
11121112

11131113
auto *GetElementAddrArrayLoad =
11141114
dyn_cast<LoadInst>(GetElementAddrCall.getSelf());
11151115
if (!GetElementAddrArrayLoad ||
1116-
Loop->contains(GetElementAddrArrayLoad->getOperand()->getParentBB()))
1116+
Loop->contains(GetElementAddrArrayLoad->getOperand()->getParentBlock()))
11171117
return false;
11181118

11191119
// Check the retain/release around the get_element_addr call.
@@ -1140,18 +1140,18 @@ struct HoistableMakeMutable {
11401140
if (CheckSubscript.getKind() == ArrayCallKind::kMakeMutable)
11411141
return true;
11421142

1143-
if (Loop->contains(CheckSubscript.getIndex()->getParentBB()) ||
1143+
if (Loop->contains(CheckSubscript.getIndex()->getParentBlock()) ||
11441144
Loop->contains(CheckSubscript.getArrayPropertyIsNativeTypeChecked()
1145-
->getParentBB()))
1145+
->getParentBlock()))
11461146
return false;
11471147

11481148
auto *CheckSubscriptArrayLoad =
11491149
dyn_cast<LoadInst>(CheckSubscript.getSelf());
11501150
if (!CheckSubscript ||
1151-
Loop->contains(CheckSubscriptArrayLoad->getOperand()->getParentBB()))
1151+
Loop->contains(CheckSubscriptArrayLoad->getOperand()->getParentBlock()))
11521152
return false;
11531153
if (Loop->contains(
1154-
((ApplyInst *)CheckSubscript)->getCallee()->getParentBB()))
1154+
((ApplyInst *)CheckSubscript)->getCallee()->getParentBlock()))
11551155
return false;
11561156

11571157
// The array must match get_element_addr's array.
@@ -1460,7 +1460,7 @@ bool COWArrayOpt::hoistMakeMutable(ArraySemanticsCall MakeMutable) {
14601460
// We can hoist address projections (even if they are only conditionally
14611461
// executed).
14621462
auto ArrayAddrBase = stripUnaryAddressProjections(CurrentArrayAddr);
1463-
SILBasicBlock *ArrayAddrBaseBB = ArrayAddrBase->getParentBB();
1463+
SILBasicBlock *ArrayAddrBaseBB = ArrayAddrBase->getParentBlock();
14641464

14651465
if (ArrayAddrBaseBB && !DomTree->dominates(ArrayAddrBaseBB, Preheader)) {
14661466
DEBUG(llvm::dbgs() << " Skipping Array: does not dominate loop!\n");
@@ -2043,7 +2043,7 @@ class RegionCloner : public SILCloner<RegionCloner> {
20432043
}
20442044

20452045
SILValue remapValue(SILValue V) {
2046-
if (auto *BB = V->getParentBB()) {
2046+
if (auto *BB = V->getParentBlock()) {
20472047
if (!DomTree.dominates(StartBB, BB)) {
20482048
// Must be a value that dominates the start basic block.
20492049
assert(DomTree.dominates(BB, StartBB) &&

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static bool sinkFixLifetime(SILLoop *Loop, DominanceInfo *DomTree,
348348
// Sink the fix_lifetime instruction.
349349
bool Changed = false;
350350
for (auto *FLI : FixLifetimeInsts)
351-
if (DomTree->dominates(FLI->getOperand()->getParentBB(),
351+
if (DomTree->dominates(FLI->getOperand()->getParentBlock(),
352352
Preheader)) {
353353
auto Succs = ExitingBB->getSuccessors();
354354
for (unsigned EdgeIdx = 0; EdgeIdx < Succs.size(); ++EdgeIdx) {

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class LoopCloner : public SILCloner<LoopCloner> {
5656

5757
protected:
5858
SILValue remapValue(SILValue V) {
59-
if (auto *BB = V->getParentBB()) {
59+
if (auto *BB = V->getParentBlock()) {
6060
if (!Loop->contains(BB))
6161
return V;
6262
}
@@ -314,9 +314,9 @@ updateSSA(SILLoop *Loop,
314314
UseList.push_back(UseWrapper(Use));
315315
// Update SSA of use with the available values.
316316
SSAUp.Initialize(OrigValue->getType());
317-
SSAUp.AddAvailableValue(OrigValue->getParentBB(), OrigValue);
317+
SSAUp.AddAvailableValue(OrigValue->getParentBlock(), OrigValue);
318318
for (auto NewValue : MapEntry.second)
319-
SSAUp.AddAvailableValue(NewValue->getParentBB(), NewValue);
319+
SSAUp.AddAvailableValue(NewValue->getParentBlock(), NewValue);
320320
for (auto U : UseList) {
321321
Operand *Use = U;
322322
SSAUp.RewriteUse(*Use);

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ runOnFunctionRecursively(SILFunction *F, FullApplySite AI,
360360
if (auto *II = dyn_cast<SILInstruction>(NewInst))
361361
I = II->getIterator();
362362
else
363-
I = NewInst->getParentBB()->begin();
363+
I = NewInst->getParentBlock()->begin();
364364
auto NewAI = FullApplySite::isa(NewInstPair.second.getInstruction());
365365
if (!NewAI)
366366
continue;

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3357,7 +3357,7 @@ static void tryToReplaceArgWithIncomingValue(SILBasicBlock *BB, unsigned i,
33573357
// If the incoming values of all predecessors are equal usually this means
33583358
// that the common incoming value dominates the BB. But: this might be not
33593359
// the case if BB is unreachable. Therefore we still have to check it.
3360-
if (!DT->dominates(V->getParentBB(), BB))
3360+
if (!DT->dominates(V->getParentBlock(), BB))
33613361
return;
33623362

33633363
// An argument has one result value. We need to replace this with the *value*

lib/SILOptimizer/Utils/CheckedCastBrJumpThreading.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ SILValue CheckedCastBrJumpThreading::isArgValueEquivalentToCondition(
200200
if (Def != Value)
201201
return SILValue();
202202

203-
if (!DT->dominates(DomBB, Value->getParentBB()))
203+
if (!DT->dominates(DomBB, Value->getParentBlock()))
204204
return SILValue();
205205
// OK, this value is a potential candidate
206206
}

0 commit comments

Comments
 (0)