GVNSink: Make ModelledPHIs constructor linear (and avoid edge case it worries about) by avoiding getIncomingValueForBlock

llvm-svn: 313702
This commit is contained in:
Daniel Berlin 2017-09-20 00:07:27 +00:00
parent dd323297d0
commit 064cb68d18
1 changed files with 8 additions and 7 deletions

View File

@ -206,14 +206,15 @@ class ModelledPHI {
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.