Move isLoadFrom/StoreToStackSlot from MRegisterInfo to TargetInstrInfo,a far more...
authorChris Lattner <sabre@nondot.org>
Thu, 2 Feb 2006 20:12:32 +0000 (20:12 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 2 Feb 2006 20:12:32 +0000 (20:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25913 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
lib/CodeGen/VirtRegMap.cpp
lib/Target/Alpha/AlphaInstrInfo.cpp
lib/Target/Alpha/AlphaInstrInfo.h
lib/Target/Alpha/AlphaRegisterInfo.cpp
lib/Target/Alpha/AlphaRegisterInfo.h
lib/Target/PowerPC/PPCInstrInfo.cpp
lib/Target/PowerPC/PPCInstrInfo.h
lib/Target/PowerPC/PPCRegisterInfo.cpp
lib/Target/PowerPC/PPCRegisterInfo.h
lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86InstrInfo.h
lib/Target/X86/X86RegisterInfo.cpp
lib/Target/X86/X86RegisterInfo.h

index 8a4574460c972dfea2b7e6550269aadbc041cffb..313452dd9a5a8605f4bdc54b5975e616a1c9e523 100644 (file)
@@ -490,8 +490,9 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, const VirtRegMap &VRM) {
       // straight load from the virt reg slot.
       if ((MR & VirtRegMap::isRef) && !(MR & VirtRegMap::isMod)) {
         int FrameIdx;
-        if (unsigned DestReg = MRI->isLoadFromStackSlot(&MI, FrameIdx)) {
-          // If this spill slot is available, insert a copy for it!
+        if (unsigned DestReg = TII->isLoadFromStackSlot(&MI, FrameIdx)) {
+          // If this spill slot is available, turn it into a copy (or nothing)
+          // instead of leaving it as a load!
           std::map<int, unsigned>::iterator It = SpillSlotsAvailable.find(SS);
           if (FrameIdx == SS && It != SpillSlotsAvailable.end()) {
             DEBUG(std::cerr << "Promoted Load To Copy: " << MI);
index fc9ace7126a7289e59f2ec69ec16da06351be493..c64fe3bee940bdf09fe81ef8f57a8424a51e9e1a 100644 (file)
@@ -42,3 +42,22 @@ bool AlphaInstrInfo::isMoveInstr(const MachineInstr& MI,
   }
   return false;
 }
+
+unsigned 
+AlphaInstrInfo::isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const {
+  switch (MI->getOpcode()) {
+  case Alpha::LDL:
+  case Alpha::LDQ:
+  case Alpha::LDBU:
+  case Alpha::LDWU:
+  case Alpha::LDS:
+  case Alpha::LDT:
+    if (MI->getOperand(1).isFrameIndex()) {
+      FrameIndex = MI->getOperand(1).getFrameIndex();
+      return MI->getOperand(0).getReg();
+    }
+    break;
+  }
+  return 0;
+}
+
index 2ee13a0cc2c5a0160735a1b5cc588ece122838cf..5211e6fcf5723ce27dbfeb04856ceaec0eeb772b 100644 (file)
@@ -35,6 +35,8 @@ public:
   ///
   virtual bool isMoveInstr(const MachineInstr &MI,
                            unsigned &SrcReg, unsigned &DstReg) const;
+  
+  virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
 };
 
 }
index 658175d25009dc136b4d85e1ab2c0e0c5773f02f..383529b8e71e2dca36565a1f19e37955415ef2a5 100644 (file)
@@ -104,25 +104,6 @@ AlphaRegisterInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
     abort();
 }
 
-unsigned 
-AlphaRegisterInfo::isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const
-{
-  switch (MI->getOpcode()) {
-  case Alpha::LDL:
-  case Alpha::LDQ:
-  case Alpha::LDBU:
-  case Alpha::LDWU:
-  case Alpha::LDS:
-  case Alpha::LDT:
-    if (MI->getOperand(1).isFrameIndex()) {
-      FrameIndex = MI->getOperand(1).getFrameIndex();
-      return MI->getOperand(0).getReg();
-    }
-    break;
-  }
-  return 0;
-}
-
 MachineInstr *AlphaRegisterInfo::foldMemoryOperand(MachineInstr *MI,
                                                  unsigned OpNum,
                                                  int FrameIndex) const {
index 4f9fbf459786517fca0a0bdd85214e2e32267be1..0ad04b44ea88013c5f2d16e7c92c52c9c1b3657a 100644 (file)
@@ -35,8 +35,6 @@ struct AlphaRegisterInfo : public AlphaGenRegisterInfo {
                             unsigned DestReg, int FrameIndex,
                             const TargetRegisterClass *RC) const;
   
-  virtual unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
-
   MachineInstr* foldMemoryOperand(MachineInstr *MI, unsigned OpNum, 
                                   int FrameIndex) const;
 
index f1cd9f56d72f83ef9772b5bfac3f4f48bb213a78..322d027504cffcbed2da9cbc72e7a4b6b8b76e02 100644 (file)
@@ -79,6 +79,25 @@ bool PPCInstrInfo::isMoveInstr(const MachineInstr& MI,
   return false;
 }
 
+unsigned PPCInstrInfo::isLoadFromStackSlot(MachineInstr *MI, 
+                                              int &FrameIndex) const {
+  switch (MI->getOpcode()) {
+  default: break;
+  case PPC::LD:
+  case PPC::LWZ:
+  case PPC::LFS:
+  case PPC::LFD:
+    if (MI->getOperand(1).isImmediate() && !MI->getOperand(1).getImmedValue() &&
+        MI->getOperand(2).isFrameIndex()) {
+      FrameIndex = MI->getOperand(2).getFrameIndex();
+      return MI->getOperand(0).getReg();
+    }
+    break;
+  }
+  return 0;
+                                              }
+
+
 // commuteInstruction - We can commute rlwimi instructions, but only if the
 // rotate amt is zero.  We also have to munge the immediates a bit.
 MachineInstr *PPCInstrInfo::commuteInstruction(MachineInstr *MI) const {
index 59e0643e59ad59e0f06ae422254ff406f9d33afc..d0be2d6ba3ea606d288fd0c4592d733a125b688c 100644 (file)
@@ -39,6 +39,8 @@ public:
                            unsigned& sourceReg,
                            unsigned& destReg) const;
 
+  unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
+
   // commuteInstruction - We can commute rlwimi instructions, but only if the
   // rotate amt is zero.  We also have to munge the immediates a bit.
   virtual MachineInstr *commuteInstruction(MachineInstr *MI) const;
index 896c71b91a82324fe71c650f69d87fefb3b2f483..8d2037cc6b577399d1bd5f95cd312ecefa0b7e94 100644 (file)
@@ -116,24 +116,6 @@ void PPCRegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
   }
 }
 
-unsigned PPCRegisterInfo::isLoadFromStackSlot(MachineInstr *MI, 
-                                              int &FrameIndex) const {
-  switch (MI->getOpcode()) {
-  default: break;
-  case PPC::LD:
-  case PPC::LWZ:
-  case PPC::LFS:
-  case PPC::LFD:
-    if (MI->getOperand(1).isImmediate() && !MI->getOperand(1).getImmedValue() &&
-        MI->getOperand(2).isFrameIndex()) {
-      FrameIndex = MI->getOperand(2).getFrameIndex();
-      return MI->getOperand(0).getReg();
-    }
-    break;
-  }
-  return 0;
-}
-
 /// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
 /// copy instructions, turning them into load/store instructions.
 MachineInstr *PPCRegisterInfo::foldMemoryOperand(MachineInstr *MI,
index ccb757c6a5be9ddfa783f92bb7da249693a97d69..e5a94f0ff6f9c6f350712178e9ccfd198e65d951 100644 (file)
@@ -42,8 +42,6 @@ public:
                     unsigned DestReg, unsigned SrcReg,
                     const TargetRegisterClass *RC) const;
 
-  unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
-    
   /// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
   /// copy instructions, turning them into load/store instructions.
   virtual MachineInstr* foldMemoryOperand(MachineInstr* MI, unsigned OpNum,
index 9d3f3ec7e7d5d026de2e632359b268ef55f7d600..65e8ea093945618844771bbe2440c6e73eca547b 100644 (file)
@@ -41,6 +41,54 @@ bool X86InstrInfo::isMoveInstr(const MachineInstr& MI,
   return false;
 }
 
+unsigned X86InstrInfo::isLoadFromStackSlot(MachineInstr *MI, 
+                                           int &FrameIndex) const {
+  switch (MI->getOpcode()) {
+  default: break;
+  case X86::MOV8rm:
+  case X86::MOV16rm:
+  case X86::MOV32rm:
+  case X86::FpLD64m:
+  case X86::MOVSSrm:
+  case X86::MOVSDrm:
+    if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
+        MI->getOperand(3).isRegister() && MI->getOperand(4).isImmediate() &&
+        MI->getOperand(2).getImmedValue() == 1 &&
+        MI->getOperand(3).getReg() == 0 &&
+        MI->getOperand(4).getImmedValue() == 0) {
+      FrameIndex = MI->getOperand(1).getFrameIndex();
+      return MI->getOperand(0).getReg();
+    }
+    break;
+  }
+  return 0;
+}
+
+unsigned X86InstrInfo::isStoreToStackSlot(MachineInstr *MI,
+                                          int &FrameIndex) const {
+  switch (MI->getOpcode()) {
+  default: break;
+  case X86::MOV8mr:
+  case X86::MOV16mr:
+  case X86::MOV32mr:
+  case X86::FpSTP64m:
+  case X86::MOVSSmr:
+  case X86::MOVSDmr:
+    if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
+        MI->getOperand(2).isRegister() && MI->getOperand(3).isImmediate() &&
+        MI->getOperand(3).getImmedValue() == 1 &&
+        MI->getOperand(4).getReg() == 0 &&
+        MI->getOperand(5).getImmedValue() == 0) {
+      FrameIndex = MI->getOperand(1).getFrameIndex();
+      return MI->getOperand(4).getReg();
+    }
+    break;
+  }
+  return 0;
+}
+
+
+
 /// convertToThreeAddress - This method must be implemented by targets that
 /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
 /// may be able to convert a two-address instruction into a true
