mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
Add support for inferring values for the default cases of switches.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111971 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3197380143
commit
dae90c6afb
@ -671,9 +671,28 @@ LVILatticeVal LVIQuery::getEdgeValue(BasicBlock *BBFrom, BasicBlock *BBTo) {
|
|||||||
// If the edge was formed by a switch on the value, then we may know exactly
|
// If the edge was formed by a switch on the value, then we may know exactly
|
||||||
// what it is.
|
// what it is.
|
||||||
if (SwitchInst *SI = dyn_cast<SwitchInst>(BBFrom->getTerminator())) {
|
if (SwitchInst *SI = dyn_cast<SwitchInst>(BBFrom->getTerminator())) {
|
||||||
// If BBTo is the default destination of the switch, we don't know anything.
|
// If BBTo is the default destination of the switch, we know that it
|
||||||
// Given a more powerful range analysis we could know stuff.
|
// doesn't have the same value as any of the cases.
|
||||||
if (SI->getCondition() == Val && SI->getDefaultDest() != BBTo) {
|
if (SI->getCondition() == Val) {
|
||||||
|
if (SI->getDefaultDest() == BBTo) {
|
||||||
|
const IntegerType *IT = cast<IntegerType>(Val->getType());
|
||||||
|
ConstantRange CR(IT->getBitWidth());
|
||||||
|
|
||||||
|
for (unsigned i = 1, e = SI->getNumSuccessors(); i != e; ++i) {
|
||||||
|
const APInt CaseVal = SI->getCaseValue(i)->getValue();
|
||||||
|
ConstantRange CaseRange(CaseVal, CaseVal+1);
|
||||||
|
CaseRange = CaseRange.inverse();
|
||||||
|
CR = CR.intersectWith(CaseRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
LVILatticeVal Result;
|
||||||
|
if (CR.isFullSet() || CR.isEmptySet())
|
||||||
|
Result.markOverdefined();
|
||||||
|
else
|
||||||
|
Result.markConstantRange(CR);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
// We only know something if there is exactly one value that goes from
|
// We only know something if there is exactly one value that goes from
|
||||||
// BBFrom to BBTo.
|
// BBFrom to BBTo.
|
||||||
unsigned NumEdges = 0;
|
unsigned NumEdges = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user