diff options
author | Alkis Evlogimenos <alkis@evlogimenos.com> | 2004-02-17 04:33:18 +0000 |
---|---|---|
committer | Alkis Evlogimenos <alkis@evlogimenos.com> | 2004-02-17 04:33:18 +0000 |
commit | b499866c05cac0e97a22c5e1f477c89096be836b (patch) | |
tree | 92f6eb47d687ec0dbd9666fd4752a9cab7cc6526 /lib | |
parent | 55b5481255f0bf0bff73c8b5087004198ac87213 (diff) | |
download | external_llvm-b499866c05cac0e97a22c5e1f477c89096be836b.zip external_llvm-b499866c05cac0e97a22c5e1f477c89096be836b.tar.gz external_llvm-b499866c05cac0e97a22c5e1f477c89096be836b.tar.bz2 |
Add API to check and fold memory operands into instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.cpp | 81 | ||||
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.h | 5 |
2 files changed, 86 insertions, 0 deletions
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index 59be5fb..01a3f07 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -79,6 +79,87 @@ int X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB, return 1; } +bool X86RegisterInfo::canFoldMemoryOperand(MachineInstr* MI, + unsigned i) const +{ + switch(MI->getOpcode()) { + case X86::ADDrr8: case X86::ADDrr16: case X86::ADDrr32: + case X86::ADDri8: case X86::ADDri16: case X86::ADDri32: + case X86::MOVrr8: case X86::MOVrr16: case X86::MOVrr32: + return true; + default: + return false; + } +} + +int X86RegisterInfo::foldMemoryOperand(MachineInstr* MI, + unsigned i, + int FrameIndex) const +{ + MachineBasicBlock& MBB = *MI->getParent(); + MachineInstr* NI = 0; + if (i == 0) + switch(MI->getOpcode()) { + case X86::MOVrr8: + NI = addFrameReference(BuildMI(X86::MOVmr8, 5), FrameIndex).addReg(MI->getOperand(1).getReg()); + break; + case X86::MOVrr16: + NI = addFrameReference(BuildMI(X86::MOVmr16, 5), FrameIndex).addReg(MI->getOperand(1).getReg()); + break; + case X86::MOVrr32: + NI = addFrameReference(BuildMI(X86::MOVmr32, 5), FrameIndex).addReg(MI->getOperand(1).getReg()); + break; + case X86::ADDrr8: + NI = addFrameReference(BuildMI(X86::ADDmr8, 5), FrameIndex).addReg(MI->getOperand(1).getReg()); + break; + case X86::ADDrr16: + NI = addFrameReference(BuildMI(X86::ADDmr16, 5), FrameIndex).addReg(MI->getOperand(1).getReg()); + break; + case X86::ADDrr32: + NI = addFrameReference(BuildMI(X86::ADDmr32, 5), FrameIndex).addReg(MI->getOperand(1).getReg()); + break; + case X86::ADDri8: + NI = addFrameReference(BuildMI(X86::ADDmi8, 5), FrameIndex).addZImm(MI->getOperand(1).getImmedValue()); + break; + case X86::ADDri16: + NI = addFrameReference(BuildMI(X86::ADDmi16, 5), FrameIndex).addZImm(MI->getOperand(1).getImmedValue()); + break; + case X86::ADDri32: + NI = addFrameReference(BuildMI(X86::ADDmi32, 5), FrameIndex).addZImm(MI->getOperand(1).getImmedValue()); + break; + default: + assert(0 && "Operand cannot be folded"); + } + else if (i == 1) + switch(MI->getOpcode()) { + case X86::MOVrr8: + NI = addFrameReference(BuildMI(X86::MOVrm8, 5).addReg(MI->getOperand(0).getReg()), FrameIndex); + break; + case X86::MOVrr16: + NI = addFrameReference(BuildMI(X86::MOVrm16, 5).addReg(MI->getOperand(0).getReg()), FrameIndex); + break; + case X86::MOVrr32: + NI = addFrameReference(BuildMI(X86::MOVrm32, 5).addReg(MI->getOperand(0).getReg()), FrameIndex); + break; + case X86::ADDrr8: + NI = addFrameReference(BuildMI(X86::ADDrm8, 5).addReg(MI->getOperand(0).getReg()), FrameIndex); + break; + case X86::ADDrr16: + NI = addFrameReference(BuildMI(X86::ADDrm16, 5).addReg(MI->getOperand(0).getReg()), FrameIndex); + break; + case X86::ADDrr32: + NI = addFrameReference(BuildMI(X86::ADDrm32, 5).addReg(MI->getOperand(0).getReg()), FrameIndex); + break; + default: + assert(0 && "Operand cannot be folded"); + } + else + assert(0 && "Operand cannot be folded"); + + MBB.insert(MBB.erase(MI), NI); + return 0; +} + //===----------------------------------------------------------------------===// // Stack Frame Processing methods //===----------------------------------------------------------------------===// diff --git a/lib/Target/X86/X86RegisterInfo.h b/lib/Target/X86/X86RegisterInfo.h index 9549555..711bfe1 100644 --- a/lib/Target/X86/X86RegisterInfo.h +++ b/lib/Target/X86/X86RegisterInfo.h @@ -42,6 +42,11 @@ struct X86RegisterInfo : public X86GenRegisterInfo { unsigned DestReg, unsigned SrcReg, const TargetRegisterClass *RC) const; + virtual bool canFoldMemoryOperand(MachineInstr* MI, unsigned i) const; + + virtual int foldMemoryOperand(MachineInstr* MI, unsigned i, + int FrameIndex) const; + void eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const; |