Skip to content

Commit cb0c527

Browse files
authored
Merge pull request #40733 from eeckstein/rename-libswiftpassinvocation
2 parents 43324e8 + 3522ba1 commit cb0c527

File tree

7 files changed

+56
-42
lines changed

7 files changed

+56
-42
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class SILInstruction : public llvm::ilist_node<SILInstruction> {
368368
SILInstructionResultArray getResultsImpl() const;
369369

370370
protected:
371-
friend class LibswiftPassInvocation;
371+
friend class SwiftPassInvocation;
372372

373373
SILInstruction() {
374374
NumCreatedInstructions++;

include/swift/SIL/SILInstructionWorklist.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,13 @@ template <typename VectorT = std::vector<SILInstruction *>,
6767
class SILInstructionWorklist : SILInstructionWorklistBase {
6868
BlotSetVector<SILInstruction *, VectorT, MapT> worklist;
6969

70-
/// For invoking Swift instruction passes in Swift.
71-
LibswiftPassInvocation *libswiftPassInvocation = nullptr;
72-
7370
void operator=(const SILInstructionWorklist &rhs) = delete;
7471
SILInstructionWorklist(const SILInstructionWorklist &worklist) = delete;
7572

7673
public:
7774
SILInstructionWorklist(const char *loggingName = "InstructionWorklist")
7875
: SILInstructionWorklistBase(loggingName) {}
7976

80-
void setLibswiftPassInvocation(LibswiftPassInvocation *invocation) {
81-
libswiftPassInvocation = invocation;
82-
}
83-
8477
/// Returns true if the worklist is empty.
8578
bool isEmpty() const { return worklist.empty(); }
8679

include/swift/SILOptimizer/PassManager/PassManager.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void executePassPipelinePlan(SILModule *SM, const SILPassPipelinePlan &plan,
4545
irgen::IRGenModule *IRMod = nullptr);
4646

4747
/// Utility class to invoke Swift passes.
48-
class LibswiftPassInvocation {
48+
class SwiftPassInvocation {
4949
/// Backlink to the pass manager.
5050
SILPassManager *passManager;
5151

@@ -58,12 +58,14 @@ class LibswiftPassInvocation {
5858
/// All slabs, allocated by the pass.
5959
SILModule::SlabList allocatedSlabs;
6060

61+
void endPassRunChecks();
62+
6163
public:
62-
LibswiftPassInvocation(SILPassManager *passManager, SILFunction *function,
64+
SwiftPassInvocation(SILPassManager *passManager, SILFunction *function,
6365
SILCombiner *silCombiner) :
6466
passManager(passManager), function(function), silCombiner(silCombiner) {}
6567

66-
LibswiftPassInvocation(SILPassManager *passManager) :
68+
SwiftPassInvocation(SILPassManager *passManager) :
6769
passManager(passManager) {}
6870

6971
SILPassManager *getPassManager() const { return passManager; }
@@ -81,10 +83,16 @@ class LibswiftPassInvocation {
8183
void notifyChanges(SILAnalysis::InvalidationKind invalidationKind);
8284

8385
/// Called by the pass manager before the pass starts running.
84-
void startPassRun(SILFunction *function);
86+
void startFunctionPassRun(SILFunction *function);
87+
88+
/// Called by the SILCombiner before the instruction pass starts running.
89+
void startInstructionPassRun(SILInstruction *inst);
8590

8691
/// Called by the pass manager when the pass has finished.
87-
void finishedPassRun();
92+
void finishedFunctionPassRun();
93+
94+
/// Called by the SILCombiner when the instruction pass has finished.
95+
void finishedInstructionPassRun();
8896
};
8997

9098
/// The SIL pass manager.
@@ -126,7 +134,7 @@ class SILPassManager {
126134
unsigned NumPassesRun = 0;
127135

128136
/// For invoking Swift passes.
129-
LibswiftPassInvocation libswiftPassInvocation;
137+
SwiftPassInvocation swiftPassInvocation;
130138

131139
/// Change notifications, collected during a bridged pass run.
132140
SILAnalysis::InvalidationKind changeNotifications =
@@ -201,8 +209,8 @@ class SILPassManager {
201209
/// pass manager.
202210
irgen::IRGenModule *getIRGenModule() { return IRMod; }
203211

204-
LibswiftPassInvocation *getLibswiftPassInvocation() {
205-
return &libswiftPassInvocation;
212+
SwiftPassInvocation *getSwiftPassInvocation() {
213+
return &swiftPassInvocation;
206214
}
207215

208216
/// Restart the function pass pipeline on the same function
@@ -377,7 +385,7 @@ class SILPassManager {
377385
void viewCallGraph();
378386
};
379387

380-
inline void LibswiftPassInvocation::
388+
inline void SwiftPassInvocation::
381389
notifyChanges(SILAnalysis::InvalidationKind invalidationKind) {
382390
passManager->notifyPassChanges(invalidationKind);
383391
}

lib/SILOptimizer/PassManager/PassManager.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void swift::executePassPipelinePlan(SILModule *SM,
322322
SILPassManager::SILPassManager(SILModule *M, bool isMandatory,
323323
irgen::IRGenModule *IRMod)
324324
: Mod(M), IRMod(IRMod),
325-
libswiftPassInvocation(this),
325+
swiftPassInvocation(this),
326326
isMandatory(isMandatory), deserializationNotificationHandler(nullptr) {
327327
#define ANALYSIS(NAME) \
328328
Analyses.push_back(create##NAME##Analysis(Mod));
@@ -469,7 +469,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
469469
assert(changeNotifications == SILAnalysis::InvalidationKind::Nothing
470470
&& "change notifications not cleared");
471471

472-
libswiftPassInvocation.startPassRun(F);
472+
swiftPassInvocation.startFunctionPassRun(F);
473473

474474
// Run it!
475475
SFT->run();
@@ -478,7 +478,7 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) {
478478
invalidateAnalysis(F, changeNotifications);
479479
changeNotifications = SILAnalysis::InvalidationKind::Nothing;
480480
}
481-
libswiftPassInvocation.finishedPassRun();
481+
swiftPassInvocation.finishedFunctionPassRun();
482482

483483
if (SILForceVerifyAll ||
484484
SILForceVerifyAroundPass.end() !=
@@ -1078,13 +1078,13 @@ void SILPassManager::viewCallGraph() {
10781078
}
10791079

10801080
//===----------------------------------------------------------------------===//
1081-
// LibswiftPassInvocation
1081+
// SwiftPassInvocation
10821082
//===----------------------------------------------------------------------===//
10831083

10841084
static_assert(BridgedSlabCapacity == FixedSizeSlab::capacity,
10851085
"wrong bridged slab capacity");
10861086

1087-
FixedSizeSlab *LibswiftPassInvocation::allocSlab(FixedSizeSlab *afterSlab) {
1087+
FixedSizeSlab *SwiftPassInvocation::allocSlab(FixedSizeSlab *afterSlab) {
10881088
FixedSizeSlab *slab = passManager->getModule()->allocSlab();
10891089
if (afterSlab) {
10901090
allocatedSlabs.insert(std::next(afterSlab->getIterator()), *slab);
@@ -1094,7 +1094,7 @@ FixedSizeSlab *LibswiftPassInvocation::allocSlab(FixedSizeSlab *afterSlab) {
10941094
return slab;
10951095
}
10961096

1097-
FixedSizeSlab *LibswiftPassInvocation::freeSlab(FixedSizeSlab *slab) {
1097+
FixedSizeSlab *SwiftPassInvocation::freeSlab(FixedSizeSlab *slab) {
10981098
FixedSizeSlab *prev = nullptr;
10991099
assert(!allocatedSlabs.empty());
11001100
if (&allocatedSlabs.front() != slab)
@@ -1105,23 +1105,37 @@ FixedSizeSlab *LibswiftPassInvocation::freeSlab(FixedSizeSlab *slab) {
11051105
return prev;
11061106
}
11071107

1108-
void LibswiftPassInvocation::startPassRun(SILFunction *function) {
1108+
void SwiftPassInvocation::startFunctionPassRun(SILFunction *function) {
11091109
assert(!this->function && "a pass is already running");
11101110
this->function = function;
11111111
}
11121112

1113-
void LibswiftPassInvocation::finishedPassRun() {
1114-
assert(allocatedSlabs.empty() && "StackList is leaking slabs");
1113+
void SwiftPassInvocation::startInstructionPassRun(SILInstruction *inst) {
1114+
assert(inst->getFunction() == function &&
1115+
"running instruction pass on wrong function");
1116+
}
1117+
1118+
void SwiftPassInvocation::finishedFunctionPassRun() {
1119+
endPassRunChecks();
1120+
assert(function && "not running a pass");
11151121
function = nullptr;
11161122
}
11171123

1124+
void SwiftPassInvocation::finishedInstructionPassRun() {
1125+
endPassRunChecks();
1126+
}
1127+
1128+
void SwiftPassInvocation::endPassRunChecks() {
1129+
assert(allocatedSlabs.empty() && "StackList is leaking slabs");
1130+
}
1131+
11181132
//===----------------------------------------------------------------------===//
11191133
// Swift Bridging
11201134
//===----------------------------------------------------------------------===//
11211135

1122-
inline LibswiftPassInvocation *castToPassInvocation(BridgedPassContext ctxt) {
1123-
return const_cast<LibswiftPassInvocation *>(
1124-
static_cast<const LibswiftPassInvocation *>(ctxt.opaqueCtxt));
1136+
inline SwiftPassInvocation *castToPassInvocation(BridgedPassContext ctxt) {
1137+
return const_cast<SwiftPassInvocation *>(
1138+
static_cast<const SwiftPassInvocation *>(ctxt.opaqueCtxt));
11251139
}
11261140

11271141
inline FixedSizeSlab *castToSlab(BridgedSlab slab) {
@@ -1158,7 +1172,7 @@ BridgedSlab PassContext_freeSlab(BridgedPassContext passContext,
11581172

11591173
void PassContext_notifyChanges(BridgedPassContext passContext,
11601174
enum ChangeNotificationKind changeKind) {
1161-
LibswiftPassInvocation *inv = castToPassInvocation(passContext);
1175+
SwiftPassInvocation *inv = castToPassInvocation(passContext);
11621176
switch (changeKind) {
11631177
case instructionsChanged:
11641178
inv->notifyChanges(SILAnalysis::InvalidationKind::Instructions);
@@ -1185,7 +1199,7 @@ SwiftInt PassContext_isSwift51RuntimeAvailable(BridgedPassContext context) {
11851199
}
11861200

11871201
BridgedAliasAnalysis PassContext_getAliasAnalysis(BridgedPassContext context) {
1188-
LibswiftPassInvocation *invocation = castToPassInvocation(context);
1202+
SwiftPassInvocation *invocation = castToPassInvocation(context);
11891203
SILPassManager *pm = invocation->getPassManager();
11901204
return {pm->getAnalysis<AliasAnalysis>(invocation->getFunction())};
11911205
}

lib/SILOptimizer/PassManager/Passes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void runBridgedFunctionPass(BridgedFunctionPassRunFn &runFunction,
240240
llvm::errs() << "SILFunction metatype is not registered\n";
241241
abort();
242242
}
243-
runFunction({{f}, {passManager->getLibswiftPassInvocation()}});
243+
runFunction({{f}, {passManager->getSwiftPassInvocation()}});
244244
}
245245

246246
// Called from initializeSwiftModules().

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,20 +471,19 @@ void SILCombiner::eraseInstIncludingUsers(SILInstruction *inst) {
471471
/// Runs a Swift instruction pass.
472472
void SILCombiner::runSwiftInstructionPass(SILInstruction *inst,
473473
void (*runFunction)(BridgedInstructionPassCtxt)) {
474-
Worklist.setLibswiftPassInvocation(&libswiftPassInvocation);
475-
runFunction({ {inst->asSILNode()}, {&libswiftPassInvocation} });
476-
Worklist.setLibswiftPassInvocation(nullptr);
477-
libswiftPassInvocation.finishedPassRun();
474+
swiftPassInvocation.startInstructionPassRun(inst);
475+
runFunction({ {inst->asSILNode()}, {&swiftPassInvocation} });
476+
swiftPassInvocation.finishedInstructionPassRun();
478477
}
479478

480479
/// Registered briged instruction pass run functions.
481-
static llvm::StringMap<BridgedInstructionPassRunFn> libswiftInstPasses;
480+
static llvm::StringMap<BridgedInstructionPassRunFn> swiftInstPasses;
482481
static bool passesRegistered = false;
483482

484483
// Called from initializeSwiftModules().
485484
void SILCombine_registerInstructionPass(BridgedStringRef name,
486485
BridgedInstructionPassRunFn runFn) {
487-
libswiftInstPasses[getStringRef(name)] = runFn;
486+
swiftInstPasses[getStringRef(name)] = runFn;
488487
passesRegistered = true;
489488
}
490489

@@ -493,7 +492,7 @@ SILInstruction *SILCombiner::visit##INST(INST *inst) { \
493492
static BridgedInstructionPassRunFn runFunction = nullptr; \
494493
static bool runFunctionSet = false; \
495494
if (!runFunctionSet) { \
496-
runFunction = libswiftInstPasses[TAG]; \
495+
runFunction = swiftInstPasses[TAG]; \
497496
if (!runFunction && passesRegistered) { \
498497
llvm::errs() << "Swift pass " << TAG << " is not registered\n"; \
499498
abort(); \
@@ -572,7 +571,7 @@ SILTransform *swift::createSILCombine() {
572571
// SwiftFunctionPassContext
573572
//===----------------------------------------------------------------------===//
574573

575-
void LibswiftPassInvocation::eraseInstruction(SILInstruction *inst) {
574+
void SwiftPassInvocation::eraseInstruction(SILInstruction *inst) {
576575
if (silCombiner) {
577576
silCombiner->eraseInstFromFunction(*inst);
578577
} else {

lib/SILOptimizer/SILCombiner/SILCombiner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class SILCombiner :
110110
OwnershipFixupContext ownershipFixupContext;
111111

112112
/// For invoking Swift instruction passes.
113-
LibswiftPassInvocation libswiftPassInvocation;
113+
SwiftPassInvocation swiftPassInvocation;
114114

115115
public:
116116
SILCombiner(SILFunctionTransform *parentTransform,
@@ -158,7 +158,7 @@ class SILCombiner :
158158
[&](SILInstruction *I) { eraseInstFromFunction(*I); }),
159159
deBlocks(&B.getFunction()),
160160
ownershipFixupContext(getInstModCallbacks(), deBlocks),
161-
libswiftPassInvocation(parentTransform->getPassManager(),
161+
swiftPassInvocation(parentTransform->getPassManager(),
162162
parentTransform->getFunction(), this) {}
163163

164164
bool runOnFunction(SILFunction &F);

0 commit comments

Comments
 (0)