mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-23 20:29:30 +00:00
Factor out the code for picking integer arithmetic with immediate
opcodes into a helper function. This fixes a few places in the code which were not properly selecting the 8-bit-immediate opcodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104091 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cc6b6b9348
commit
7c2e03916c
@ -517,6 +517,30 @@ X86RegisterInfo::getFrameIndexOffset(const MachineFunction &MF, int FI) const {
|
|||||||
return Offset;
|
return Offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned getSUBriOpcode(unsigned is64Bit, int64_t Imm) {
|
||||||
|
if (is64Bit) {
|
||||||
|
if (isInt<8>(Imm))
|
||||||
|
return X86::SUB64ri8;
|
||||||
|
return X86::SUB64ri32;
|
||||||
|
} else {
|
||||||
|
if (isInt<8>(Imm))
|
||||||
|
return X86::SUB32ri8;
|
||||||
|
return X86::SUB32ri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned getADDriOpcode(unsigned is64Bit, int64_t Imm) {
|
||||||
|
if (is64Bit) {
|
||||||
|
if (isInt<8>(Imm))
|
||||||
|
return X86::ADD64ri8;
|
||||||
|
return X86::ADD64ri32;
|
||||||
|
} else {
|
||||||
|
if (isInt<8>(Imm))
|
||||||
|
return X86::ADD32ri8;
|
||||||
|
return X86::ADD32ri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void X86RegisterInfo::
|
void X86RegisterInfo::
|
||||||
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator I) const {
|
MachineBasicBlock::iterator I) const {
|
||||||
@ -536,7 +560,7 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|||||||
MachineInstr *New = 0;
|
MachineInstr *New = 0;
|
||||||
if (Old->getOpcode() == getCallFrameSetupOpcode()) {
|
if (Old->getOpcode() == getCallFrameSetupOpcode()) {
|
||||||
New = BuildMI(MF, Old->getDebugLoc(),
|
New = BuildMI(MF, Old->getDebugLoc(),
|
||||||
TII.get(Is64Bit ? X86::SUB64ri32 : X86::SUB32ri),
|
TII.get(getSUBriOpcode(Is64Bit, Amount)),
|
||||||
StackPtr)
|
StackPtr)
|
||||||
.addReg(StackPtr)
|
.addReg(StackPtr)
|
||||||
.addImm(Amount);
|
.addImm(Amount);
|
||||||
@ -548,9 +572,7 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|||||||
Amount -= CalleeAmt;
|
Amount -= CalleeAmt;
|
||||||
|
|
||||||
if (Amount) {
|
if (Amount) {
|
||||||
unsigned Opc = (Amount < 128) ?
|
unsigned Opc = getADDriOpcode(Is64Bit, Amount);
|
||||||
(Is64Bit ? X86::ADD64ri8 : X86::ADD32ri8) :
|
|
||||||
(Is64Bit ? X86::ADD64ri32 : X86::ADD32ri);
|
|
||||||
New = BuildMI(MF, Old->getDebugLoc(), TII.get(Opc), StackPtr)
|
New = BuildMI(MF, Old->getDebugLoc(), TII.get(Opc), StackPtr)
|
||||||
.addReg(StackPtr)
|
.addReg(StackPtr)
|
||||||
.addImm(Amount);
|
.addImm(Amount);
|
||||||
@ -570,9 +592,7 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
|
|||||||
// something off the stack pointer, add it back. We do this until we have
|
// something off the stack pointer, add it back. We do this until we have
|
||||||
// more advanced stack pointer tracking ability.
|
// more advanced stack pointer tracking ability.
|
||||||
if (uint64_t CalleeAmt = I->getOperand(1).getImm()) {
|
if (uint64_t CalleeAmt = I->getOperand(1).getImm()) {
|
||||||
unsigned Opc = (CalleeAmt < 128) ?
|
unsigned Opc = getSUBriOpcode(Is64Bit, CalleeAmt);
|
||||||
(Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) :
|
|
||||||
(Is64Bit ? X86::SUB64ri32 : X86::SUB32ri);
|
|
||||||
MachineInstr *Old = I;
|
MachineInstr *Old = I;
|
||||||
MachineInstr *New =
|
MachineInstr *New =
|
||||||
BuildMI(MF, Old->getDebugLoc(), TII.get(Opc),
|
BuildMI(MF, Old->getDebugLoc(), TII.get(Opc),
|
||||||
@ -690,13 +710,9 @@ void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
|
|||||||
const TargetInstrInfo &TII) {
|
const TargetInstrInfo &TII) {
|
||||||
bool isSub = NumBytes < 0;
|
bool isSub = NumBytes < 0;
|
||||||
uint64_t Offset = isSub ? -NumBytes : NumBytes;
|
uint64_t Offset = isSub ? -NumBytes : NumBytes;
|
||||||
unsigned Opc = isSub
|
unsigned Opc = isSub ?
|
||||||
? ((Offset < 128) ?
|
getSUBriOpcode(Is64Bit, Offset) :
|
||||||
(Is64Bit ? X86::SUB64ri8 : X86::SUB32ri8) :
|
getADDriOpcode(Is64Bit, Offset);
|
||||||
(Is64Bit ? X86::SUB64ri32 : X86::SUB32ri))
|
|
||||||
: ((Offset < 128) ?
|
|
||||||
(Is64Bit ? X86::ADD64ri8 : X86::ADD32ri8) :
|
|
||||||
(Is64Bit ? X86::ADD64ri32 : X86::ADD32ri));
|
|
||||||
uint64_t Chunk = (1LL << 31) - 1;
|
uint64_t Chunk = (1LL << 31) - 1;
|
||||||
DebugLoc DL = MBB.findDebugLoc(MBBI);
|
DebugLoc DL = MBB.findDebugLoc(MBBI);
|
||||||
|
|
||||||
@ -916,7 +932,8 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
|
|||||||
// size is bigger than the callers.
|
// size is bigger than the callers.
|
||||||
if (TailCallReturnAddrDelta < 0) {
|
if (TailCallReturnAddrDelta < 0) {
|
||||||
MachineInstr *MI =
|
MachineInstr *MI =
|
||||||
BuildMI(MBB, MBBI, DL, TII.get(Is64Bit? X86::SUB64ri32 : X86::SUB32ri),
|
BuildMI(MBB, MBBI, DL,
|
||||||
|
TII.get(getSUBriOpcode(Is64Bit, -TailCallReturnAddrDelta)),
|
||||||
StackPtr)
|
StackPtr)
|
||||||
.addReg(StackPtr)
|
.addReg(StackPtr)
|
||||||
.addImm(-TailCallReturnAddrDelta);
|
.addImm(-TailCallReturnAddrDelta);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user