Implement initial prolog/epilog code insertion methods.
authorChris Lattner <sabre@nondot.org>
Sun, 29 Feb 2004 05:18:30 +0000 (05:18 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 29 Feb 2004 05:18:30 +0000 (05:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11979 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Sparc/SparcRegisterInfo.cpp
lib/Target/Sparc/SparcRegisterInfo.td
lib/Target/SparcV8/SparcV8RegisterInfo.cpp
lib/Target/SparcV8/SparcV8RegisterInfo.td

index 7f576f956b597c0887a70594cf66b2119644dd9f..fda45ff3cef45953945ab6d98fae9c488802e6a0 100644 (file)
 
 #include "SparcV8.h"
 #include "SparcV8RegisterInfo.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Type.h"
+#include "Support/STLExtras.h"
 using namespace llvm;
 
 SparcV8RegisterInfo::SparcV8RegisterInfo()
@@ -60,18 +63,23 @@ SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
   abort();
 }
 
-void SparcV8RegisterInfo::processFunctionBeforeFrameFinalized(
-    MachineFunction &MF) const {
-  abort();
-}
+void SparcV8RegisterInfo::
+processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
 
 void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
-  abort();
+  MachineBasicBlock &MBB = MF.front();
+
+  // Eventually this should emit the correct save instruction based on the
+  // number of bytes in the frame.  For now we just hardcode it.
+  BuildMI(MBB, MBB.begin(), V8::SAVEi, 2, V8::SP).addImm(-122).addReg(V8::SP);
 }
 
 void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
                                        MachineBasicBlock &MBB) const {
-  abort();
+  MachineBasicBlock::iterator MBBI = prior(MBB.end());
+  assert(MBBI->getOpcode() == V8::JMPLi &&
+         "Can only put epilog before return instruction!");
+  BuildMI(MBB, MBBI, V8::RESTOREi, 2, V8::O0).addImm(0).addReg(V8::L7);
 }
 
 
index 84b4c316025f8c7799c28f26becafd1573885285..ccc3be6e44970e095bf650217998b3e6471680c9 100644 (file)
@@ -26,6 +26,9 @@ let Namespace = "V8" in {
   def I0 : Ri<24>;    def I1 : Ri<25>;    def I2 : Ri<26>;    def I3 : Ri<27>;
   def I4 : Ri<28>;    def I5 : Ri<29>;    def I6 : Ri<30>;    def I7 : Ri<31>;
 
+  // Standard register aliases.
+  def SP : Ri<14>;    def FP : Ri<30>;
+
   // Floating-point registers?
   // ...
 }
index 7f576f956b597c0887a70594cf66b2119644dd9f..fda45ff3cef45953945ab6d98fae9c488802e6a0 100644 (file)
 
 #include "SparcV8.h"
 #include "SparcV8RegisterInfo.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Type.h"
+#include "Support/STLExtras.h"
 using namespace llvm;
 
 SparcV8RegisterInfo::SparcV8RegisterInfo()
@@ -60,18 +63,23 @@ SparcV8RegisterInfo::eliminateFrameIndex(MachineFunction &MF,
   abort();
 }
 
-void SparcV8RegisterInfo::processFunctionBeforeFrameFinalized(
-    MachineFunction &MF) const {
-  abort();
-}
+void SparcV8RegisterInfo::
+processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
 
 void SparcV8RegisterInfo::emitPrologue(MachineFunction &MF) const {
-  abort();
+  MachineBasicBlock &MBB = MF.front();
+
+  // Eventually this should emit the correct save instruction based on the
+  // number of bytes in the frame.  For now we just hardcode it.
+  BuildMI(MBB, MBB.begin(), V8::SAVEi, 2, V8::SP).addImm(-122).addReg(V8::SP);
 }
 
 void SparcV8RegisterInfo::emitEpilogue(MachineFunction &MF,
                                        MachineBasicBlock &MBB) const {
-  abort();
+  MachineBasicBlock::iterator MBBI = prior(MBB.end());
+  assert(MBBI->getOpcode() == V8::JMPLi &&
+         "Can only put epilog before return instruction!");
+  BuildMI(MBB, MBBI, V8::RESTOREi, 2, V8::O0).addImm(0).addReg(V8::L7);
 }
 
 
index 84b4c316025f8c7799c28f26becafd1573885285..ccc3be6e44970e095bf650217998b3e6471680c9 100644 (file)
@@ -26,6 +26,9 @@ let Namespace = "V8" in {
   def I0 : Ri<24>;    def I1 : Ri<25>;    def I2 : Ri<26>;    def I3 : Ri<27>;
   def I4 : Ri<28>;    def I5 : Ri<29>;    def I6 : Ri<30>;    def I7 : Ri<31>;
 
+  // Standard register aliases.
+  def SP : Ri<14>;    def FP : Ri<30>;
+
   // Floating-point registers?
   // ...
 }