|
16 | 16 | #include "swift/AST/SILOptimizerRequests.h" |
17 | 17 | #include "swift/Demangling/Demangle.h" |
18 | 18 | #include "swift/SIL/ApplySite.h" |
| 19 | +#include "swift/SIL/SILBridgingUtils.h" |
19 | 20 | #include "swift/SIL/SILFunction.h" |
20 | 21 | #include "swift/SIL/SILModule.h" |
21 | 22 | #include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h" |
22 | 23 | #include "swift/SILOptimizer/Analysis/FunctionOrder.h" |
| 24 | +#include "swift/SILOptimizer/OptimizerBridging.h" |
23 | 25 | #include "swift/SILOptimizer/PassManager/PrettyStackTrace.h" |
24 | 26 | #include "swift/SILOptimizer/PassManager/Transforms.h" |
25 | 27 | #include "swift/SILOptimizer/Utils/OptimizerStatsUtils.h" |
@@ -318,8 +320,9 @@ void swift::executePassPipelinePlan(SILModule *SM, |
318 | 320 |
|
319 | 321 | SILPassManager::SILPassManager(SILModule *M, bool isMandatory, |
320 | 322 | irgen::IRGenModule *IRMod) |
321 | | - : Mod(M), IRMod(IRMod), isMandatory(isMandatory), |
322 | | - deserializationNotificationHandler(nullptr) { |
| 323 | + : Mod(M), IRMod(IRMod), |
| 324 | + libswiftPassInvocation(this, /*SILCombiner*/ nullptr), |
| 325 | + isMandatory(isMandatory), deserializationNotificationHandler(nullptr) { |
323 | 326 | #define ANALYSIS(NAME) \ |
324 | 327 | Analyses.push_back(create##NAME##Analysis(Mod)); |
325 | 328 | #include "swift/SILOptimizer/Analysis/Analysis.def" |
@@ -462,7 +465,19 @@ void SILPassManager::runPassOnFunction(unsigned TransIdx, SILFunction *F) { |
462 | 465 | SILForceVerifyAroundPass.end(), MatchFun)) { |
463 | 466 | forcePrecomputeAnalyses(F); |
464 | 467 | } |
| 468 | + |
| 469 | + assert(changeNotifications == SILAnalysis::InvalidationKind::Nothing |
| 470 | + && "change notifications not cleared"); |
| 471 | + |
| 472 | + // Run it! |
465 | 473 | SFT->run(); |
| 474 | + |
| 475 | + if (changeNotifications != SILAnalysis::InvalidationKind::Nothing) { |
| 476 | + invalidateAnalysis(F, changeNotifications); |
| 477 | + changeNotifications = SILAnalysis::InvalidationKind::Nothing; |
| 478 | + } |
| 479 | + libswiftPassInvocation.finishedPassRun(); |
| 480 | + |
466 | 481 | if (SILForceVerifyAll || |
467 | 482 | SILForceVerifyAroundPass.end() != |
468 | 483 | std::find_if(SILForceVerifyAroundPass.begin(), |
@@ -1059,3 +1074,49 @@ void SILPassManager::viewCallGraph() { |
1059 | 1074 | llvm::ViewGraph(&OCG, "callgraph"); |
1060 | 1075 | #endif |
1061 | 1076 | } |
| 1077 | + |
| 1078 | +//===----------------------------------------------------------------------===// |
| 1079 | +// LibswiftPassInvocation |
| 1080 | +//===----------------------------------------------------------------------===// |
| 1081 | + |
| 1082 | +void LibswiftPassInvocation::eraseInstruction(SILInstruction *inst) { |
| 1083 | + if (silCombiner) { |
| 1084 | + // TODO |
| 1085 | + } else { |
| 1086 | + inst->eraseFromParent(); |
| 1087 | + } |
| 1088 | +} |
| 1089 | + |
| 1090 | +void LibswiftPassInvocation::finishedPassRun() { |
| 1091 | +} |
| 1092 | + |
| 1093 | +//===----------------------------------------------------------------------===// |
| 1094 | +// Swift Bridging |
| 1095 | +//===----------------------------------------------------------------------===// |
| 1096 | + |
| 1097 | +inline LibswiftPassInvocation *castToPassInvocation(BridgedPassContext ctxt) { |
| 1098 | + return const_cast<LibswiftPassInvocation *>( |
| 1099 | + static_cast<const LibswiftPassInvocation *>(ctxt.opaqueCtxt)); |
| 1100 | +} |
| 1101 | + |
| 1102 | +void PassContext_notifyChanges(BridgedPassContext passContext, |
| 1103 | + enum ChangeNotificationKind changeKind) { |
| 1104 | + LibswiftPassInvocation *inv = castToPassInvocation(passContext); |
| 1105 | + switch (changeKind) { |
| 1106 | + case instructionsChanged: |
| 1107 | + inv->notifyChanges(SILAnalysis::InvalidationKind::Instructions); |
| 1108 | + break; |
| 1109 | + case callsChanged: |
| 1110 | + inv->notifyChanges(SILAnalysis::InvalidationKind::CallsAndInstructions); |
| 1111 | + break; |
| 1112 | + case branchesChanged: |
| 1113 | + inv->notifyChanges(SILAnalysis::InvalidationKind::BranchesAndInstructions); |
| 1114 | + break; |
| 1115 | + } |
| 1116 | +} |
| 1117 | + |
| 1118 | +void PassContext_eraseInstruction(BridgedPassContext passContext, |
| 1119 | + BridgedInstruction inst) { |
| 1120 | + castToPassInvocation(passContext)->eraseInstruction(castToInst(inst)); |
| 1121 | +} |
| 1122 | + |
0 commit comments