void setAliasAnalysis(AliasAnalysis* A) { AA = A; }
void setMemDep(MemoryDependenceAnalysis* M) { MD = M; }
void setDomTree(DominatorTree* D) { DT = D; }
+ uint32_t getNextUnusedValueNumber() { return nextValueNumber; }
};
}
return changed;
}
+ uint32_t nextNum = VN.getNextUnusedValueNumber();
unsigned num = VN.lookup_or_add(I);
// Allocations are always uniquely numbered, so we can save time and memory
// by fast failing them.
- if (isa<AllocationInst>(I)) {
+ if (isa<AllocationInst>(I) || isa<TerminatorInst>(I)) {
localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
return false;
}
} else {
localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
}
+
+ // If the number we were assigned was a brand new VN, then we don't
+ // need to do a lookup to see if the number already exists
+ // somewhere in the domtree: it can't!
+ } else if (num == nextNum) {
+ localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
+
// Perform value-number based elimination
} else if (Value* repl = lookupNumber(I->getParent(), num)) {
// Remove it!
I->replaceAllUsesWith(repl);
toErase.push_back(I);
return true;
- } else if (!I->isTerminator()) {
+ } else {
localAvail[I->getParent()]->table.insert(std::make_pair(num, I));
}
Value* op = BI->getOperand(i);
if (isa<Argument>(op) || isa<Constant>(op) || isa<GlobalValue>(op))
PREInstr->setOperand(i, op);
- else if (!lookupNumber(PREPred, VN.lookup(op))) {
- success = false;
- break;
- } else
- PREInstr->setOperand(i, lookupNumber(PREPred, VN.lookup(op)));
+ else {
+ Value* V = lookupNumber(PREPred, VN.lookup(op));
+ if (!V) {
+ success = false;
+ break;
+ } else
+ PREInstr->setOperand(i, V);
+ }
}
// Fail out if we encounter an operand that is not available in