From 5a051f65d3074126b762eaf44b30c44e996577fe Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 17 Feb 2004 05:54:57 +0000 Subject: [PATCH] Change to match the newer, simpler, interface git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11525 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86RegisterInfo.cpp | 37 ++++++------------------------ lib/Target/X86/X86RegisterInfo.h | 11 ++++++--- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index eead81fb161..d871b82b0db 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -79,24 +79,6 @@ 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::ANDrr8: case X86::ANDrr16: case X86::ANDrr32: - case X86::ANDri8: case X86::ANDri16: case X86::ANDri32: - case X86::MOVrr8: case X86::MOVrr16: case X86::MOVrr32: - return true; - case X86::IMULrr16: case X86::IMULrr32: - case X86::IMULrri16: case X86::IMULrri32: - return i == 1; - default: - return false; - } -} - static MachineInstr *MakeMRInst(unsigned Opcode, unsigned FrameIndex, MachineInstr *MI) { return addFrameReference(BuildMI(Opcode, 5), FrameIndex) @@ -122,11 +104,8 @@ static MachineInstr *MakeRMIInst(unsigned Opcode, unsigned FrameIndex, } - -int X86RegisterInfo::foldMemoryOperand(MachineInstr* MI, - unsigned i, - int FrameIndex) const -{ +bool X86RegisterInfo::foldMemoryOperand(MachineBasicBlock::iterator &MI, + unsigned i, int FrameIndex) const { /// FIXME: This should obviously be autogenerated by tablegen when patterns /// are available! MachineBasicBlock& MBB = *MI->getParent(); @@ -148,8 +127,7 @@ int X86RegisterInfo::foldMemoryOperand(MachineInstr* MI, case X86::ANDri8: NI = MakeMIInst(X86::ANDmi8 , FrameIndex, MI); break; case X86::ANDri16: NI = MakeMIInst(X86::ANDmi16, FrameIndex, MI); break; case X86::ANDri32: NI = MakeMIInst(X86::ANDmi32, FrameIndex, MI); break; - - default: assert(0 && "Operand cannot be folded"); + default: return false; // Cannot fold } } else if (i == 1) { switch(MI->getOpcode()) { @@ -166,15 +144,14 @@ int X86RegisterInfo::foldMemoryOperand(MachineInstr* MI, case X86::IMULrr32:NI = MakeRMInst(X86::IMULrm32, FrameIndex, MI); break; case X86::IMULrri16: NI = MakeRMIInst(X86::IMULrmi16, FrameIndex, MI); break; case X86::IMULrri32: NI = MakeRMIInst(X86::IMULrmi32, FrameIndex, MI); break; - - default: assert(0 && "Operand cannot be folded"); + default: return false; // cannot fold. } } else { - assert(0 && "Operand cannot be folded"); + return false; // cannot fold. } - MBB.insert(MBB.erase(MI), NI); - return 0; + MI = MBB.insert(MBB.erase(MI), NI); + return true; } //===----------------------------------------------------------------------===// diff --git a/lib/Target/X86/X86RegisterInfo.h b/lib/Target/X86/X86RegisterInfo.h index 711bfe11ebc..5d843ab729d 100644 --- a/lib/Target/X86/X86RegisterInfo.h +++ b/lib/Target/X86/X86RegisterInfo.h @@ -42,10 +42,15 @@ struct X86RegisterInfo : public X86GenRegisterInfo { unsigned DestReg, unsigned SrcReg, const TargetRegisterClass *RC) const; - virtual bool canFoldMemoryOperand(MachineInstr* MI, unsigned i) const; + /// foldMemoryOperand - If this target supports it, fold a load or store of + /// the specified stack slot into the specified machine instruction for the + /// specified operand. If this is possible, the target should perform the + /// folding and return true, otherwise it should return false. If it folds + /// the instruction, it is likely that the MachineInstruction the iterator + /// references has been changed. + virtual bool foldMemoryOperand(MachineBasicBlock::iterator &MI,unsigned OpNum, + int FrameIndex) const; - virtual int foldMemoryOperand(MachineInstr* MI, unsigned i, - int FrameIndex) const; void eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, -- 2.34.1