mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-25 16:29:20 +00:00
Expand GEP handling for constant offsets.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116594 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
824c10ece2
commit
2896df897c
@ -138,7 +138,7 @@ class ARMFastISel : public FastISel {
|
||||
bool ARMEmitLoad(EVT VT, unsigned &ResultReg, unsigned Reg, int Offset);
|
||||
bool ARMEmitStore(EVT VT, unsigned SrcReg, unsigned Reg, int Offset);
|
||||
bool ARMComputeRegOffset(const Value *Obj, unsigned &Reg, int &Offset);
|
||||
unsigned ARMSimplifyRegOffset(unsigned Reg, int &Offset);
|
||||
void ARMSimplifyRegOffset(unsigned &Reg, int &Offset, EVT VT);
|
||||
unsigned ARMMaterializeFP(const ConstantFP *CFP, EVT VT);
|
||||
unsigned ARMMaterializeInt(const Constant *C, EVT VT);
|
||||
unsigned ARMMaterializeGV(const GlobalValue *GV, EVT VT);
|
||||
@ -605,6 +605,7 @@ bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg,
|
||||
}
|
||||
case Instruction::GetElementPtr: {
|
||||
int SavedOffset = Offset;
|
||||
unsigned SavedReg = Reg;
|
||||
int TmpOffset = Offset;
|
||||
|
||||
// Iterate through the GEP folding the constants into offsets where
|
||||
@ -618,18 +619,37 @@ bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg,
|
||||
unsigned Idx = cast<ConstantInt>(Op)->getZExtValue();
|
||||
TmpOffset += SL->getElementOffset(Idx);
|
||||
} else {
|
||||
uint64_t S = TD.getTypeAllocSize(GTI.getIndexedType());
|
||||
SmallVector<const Value *, 4> Worklist;
|
||||
Worklist.push_back(Op);
|
||||
do {
|
||||
Op = Worklist.pop_back_val();
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
|
||||
// Constant-offset addressing.
|
||||
TmpOffset += CI->getSExtValue() * S;
|
||||
} else if (0 && isa<AddOperator>(Op) &&
|
||||
isa<ConstantInt>(cast<AddOperator>(Op)->getOperand(1))) {
|
||||
// An add with a constant operand. Fold the constant.
|
||||
ConstantInt *CI =
|
||||
cast<ConstantInt>(cast<AddOperator>(Op)->getOperand(1));
|
||||
TmpOffset += CI->getSExtValue() * S;
|
||||
// Add the other operand back to the work list.
|
||||
Worklist.push_back(cast<AddOperator>(Op)->getOperand(0));
|
||||
} else
|
||||
goto unsupported_gep;
|
||||
} while (!Worklist.empty());
|
||||
}
|
||||
}
|
||||
|
||||
// Try to grab the base operand now.
|
||||
Offset = TmpOffset;
|
||||
if (ARMComputeRegOffset(U->getOperand(0), Reg, Offset)) return true;
|
||||
|
||||
// We failed, restore everything and try the other options.
|
||||
Offset = SavedOffset;
|
||||
break;
|
||||
Reg = SavedReg;
|
||||
|
||||
unsupported_gep:
|
||||
// errs() << "GEP: " << *U << "\n";
|
||||
break;
|
||||
}
|
||||
case Instruction::Alloca: {
|
||||
@ -663,11 +683,10 @@ bool ARMFastISel::ARMComputeRegOffset(const Value *Obj, unsigned &Reg,
|
||||
|
||||
// Try to get this in a register if nothing else has worked.
|
||||
if (Reg == 0) Reg = getRegForValue(Obj);
|
||||
|
||||
return Reg != 0;
|
||||
}
|
||||
|
||||
unsigned ARMFastISel::ARMSimplifyRegOffset(unsigned Reg, int &Offset) {
|
||||
void ARMFastISel::ARMSimplifyRegOffset(unsigned &Reg, int &Offset, EVT VT) {
|
||||
|
||||
// Since the offset may be too large for the load instruction
|
||||
// get the reg+offset into a register.
|
||||
@ -675,21 +694,23 @@ unsigned ARMFastISel::ARMSimplifyRegOffset(unsigned Reg, int &Offset) {
|
||||
ARMCC::CondCodes Pred = ARMCC::AL;
|
||||
unsigned PredReg = 0;
|
||||
|
||||
TargetRegisterClass *RC = isThumb ? ARM::tGPRRegisterClass :
|
||||
ARM::GPRRegisterClass;
|
||||
unsigned BaseReg = createResultReg(RC);
|
||||
|
||||
if (!isThumb)
|
||||
emitARMRegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
||||
Reg, Reg, Offset, Pred, PredReg,
|
||||
BaseReg, Reg, Offset, Pred, PredReg,
|
||||
static_cast<const ARMBaseInstrInfo&>(TII));
|
||||
else {
|
||||
assert(AFI->isThumb2Function());
|
||||
emitT2RegPlusImmediate(*FuncInfo.MBB, FuncInfo.InsertPt, DL,
|
||||
Reg, Reg, Offset, Pred, PredReg,
|
||||
BaseReg, Reg, Offset, Pred, PredReg,
|
||||
static_cast<const ARMBaseInstrInfo&>(TII));
|
||||
}
|
||||
|
||||
Offset = 0;
|
||||
Reg = BaseReg;
|
||||
}
|
||||
|
||||
return Reg;
|
||||
}
|
||||
|
||||
bool ARMFastISel::ARMEmitLoad(EVT VT, unsigned &ResultReg,
|
||||
@ -767,10 +788,10 @@ bool ARMFastISel::SelectLoad(const Instruction *I) {
|
||||
if (!ARMComputeRegOffset(I->getOperand(0), Reg, Offset))
|
||||
return false;
|
||||
|
||||
unsigned BaseReg = ARMSimplifyRegOffset(Reg, Offset);
|
||||
ARMSimplifyRegOffset(Reg, Offset, VT);
|
||||
|
||||
unsigned ResultReg;
|
||||
if (!ARMEmitLoad(VT, ResultReg, BaseReg, Offset)) return false;
|
||||
if (!ARMEmitLoad(VT, ResultReg, Reg, Offset)) return false;
|
||||
|
||||
UpdateValueMap(I, ResultReg);
|
||||
return true;
|
||||
@ -846,9 +867,9 @@ bool ARMFastISel::SelectStore(const Instruction *I) {
|
||||
if (!ARMComputeRegOffset(I->getOperand(1), Reg, Offset))
|
||||
return false;
|
||||
|
||||
unsigned BaseReg = ARMSimplifyRegOffset(Reg, Offset);
|
||||
ARMSimplifyRegOffset(Reg, Offset, VT);
|
||||
|
||||
if (!ARMEmitStore(VT, SrcReg, BaseReg, Offset)) return false;
|
||||
if (!ARMEmitStore(VT, SrcReg, Reg, Offset)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user