Skip to content

Commit 17eb463

Browse files
authored
Merge pull request #33347 from gottesmm/pr-0e907fa209a6d12c8e02117c55a3d0f8989fa231
[ssa-updater] Modernize style before adding support for guaranteed parameters
2 parents 1d410fb + d064241 commit 17eb463

File tree

11 files changed

+370
-350
lines changed

11 files changed

+370
-350
lines changed

include/swift/SILOptimizer/Utils/SILSSAUpdater.h

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
#include "swift/SIL/SILValue.h"
1919

2020
namespace llvm {
21-
template<typename T> class SSAUpdaterTraits;
22-
template<typename T> class SmallVectorImpl;
23-
}
21+
22+
template <typename T>
23+
class SSAUpdaterTraits;
24+
25+
template <typename T>
26+
class SmallVectorImpl;
27+
28+
} // namespace llvm
2429

2530
namespace swift {
2631

@@ -31,7 +36,7 @@ class SILUndef;
3136

3237
/// Independent utility that canonicalizes BB arguments by reusing structurally
3338
/// equivalent arguments and replacing the original arguments with casts.
34-
SILValue replaceBBArgWithCast(SILPhiArgument *Arg);
39+
SILValue replaceBBArgWithCast(SILPhiArgument *arg);
3540

3641
/// This class updates SSA for a set of SIL instructions defined in multiple
3742
/// blocks.
@@ -40,38 +45,38 @@ class SILSSAUpdater {
4045

4146
// A map of basic block to available phi value.
4247
using AvailableValsTy = llvm::DenseMap<SILBasicBlock *, SILValue>;
43-
std::unique_ptr<AvailableValsTy> AV;
48+
std::unique_ptr<AvailableValsTy> blockToAvailableValueMap;
4449

45-
SILType ValType;
50+
SILType type;
4651

4752
// The SSAUpdaterTraits specialization uses this sentinel to mark 'new' phi
4853
// nodes (all the incoming edge arguments have this sentinel set).
49-
std::unique_ptr<SILUndef, void(*)(SILUndef *)> PHISentinel;
54+
std::unique_ptr<SILUndef, void (*)(SILUndef *)> phiSentinel;
5055

5156
// If not null updated with inserted 'phi' nodes (SILArgument).
52-
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs;
57+
SmallVectorImpl<SILPhiArgument *> *insertedPhis;
5358

5459
// Not copyable.
5560
void operator=(const SILSSAUpdater &) = delete;
5661
SILSSAUpdater(const SILSSAUpdater &) = delete;
5762

5863
public:
5964
explicit SILSSAUpdater(
60-
SmallVectorImpl<SILPhiArgument *> *InsertedPHIs = nullptr);
65+
SmallVectorImpl<SILPhiArgument *> *insertedPhis = nullptr);
6166
~SILSSAUpdater();
6267

63-
void setInsertedPhis(SmallVectorImpl<SILPhiArgument *> *insertedPhis) {
64-
InsertedPHIs = insertedPhis;
68+
void setInsertedPhis(SmallVectorImpl<SILPhiArgument *> *inputInsertedPhis) {
69+
insertedPhis = inputInsertedPhis;
6570
}
6671

6772
/// Initialize for a use of a value of type.
68-
void Initialize(SILType T);
73+
void initialize(SILType type);
6974

70-
bool HasValueForBlock(SILBasicBlock *BB) const;
71-
void AddAvailableValue(SILBasicBlock *BB, SILValue V);
75+
bool hasValueForBlock(SILBasicBlock *block) const;
76+
void addAvailableValue(SILBasicBlock *block, SILValue value);
7277

7378
/// Construct SSA for a value that is live at the *end* of a basic block.
74-
SILValue GetValueAtEndOfBlock(SILBasicBlock *BB);
79+
SILValue getValueAtEndOfBlock(SILBasicBlock *block);
7580

7681
/// Construct SSA for a value that is live in the middle of a block.
7782
/// This handles the case where the use is before a definition of the value.
@@ -85,15 +90,15 @@ class SILSSAUpdater {
8590
///
8691
/// In this case we need to insert a 'PHI' node at the beginning of BB2
8792
/// merging val_1 and val_2.
88-
SILValue GetValueInMiddleOfBlock(SILBasicBlock *BB);
93+
SILValue getValueInMiddleOfBlock(SILBasicBlock *block);
8994

90-
void RewriteUse(Operand &Op);
95+
void rewriteUse(Operand &operand);
9196

92-
void *allocate(unsigned Size, unsigned Align) const;
93-
static void deallocateSentinel(SILUndef *U);
94-
private:
97+
void *allocate(unsigned size, unsigned align) const;
98+
static void deallocateSentinel(SILUndef *undef);
9599

96-
SILValue GetValueAtEndOfBlockInternal(SILBasicBlock *BB);
100+
private:
101+
SILValue getValueAtEndOfBlockInternal(SILBasicBlock *block);
97102
};
98103

99104
/// Utility to wrap 'Operand's to deal with invalidation of
@@ -112,15 +117,15 @@ class SILSSAUpdater {
112117
/// identify the use allowing us to reconstruct the use after the branch has
113118
/// been changed.
114119
class UseWrapper {
115-
Operand *U;
116-
SILBasicBlock *Parent;
120+
Operand *wrappedUse;
121+
SILBasicBlock *parent;
117122
enum {
118123
kRegularUse,
119124
kBranchUse,
120125
kCondBranchUseTrue,
121126
kCondBranchUseFalse
122-
} Type;
123-
unsigned Idx;
127+
} type;
128+
unsigned index;
124129

125130
public:
126131

@@ -131,7 +136,7 @@ class UseWrapper {
131136
/// (ValueUseIterator) become invalid as they point to freed operands.
132137
/// Instead we store the branch's parent and the idx so that we can
133138
/// reconstruct the use.
134-
UseWrapper(Operand *Use);
139+
UseWrapper(Operand *use);
135140

136141
Operand *getOperand();
137142

lib/SILOptimizer/LoopTransforms/ArrayPropertyOpt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,13 @@ class RegionCloner : public SILCloner<RegionCloner> {
519519
return;
520520

521521
// Update SSA form.
522-
SSAUp.Initialize(V->getType());
523-
SSAUp.AddAvailableValue(OrigBB, V);
522+
SSAUp.initialize(V->getType());
523+
SSAUp.addAvailableValue(OrigBB, V);
524524
SILValue NewVal = getMappedValue(V);
525-
SSAUp.AddAvailableValue(getOpBasicBlock(OrigBB), NewVal);
525+
SSAUp.addAvailableValue(getOpBasicBlock(OrigBB), NewVal);
526526
for (auto U : UseList) {
527527
Operand *Use = U;
528-
SSAUp.RewriteUse(*Use);
528+
SSAUp.rewriteUse(*Use);
529529
}
530530
}
531531

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,8 @@ void LoopTreeOptimization::hoistLoadsAndStores(SILValue addr, SILLoop *loop, Ins
10621062
LLVM_DEBUG(llvm::dbgs() << "Creating preload " << *initialLoad);
10631063

10641064
SILSSAUpdater ssaUpdater;
1065-
ssaUpdater.Initialize(initialLoad->getType());
1066-
ssaUpdater.AddAvailableValue(preheader, initialLoad);
1065+
ssaUpdater.initialize(initialLoad->getType());
1066+
ssaUpdater.addAvailableValue(preheader, initialLoad);
10671067

10681068
// Set all stored values as available values in the ssaUpdater.
10691069
// If there are multiple stores in a block, only the last one counts.
@@ -1078,7 +1078,7 @@ void LoopTreeOptimization::hoistLoadsAndStores(SILValue addr, SILLoop *loop, Ins
10781078
if (isLoadFromAddr(dyn_cast<LoadInst>(SI->getSrc()), addr))
10791079
return;
10801080

1081-
ssaUpdater.AddAvailableValue(SI->getParent(), SI->getSrc());
1081+
ssaUpdater.addAvailableValue(SI->getParent(), SI->getSrc());
10821082
}
10831083
}
10841084

@@ -1099,7 +1099,7 @@ void LoopTreeOptimization::hoistLoadsAndStores(SILValue addr, SILLoop *loop, Ins
10991099
// If we didn't see a store in this block yet, get the current value from
11001100
// the ssaUpdater.
11011101
if (!currentVal)
1102-
currentVal = ssaUpdater.GetValueInMiddleOfBlock(block);
1102+
currentVal = ssaUpdater.getValueInMiddleOfBlock(block);
11031103
SILValue projectedValue = projectLoadValue(LI->getOperand(), addr,
11041104
currentVal, LI);
11051105
LLVM_DEBUG(llvm::dbgs() << "Replacing stored load " << *LI << " with "
@@ -1117,8 +1117,8 @@ void LoopTreeOptimization::hoistLoadsAndStores(SILValue addr, SILLoop *loop, Ins
11171117
"should have split critical edges");
11181118
SILBuilder B(succ->begin());
11191119
auto *SI = B.createStore(loc.getValue(),
1120-
ssaUpdater.GetValueInMiddleOfBlock(succ),
1121-
addr, StoreOwnershipQualifier::Unqualified);
1120+
ssaUpdater.getValueInMiddleOfBlock(succ), addr,
1121+
StoreOwnershipQualifier::Unqualified);
11221122
(void)SI;
11231123
LLVM_DEBUG(llvm::dbgs() << "Creating loop-exit store " << *SI);
11241124
}

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ static void updateSSAForUseOfValue(
131131
assert(Res->getType() == MappedValue->getType() && "The types must match");
132132

133133
insertedPhis.clear();
134-
updater.Initialize(Res->getType());
135-
updater.AddAvailableValue(Header, Res);
136-
updater.AddAvailableValue(EntryCheckBlock, MappedValue);
134+
updater.initialize(Res->getType());
135+
updater.addAvailableValue(Header, Res);
136+
updater.addAvailableValue(EntryCheckBlock, MappedValue);
137137

138138
// Because of the way that phi nodes are represented we have to collect all
139139
// uses before we update SSA. Modifying one phi node can invalidate another
@@ -155,7 +155,7 @@ static void updateSSAForUseOfValue(
155155

156156
assert(user->getParent() != EntryCheckBlock
157157
&& "The entry check block should dominate the header");
158-
updater.RewriteUse(*use);
158+
updater.rewriteUse(*use);
159159
}
160160
// Canonicalize inserted phis to avoid extra BB Args.
161161
for (SILPhiArgument *arg : insertedPhis) {

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,13 @@ updateSSA(SILModule &M, SILLoop *Loop,
334334
if (!Loop->contains(Use->getUser()->getParent()))
335335
UseList.push_back(UseWrapper(Use));
336336
// Update SSA of use with the available values.
337-
SSAUp.Initialize(OrigValue->getType());
338-
SSAUp.AddAvailableValue(OrigValue->getParentBlock(), OrigValue);
337+
SSAUp.initialize(OrigValue->getType());
338+
SSAUp.addAvailableValue(OrigValue->getParentBlock(), OrigValue);
339339
for (auto NewValue : MapEntry.second)
340-
SSAUp.AddAvailableValue(NewValue->getParentBlock(), NewValue);
340+
SSAUp.addAvailableValue(NewValue->getParentBlock(), NewValue);
341341
for (auto U : UseList) {
342342
Operand *Use = U;
343-
SSAUp.RewriteUse(*Use);
343+
SSAUp.rewriteUse(*Use);
344344
}
345345
}
346346
}

lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
244244
// lifetime respecting loops.
245245
SmallVector<SILPhiArgument *, 8> insertedPhis;
246246
SILSSAUpdater updater(&insertedPhis);
247-
updater.Initialize(optionalEscapingClosureTy);
247+
updater.initialize(optionalEscapingClosureTy);
248248

249249
// Create an Optional<() -> ()>.none in the entry block of the function and
250250
// add it as an available value to the SSAUpdater.
@@ -256,7 +256,7 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
256256
SILBuilderWithScope b(fn.getEntryBlock()->begin());
257257
return b.createOptionalNone(loc, optionalEscapingClosureTy);
258258
}();
259-
updater.AddAvailableValue(fn.getEntryBlock(), entryBlockOptionalNone);
259+
updater.addAvailableValue(fn.getEntryBlock(), entryBlockOptionalNone);
260260

261261
// Create a copy of the convert_escape_to_no_escape and add it as an available
262262
// value to the SSA updater.
@@ -270,7 +270,7 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
270270
cvt->setLifetimeGuaranteed();
271271
cvt->setOperand(innerCVI);
272272
SILBuilderWithScope b(std::next(cvt->getIterator()));
273-
updater.AddAvailableValue(
273+
updater.addAvailableValue(
274274
cvt->getParent(),
275275
b.createOptionalSome(loc, innerCVI, optionalEscapingClosureTy));
276276
return innerCVI;
@@ -284,13 +284,13 @@ static void extendLifetimeToEndOfFunction(SILFunction &fn,
284284
{
285285
// Before the copy value, insert an extra destroy_value to handle
286286
// loops. Since we used our enum value this is safe.
287-
SILValue v = updater.GetValueInMiddleOfBlock(cvi->getParent());
287+
SILValue v = updater.getValueInMiddleOfBlock(cvi->getParent());
288288
SILBuilderWithScope(cvi).createDestroyValue(loc, v);
289289
}
290290

291291
for (auto *block : exitingBlocks) {
292292
auto *safeDestructionPt = getDeinitSafeClosureDestructionPoint(block);
293-
SILValue v = updater.GetValueAtEndOfBlock(block);
293+
SILValue v = updater.getValueAtEndOfBlock(block);
294294
SILBuilderWithScope(safeDestructionPt).createDestroyValue(loc, v);
295295
}
296296

@@ -849,15 +849,15 @@ static bool fixupCopyBlockWithoutEscaping(CopyBlockWithoutEscapingInst *cb,
849849

850850
SmallVector<SILPhiArgument *, 8> insertedPhis;
851851
SILSSAUpdater updater(&insertedPhis);
852-
updater.Initialize(optionalEscapingClosureTy);
852+
updater.initialize(optionalEscapingClosureTy);
853853

854854
// Create the Optional.none as the beginning available value.
855855
SILValue entryBlockOptionalNone;
856856
{
857857
SILBuilderWithScope b(fn.getEntryBlock()->begin());
858858
entryBlockOptionalNone =
859859
b.createOptionalNone(autoGenLoc, optionalEscapingClosureTy);
860-
updater.AddAvailableValue(fn.getEntryBlock(), entryBlockOptionalNone);
860+
updater.addAvailableValue(fn.getEntryBlock(), entryBlockOptionalNone);
861861
}
862862
assert(entryBlockOptionalNone);
863863

@@ -872,7 +872,7 @@ static bool fixupCopyBlockWithoutEscaping(CopyBlockWithoutEscapingInst *cb,
872872
// operand consumed at +1, so we don't need a copy) to it.
873873
auto *result = b.createOptionalSome(autoGenLoc, sentinelClosure,
874874
optionalEscapingClosureTy);
875-
updater.AddAvailableValue(result->getParent(), result);
875+
updater.addAvailableValue(result->getParent(), result);
876876
return result;
877877
}();
878878

@@ -881,22 +881,22 @@ static bool fixupCopyBlockWithoutEscaping(CopyBlockWithoutEscapingInst *cb,
881881
if (singleDestroy) {
882882
SILBuilderWithScope b(std::next(singleDestroy->getIterator()));
883883
auto *result = b.createOptionalNone(autoGenLoc, optionalEscapingClosureTy);
884-
updater.AddAvailableValue(result->getParent(), result);
884+
updater.addAvailableValue(result->getParent(), result);
885885
}
886886

887887
// Now that we have all of our available values, insert a destroy_value before
888888
// the initial Optional.some value using the SSA updater to ensure that we
889889
// handle loops correctly.
890890
{
891-
SILValue v = updater.GetValueInMiddleOfBlock(initialValue->getParent());
891+
SILValue v = updater.getValueInMiddleOfBlock(initialValue->getParent());
892892
SILBuilderWithScope(initialValue).createDestroyValue(autoGenLoc, v);
893893
}
894894

895895
// And insert an is_escaping_closure, cond_fail, destroy_value at each of the
896896
// lifetime end points. This ensures we do not expand our lifetime too much.
897897
if (singleDestroy) {
898898
SILBuilderWithScope b(std::next(singleDestroy->getIterator()));
899-
SILValue v = updater.GetValueInMiddleOfBlock(singleDestroy->getParent());
899+
SILValue v = updater.getValueInMiddleOfBlock(singleDestroy->getParent());
900900
SILValue isEscaping =
901901
b.createIsEscapingClosure(loc, v, IsEscapingClosureInst::ObjCEscaping);
902902
b.createCondFail(loc, isEscaping, "non-escaping closure has escaped");
@@ -911,7 +911,7 @@ static bool fixupCopyBlockWithoutEscaping(CopyBlockWithoutEscapingInst *cb,
911911

912912
for (auto *block : exitingBlocks) {
913913
auto *safeDestructionPt = getDeinitSafeClosureDestructionPoint(block);
914-
SILValue v = updater.GetValueAtEndOfBlock(block);
914+
SILValue v = updater.getValueAtEndOfBlock(block);
915915
SILBuilderWithScope(safeDestructionPt).createDestroyValue(autoGenLoc, v);
916916
}
917917
}

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
686686
// have multiple insertion points if we are storing exactly the same value
687687
// implying that we can just copy firstVal at each insertion point.
688688
SILSSAUpdater updater(&insertedPhiNodes);
689-
updater.Initialize(loadTy);
689+
updater.initialize(loadTy);
690690

691691
Optional<SILValue> singularValue;
692692
for (auto *insertPt : insertPts) {
@@ -707,7 +707,7 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
707707
}
708708

709709
// And then put the value into the SSA updater.
710-
updater.AddAvailableValue(insertPt->getParent(), eltVal);
710+
updater.addAvailableValue(insertPt->getParent(), eltVal);
711711
}
712712

713713
// If we only are tracking a singular value, we do not need to construct
@@ -727,7 +727,7 @@ AvailableValueAggregator::aggregateFullyAvailableValue(SILType loadTy,
727727
}
728728

729729
// Finally, grab the value from the SSA updater.
730-
SILValue result = updater.GetValueInMiddleOfBlock(B.getInsertionBB());
730+
SILValue result = updater.getValueInMiddleOfBlock(B.getInsertionBB());
731731
assert(result.getOwnershipKind().isCompatibleWith(ValueOwnershipKind::Owned));
732732
if (isTake() || !B.hasOwnership()) {
733733
return result;
@@ -863,7 +863,7 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
863863
// never have the same value along all paths unless we have a trivial value
864864
// meaning the SSA updater given a non-trivial value must /always/ be used.
865865
SILSSAUpdater updater(&insertedPhiNodes);
866-
updater.Initialize(loadTy);
866+
updater.initialize(loadTy);
867867

868868
Optional<SILValue> singularValue;
869869
for (auto *i : insertPts) {
@@ -881,7 +881,7 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
881881
singularValue = SILValue();
882882
}
883883

884-
updater.AddAvailableValue(i->getParent(), eltVal);
884+
updater.addAvailableValue(i->getParent(), eltVal);
885885
}
886886

887887
SILBasicBlock *insertBlock = B.getInsertionBB();
@@ -902,7 +902,7 @@ SILValue AvailableValueAggregator::handlePrimitiveValue(SILType loadTy,
902902
}
903903

904904
// Finally, grab the value from the SSA updater.
905-
SILValue eltVal = updater.GetValueInMiddleOfBlock(insertBlock);
905+
SILValue eltVal = updater.getValueInMiddleOfBlock(insertBlock);
906906
assert(!B.hasOwnership() ||
907907
eltVal.getOwnershipKind().isCompatibleWith(ValueOwnershipKind::Owned));
908908
assert(eltVal->getType() == loadTy && "Subelement types mismatch");

0 commit comments

Comments
 (0)