mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-01 00:33:09 +00:00
add support for phi translation and incorpation of new expression.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90782 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d84ea47b89
commit
6fcca1cc87
@ -16,6 +16,22 @@
|
||||
#include "llvm/Analysis/InstructionSimplify.h"
|
||||
using namespace llvm;
|
||||
|
||||
static bool CanPHITrans(Instruction *Inst) {
|
||||
if (isa<PHINode>(Inst) ||
|
||||
isa<BitCastInst>(Inst) ||
|
||||
isa<GetElementPtrInst>(Inst))
|
||||
return true;
|
||||
|
||||
if (Inst->getOpcode() == Instruction::And &&
|
||||
isa<ConstantInt>(Inst->getOperand(1)))
|
||||
return true;
|
||||
|
||||
// cerr << "MEMDEP: Could not PHI translate: " << *Pointer;
|
||||
// if (isa<BitCastInst>(PtrInst) || isa<GetElementPtrInst>(PtrInst))
|
||||
// cerr << "OP:\t\t\t\t" << *PtrInst->getOperand(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// IsPotentiallyPHITranslatable - If this needs PHI translation, return true
|
||||
/// if we have some hope of doing it. This should be used as a filter to
|
||||
/// avoid calling PHITranslateValue in hopeless situations.
|
||||
@ -23,18 +39,7 @@ bool PHITransAddr::IsPotentiallyPHITranslatable() const {
|
||||
// If the input value is not an instruction, or if it is not defined in CurBB,
|
||||
// then we don't need to phi translate it.
|
||||
Instruction *Inst = dyn_cast<Instruction>(Addr);
|
||||
if (isa<PHINode>(Inst) ||
|
||||
isa<BitCastInst>(Inst) ||
|
||||
isa<GetElementPtrInst>(Inst) ||
|
||||
(Inst->getOpcode() == Instruction::And &&
|
||||
isa<ConstantInt>(Inst->getOperand(1))))
|
||||
return true;
|
||||
|
||||
// cerr << "MEMDEP: Could not PHI translate: " << *Pointer;
|
||||
// if (isa<BitCastInst>(PtrInst) || isa<GetElementPtrInst>(PtrInst))
|
||||
// cerr << "OP:\t\t\t\t" << *PtrInst->getOperand(0);
|
||||
|
||||
return false;
|
||||
return Inst == 0 || CanPHITrans(Inst);
|
||||
}
|
||||
|
||||
|
||||
@ -44,18 +49,44 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
|
||||
Instruction *Inst = dyn_cast<Instruction>(V);
|
||||
if (Inst == 0) return V;
|
||||
|
||||
// If 'Inst' is defined in this block, it must be an input that needs to be
|
||||
// phi translated or an intermediate expression that needs to be incorporated
|
||||
// into the expression.
|
||||
if (Inst->getParent() == CurBB) {
|
||||
assert(std::count(InstInputs.begin(), InstInputs.end(), Inst) &&
|
||||
"Not an input?");
|
||||
|
||||
// If this is a PHI, go ahead and translate it.
|
||||
if (PHINode *PN = dyn_cast<PHINode>(Inst))
|
||||
return PN->getIncomingValueForBlock(PredBB);
|
||||
|
||||
|
||||
// If this is a non-phi value, and it is analyzable, we can incorporate it
|
||||
// into the expression by making all instruction operands be inputs.
|
||||
if (!CanPHITrans(Inst))
|
||||
return 0;
|
||||
|
||||
// Okay, we can incorporate it, this instruction is no longer an input.
|
||||
InstInputs.erase(std::find(InstInputs.begin(), InstInputs.end(), Inst));
|
||||
|
||||
// All instruction operands are now inputs (and of course, they may also be
|
||||
// defined in this block, so they may need to be phi translated themselves.
|
||||
for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i)
|
||||
if (Instruction *Op = dyn_cast<Instruction>(Inst->getOperand(i)))
|
||||
InstInputs.push_back(Op);
|
||||
|
||||
} else {
|
||||
// Determine whether 'Inst' is an input to our PHI translatable expression.
|
||||
bool isInput = std::count(InstInputs.begin(), InstInputs.end(), Inst);
|
||||
|
||||
// If 'Inst' is not defined in this block, it is either an input, or an
|
||||
// intermediate result.
|
||||
if (Inst->getParent() != CurBB) {
|
||||
// If it is an input, then it remains an input.
|
||||
// If it is an input defined in a different block, then it remains an input.
|
||||
if (isInput)
|
||||
return Inst;
|
||||
}
|
||||
|
||||
// Otherwise, it must be an intermediate result. See if its operands need
|
||||
// to be phi translated, and if so, reconstruct it.
|
||||
// Ok, it must be an intermediate result (either because it started that way
|
||||
// or because we just incorporated it into the expression). See if its
|
||||
// operands need to be phi translated, and if so, reconstruct it.
|
||||
|
||||
if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) {
|
||||
Value *PHIIn = PHITranslateSubExpr(BC->getOperand(0), CurBB, PredBB);
|
||||
@ -159,14 +190,6 @@ Value *PHITransAddr::PHITranslateSubExpr(Value *V, BasicBlock *CurBB,
|
||||
|
||||
// Otherwise, we failed.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Otherwise, it is defined in this block. It must be an input and must be
|
||||
// phi translated.
|
||||
assert(isInput && "Instruction defined in block must be an input");
|
||||
|
||||
|
||||
abort(); // unimplemented so far.
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user