mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
* Implement more powerful expr analysis of cast instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1335 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0252755825
commit
882572aa68
@ -284,21 +284,30 @@ ExprType analysis::ClassifyExpression(Value *Expr) {
|
|||||||
|
|
||||||
case Instruction::Cast: {
|
case Instruction::Cast: {
|
||||||
ExprType Src(ClassifyExpression(I->getOperand(0)));
|
ExprType Src(ClassifyExpression(I->getOperand(0)));
|
||||||
if (Src.ExprTy != ExprType::Constant)
|
|
||||||
return I;
|
|
||||||
const ConstPoolInt *Offs = Src.Offset;
|
|
||||||
if (Offs == 0) return ExprType();
|
|
||||||
|
|
||||||
const Type *DestTy = I->getType();
|
const Type *DestTy = I->getType();
|
||||||
if (DestTy->isPointerType())
|
if (DestTy->isPointerType())
|
||||||
DestTy = Type::ULongTy; // Pointer types are represented as ulong
|
DestTy = Type::ULongTy; // Pointer types are represented as ulong
|
||||||
|
|
||||||
assert(DestTy->isIntegral() && "Can only handle integral types!");
|
/*
|
||||||
|
if (!Src.getExprType(0)->isLosslesslyConvertableTo(DestTy)) {
|
||||||
|
if (Src.ExprTy != ExprType::Constant)
|
||||||
|
return I; // Converting cast, and not a constant value...
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
const ConstPoolVal *CPV =ConstRules::get(*Offs)->castTo(Offs, DestTy);
|
const ConstPoolInt *Offset = Src.Offset;
|
||||||
if (!CPV) return I;
|
const ConstPoolInt *Scale = Src.Scale;
|
||||||
assert(CPV->getType()->isIntegral() && "Must have an integral type!");
|
if (Offset) {
|
||||||
return cast<ConstPoolInt>(CPV);
|
const ConstPoolVal *CPV = ConstantFoldCastInstruction(Offset, DestTy);
|
||||||
|
if (!CPV) return I;
|
||||||
|
Offset = cast<ConstPoolInt>(CPV);
|
||||||
|
}
|
||||||
|
if (Scale) {
|
||||||
|
const ConstPoolVal *CPV = ConstantFoldCastInstruction(Scale, DestTy);
|
||||||
|
if (!CPV) return I;
|
||||||
|
Scale = cast<ConstPoolInt>(CPV);
|
||||||
|
}
|
||||||
|
return ExprType(Scale, Src.Var, Offset);
|
||||||
} // end case Instruction::Cast
|
} // end case Instruction::Cast
|
||||||
// TODO: Handle SUB, SHR?
|
// TODO: Handle SUB, SHR?
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user