index d31eb9a5069461161acd3d327c989eb22da43924..654a4334cfae918de1e7dd61d61cf820647f6c87 100644 (file)
@@ -179,14 +179,14 @@ public:
   ///
   virtual const MRegisterInfo &getRegisterInfo() const { return RI; }
 
-  //
   // Return true if the instruction is a register to register move and
   // leave the source and dest operands in the passed parameters.
   //
-  virtual bool isMoveInstr(const MachineInstr& MI,
-                           unsigned& sourceReg,
-                           unsigned& destReg) const;
-
+  bool isMoveInstr(const MachineInstr& MI, unsigned& sourceReg,
+                   unsigned& destReg) const;
+  unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
+  unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
+  
   /// convertToThreeAddress - This method must be implemented by targets that
   /// set the M_CONVERTIBLE_TO_3_ADDR flag.  When this flag is set, the target
   /// may be able to convert a two-address instruction into a true
index 1c0ec8b2cfff69261a20941ec8ec2b4544f3e587..ceb0f3f2a3fe13f88982d9cd244d3d6c261b0c58 100644 (file)
@@ -116,52 +116,6 @@ void X86RegisterInfo::copyRegToReg(MachineBasicBlock &MBB,
   BuildMI(MBB, MI, Opc, 1, DestReg).addReg(SrcReg);
 }
 
