|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 | 12 |
|
13 |
| -#include "llvm/ADT/STLExtras.h" |
14 |
| -#include "swift/SIL/SILBasicBlock.h" |
15 | 13 | #include "swift/SIL/SILArgument.h"
|
| 14 | +#include "swift/Basic/GraphNodeWorklist.h" |
| 15 | +#include "swift/SIL/SILBasicBlock.h" |
16 | 16 | #include "swift/SIL/SILFunction.h"
|
17 | 17 | #include "swift/SIL/SILInstruction.h"
|
18 | 18 | #include "swift/SIL/SILModule.h"
|
| 19 | +#include "llvm/ADT/STLExtras.h" |
19 | 20 |
|
20 | 21 | using namespace swift;
|
21 | 22 |
|
@@ -226,6 +227,31 @@ bool SILPhiArgument::getIncomingPhiValues(
|
226 | 227 | return true;
|
227 | 228 | }
|
228 | 229 |
|
| 230 | +bool SILPhiArgument::visitTransitiveIncomingPhiOperands( |
| 231 | + function_ref<bool(SILPhiArgument *, Operand *)> visitor) { |
| 232 | + if (!isPhi()) |
| 233 | + return false; |
| 234 | + |
| 235 | + GraphNodeWorklist<SILPhiArgument *, 4> worklist; |
| 236 | + worklist.initialize(this); |
| 237 | + |
| 238 | + while (auto *argument = worklist.pop()) { |
| 239 | + llvm::SmallVector<Operand *> operands; |
| 240 | + argument->getIncomingPhiOperands(operands); |
| 241 | + |
| 242 | + for (auto *operand : operands) { |
| 243 | + SILPhiArgument *forwarded; |
| 244 | + if ((forwarded = dyn_cast<SILPhiArgument>(operand->get())) && |
| 245 | + forwarded->isPhi()) { |
| 246 | + worklist.insert(forwarded); |
| 247 | + } |
| 248 | + if (!visitor(argument, operand)) |
| 249 | + return false; |
| 250 | + } |
| 251 | + } |
| 252 | + return true; |
| 253 | +} |
| 254 | + |
229 | 255 | static SILValue
|
230 | 256 | getSingleTerminatorOperandForPred(const SILBasicBlock *parentBlock,
|
231 | 257 | const SILBasicBlock *predBlock,
|
|
0 commit comments