[llvm-commits] CVS: llvm/lib/Target/X86/X86RegisterInfo.h X86RegisterInfo.cpp
Alkis Evlogimenos
alkis at niobe.cs.uiuc.edu
Mon Feb 16 22:34:01 PST 2004
Changes in directory llvm/lib/Target/X86:
X86RegisterInfo.h updated: 1.21 -> 1.22
X86RegisterInfo.cpp updated: 1.48 -> 1.49
---
Log message:
Add API to check and fold memory operands into instructions.
---
Diffs of the changes: (+86 -0)
Index: llvm/lib/Target/X86/X86RegisterInfo.h
diff -u llvm/lib/Target/X86/X86RegisterInfo.h:1.21 llvm/lib/Target/X86/X86RegisterInfo.h:1.22
--- llvm/lib/Target/X86/X86RegisterInfo.h:1.21 Sat Feb 14 13:49:54 2004
+++ llvm/lib/Target/X86/X86RegisterInfo.h Mon Feb 16 22:33:17 2004
@@ -42,6 +42,11 @@
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;
Index: llvm/lib/Target/X86/X86RegisterInfo.cpp
diff -u llvm/lib/Target/X86/X86RegisterInfo.cpp:1.48 llvm/lib/Target/X86/X86RegisterInfo.cpp:1.49
--- llvm/lib/Target/X86/X86RegisterInfo.cpp:1.48 Sat Feb 14 18:15:37 2004
+++ llvm/lib/Target/X86/X86RegisterInfo.cpp Mon Feb 16 22:33:17 2004
@@ -79,6 +79,87 @@
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
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list