|
30 | 30 | #include "swift/Basic/Range.h"
|
31 | 31 | #include "llvm/Support/Debug.h"
|
32 | 32 | #include "llvm/ADT/DenseSet.h"
|
| 33 | +#include "llvm/ADT/PostOrderIterator.h" |
33 | 34 | #include "llvm/ADT/StringSet.h"
|
34 | 35 | #include "llvm/Support/CommandLine.h"
|
35 | 36 | using namespace swift;
|
@@ -3212,6 +3213,27 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
|
3212 | 3213 | SILVisitor::visitSILBasicBlock(BB);
|
3213 | 3214 | }
|
3214 | 3215 |
|
| 3216 | + void visitSILBasicBlocks(SILFunction *F) { |
| 3217 | + // Visit all basic blocks in the RPOT order. |
| 3218 | + // This ensures that any open_existential instructions, which |
| 3219 | + // open archetypes, are seen before the uses of these archetypes. |
| 3220 | + llvm::ReversePostOrderTraversal<SILFunction *> RPOT(F); |
| 3221 | + llvm::DenseSet<SILBasicBlock *> VisitedBBs; |
| 3222 | + for (auto Iter = RPOT.begin(), E = RPOT.end(); Iter != E; ++Iter) { |
| 3223 | + auto *BB = *Iter; |
| 3224 | + VisitedBBs.insert(BB); |
| 3225 | + visitSILBasicBlock(BB); |
| 3226 | + } |
| 3227 | + |
| 3228 | + // Visit all basic blocks that were not visited during the RPOT traversal, |
| 3229 | + // e.g. unrechable basic blocks. |
| 3230 | + for (auto &BB : *F) { |
| 3231 | + if (VisitedBBs.count(&BB)) |
| 3232 | + continue; |
| 3233 | + visitSILBasicBlock(&BB); |
| 3234 | + } |
| 3235 | + } |
| 3236 | + |
3215 | 3237 | void visitSILFunction(SILFunction *F) {
|
3216 | 3238 | PrettyStackTraceSILFunction stackTrace("verifying", F);
|
3217 | 3239 |
|
@@ -3262,7 +3284,13 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
|
3262 | 3284 | verifyEpilogBlocks(F);
|
3263 | 3285 | verifyStackHeight(F);
|
3264 | 3286 | verifyBranches(F);
|
3265 |
| - SILVisitor::visitSILFunction(F); |
| 3287 | + |
| 3288 | + visitSILBasicBlocks(F); |
| 3289 | + |
| 3290 | + // Verify archetypes after all basic blocks are visited, |
| 3291 | + // because we build the map of archteypes as we visit the |
| 3292 | + // instructions. |
| 3293 | + verifyOpenedArchetypes(F); |
3266 | 3294 | }
|
3267 | 3295 |
|
3268 | 3296 | void verify() {
|
|
0 commit comments