|
19 | 19 | #include "llvm/ADT/None.h" |
20 | 20 | #include "llvm/ADT/Optional.h" |
21 | 21 | #include "llvm/ADT/STLExtras.h" |
| 22 | +#include "llvm/ADT/SetVector.h" |
22 | 23 | #include "llvm/ADT/SmallPtrSet.h" |
23 | 24 | #include "llvm/ADT/SmallString.h" |
24 | 25 | #include "llvm/ADT/SmallVector.h" |
@@ -3365,7 +3366,7 @@ void ModuleBitcodeWriter::writeFunction( |
3365 | 3366 | bool NeedsMetadataAttachment = F.hasMetadata(); |
3366 | 3367 |
|
3367 | 3368 | DILocation *LastDL = nullptr; |
3368 | | - SmallPtrSet<Function *, 4> BlockAddressUsers; |
| 3369 | + SmallSetVector<Function *, 4> BlockAddressUsers; |
3369 | 3370 |
|
3370 | 3371 | // Finally, emit all the instructions, in order. |
3371 | 3372 | for (const BasicBlock &BB : F) { |
@@ -3401,11 +3402,24 @@ void ModuleBitcodeWriter::writeFunction( |
3401 | 3402 | } |
3402 | 3403 |
|
3403 | 3404 | if (BlockAddress *BA = BlockAddress::lookup(&BB)) { |
3404 | | - for (User *U : BA->users()) { |
3405 | | - if (auto *I = dyn_cast<Instruction>(U)) { |
3406 | | - Function *P = I->getParent()->getParent(); |
3407 | | - if (P != &F) |
3408 | | - BlockAddressUsers.insert(P); |
| 3405 | + SmallVector<Value *, 16> BlockAddressUsersStack { BA }; |
| 3406 | + SmallPtrSet<Value *, 16> BlockAddressUsersVisited { BA }; |
| 3407 | + |
| 3408 | + while (!BlockAddressUsersStack.empty()) { |
| 3409 | + Value *V = BlockAddressUsersStack.pop_back_val(); |
| 3410 | + |
| 3411 | + for (User *U : V->users()) { |
| 3412 | + if ((isa<ConstantAggregate>(U) || isa<ConstantExpr>(U)) && |
| 3413 | + !BlockAddressUsersVisited.contains(U)) { |
| 3414 | + BlockAddressUsersStack.push_back(U); |
| 3415 | + BlockAddressUsersVisited.insert(U); |
| 3416 | + } |
| 3417 | + |
| 3418 | + if (auto *I = dyn_cast<Instruction>(U)) { |
| 3419 | + Function *P = I->getParent()->getParent(); |
| 3420 | + if (P != &F) |
| 3421 | + BlockAddressUsers.insert(P); |
| 3422 | + } |
3409 | 3423 | } |
3410 | 3424 | } |
3411 | 3425 | } |
|
0 commit comments