public:
ModelledPHI() {}
ModelledPHI(const PHINode *PN) {
+ // BasicBlock comes first so we sort by basic block pointer order, then by value pointer order.
+ SmallVector<std::pair<BasicBlock *, Value *>, 4> Ops;
for (unsigned I = 0, E = PN->getNumIncomingValues(); I != E; ++I)
- Blocks.push_back(PN->getIncomingBlock(I));
- std::sort(Blocks.begin(), Blocks.end());
-
- // This assumes the PHI is already well-formed and there aren't conflicting
- // incoming values for the same block.
- for (auto *B : Blocks)
- Values.push_back(PN->getIncomingValueForBlock(B));
+ Ops.push_back({PN->getIncomingBlock(I), PN->getIncomingValue(I)});
+ std::sort(Ops.begin(), Ops.end());
+ for (auto &P : Ops) {
+ Blocks.push_back(P.first);
+ Values.push_back(P.second);
+ }
}
/// Create a dummy ModelledPHI that will compare unequal to any other ModelledPHI
/// without the same ID.