-unsigned X86RegisterInfo::isLoadFromStackSlot(MachineInstr *MI, 
-                                              int &FrameIndex) const {
-  switch (MI->getOpcode()) {
-  default: break;
-  case X86::MOV8rm:
-  case X86::MOV16rm:
-  case X86::MOV32rm:
-  case X86::FpLD64m:
-  case X86::MOVSSrm:
-  case X86::MOVSDrm:
-    if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
-        MI->getOperand(3).isRegister() && MI->getOperand(4).isImmediate() &&
-        MI->getOperand(2).getImmedValue() == 1 &&
-        MI->getOperand(3).getReg() == 0 &&
-        MI->getOperand(4).getImmedValue() == 0) {
-      FrameIndex = MI->getOperand(1).getFrameIndex();
-      return MI->getOperand(0).getReg();
-    }
-    break;
-  }
-  return 0;
-}
-
-unsigned X86RegisterInfo::isStoreToStackSlot(MachineInstr *MI, 
-                                             int &FrameIndex) const {
-  switch (MI->getOpcode()) {
-  default: break;
-  case X86::MOV8mr:
-  case X86::MOV16mr:
-  case X86::MOV32mr:
-  case X86::FpSTP64m:
-  case X86::MOVSSmr:
-  case X86::MOVSDmr:
-    if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
-        MI->getOperand(2).isRegister() && MI->getOperand(3).isImmediate() &&
-        MI->getOperand(3).getImmedValue() == 1 &&
-        MI->getOperand(4).getReg() == 0 &&
-        MI->getOperand(5).getImmedValue() == 0) {
-      FrameIndex = MI->getOperand(1).getFrameIndex();
-      return MI->getOperand(4).getReg();
-    }
-    break;
-  }
-  return 0;
-}
-
 
 static MachineInstr *MakeMInst(unsigned Opcode, unsigned FrameIndex,
                                MachineInstr *MI) {
index 973fbf9f702e724939c37145aa169493697d71d1..35654ca832f71c5182c93a0732a628abcae11a32 100644 (file)
@@ -41,10 +41,6 @@ struct X86RegisterInfo : public X86GenRegisterInfo {
                     unsigned DestReg, unsigned SrcReg,
                     const TargetRegisterClass *RC) const;
 
-  unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
-  unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) 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