Add completely untested support for mtcrf/mfcrf encoding
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9PrologEpilogInserter.cpp
index d852dee1ed3aca37b558d0b3db8713acac723939..47cab90601a124114ff9934734189930727eb545 100644 (file)
@@ -7,20 +7,22 @@
 // 
 //===----------------------------------------------------------------------===//
 //
-// Insert SAVE/RESTORE instructions for the function
-//
-// Insert prolog code at the unique function entry point.
-// Insert epilog code at each function exit point.
-// InsertPrologEpilog invokes these only if the function is not compiled
-// with the leaf function optimization.
+// This is the SparcV9 target's own PrologEpilogInserter. It creates prolog and
+// epilog instructions for functions which have not been compiled using "leaf
+// function optimizations". These instructions include the SAVE and RESTORE
+// instructions used to rotate the SPARC register windows. Prologs are
+// attached to the unique function entry, and epilogs are attached to each
+// function exit.
 //
 //===----------------------------------------------------------------------===//
 
 #include "SparcV9Internals.h"
 #include "SparcV9RegClassInfo.h"
+#include "SparcV9RegisterInfo.h"
+#include "SparcV9FrameInfo.h"
+#include "MachineFunctionInfo.h"
+#include "MachineCodeForInstruction.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/MachineFunctionInfo.h"
-#include "llvm/CodeGen/MachineCodeForInstruction.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/Pass.h"
 #include "llvm/Function.h"
@@ -34,7 +36,7 @@ namespace {
     const char *getPassName() const { return "SparcV9 Prolog/Epilog Inserter"; }
     
     bool runOnMachineFunction(MachineFunction &F) {
-      if (!F.getInfo()->isCompiledAsLeafMethod()) {
+      if (!F.getInfo<SparcV9FunctionInfo>()->isCompiledAsLeafMethod()) {
         InsertPrologCode(F);
         InsertEpilogCode(F);
       }
@@ -47,21 +49,14 @@ namespace {
 
 }  // End anonymous namespace
 
-//------------------------------------------------------------------------ 
-//   Create prolog and epilog code for procedure entry and exit
-//------------------------------------------------------------------------ 
-
 static unsigned getStaticStackSize (MachineFunction &MF) {
   const TargetFrameInfo& frameInfo = *MF.getTarget().getFrameInfo();
-
-  unsigned staticStackSize = MF.getInfo()->getStaticStackSize();
-
-  if (staticStackSize < (unsigned) frameInfo.getMinStackFrameSize())
-    staticStackSize = (unsigned) frameInfo.getMinStackFrameSize();
-  if (unsigned padsz = (staticStackSize %
-                        (unsigned) frameInfo.getStackFrameSizeAlignment()))
-    staticStackSize += frameInfo.getStackFrameSizeAlignment() - padsz;
-
+  unsigned staticStackSize = MF.getInfo<SparcV9FunctionInfo>()->getStaticStackSize();
+  if (staticStackSize < (unsigned)SparcV9FrameInfo::MinStackFrameSize)
+    staticStackSize = SparcV9FrameInfo::MinStackFrameSize;
+  if (unsigned padsz = staticStackSize % 
+                       SparcV9FrameInfo::StackFrameSizeAlignment)
+    staticStackSize += SparcV9FrameInfo::StackFrameSizeAlignment - padsz;
   return staticStackSize;
 }
 
@@ -74,7 +69,6 @@ void InsertPrologEpilogCode::InsertPrologCode(MachineFunction &MF)
   // The second operand is the stack size. If it does not fit in the
   // immediate field, we have to use a free register to hold the size.
   // See the comments below for the choice of this register.
-  // 
   unsigned staticStackSize = getStaticStackSize (MF);
   int32_t C = - (int) staticStackSize;
   int SP = TM.getRegInfo()->getStackPointer();
@@ -117,19 +111,17 @@ void InsertPrologEpilogCode::InsertPrologCode(MachineFunction &MF)
   // (%i0 ... %i5 if K=6) .
   // By copying the varargs arguments to the stack, va_arg() then can
   // simply assume that all vararg arguments are in an array on the stack. 
-  // 
   if (MF.getFunction()->getFunctionType()->isVarArg()) {
     int numFixedArgs    = MF.getFunction()->getFunctionType()->getNumParams();
     int numArgRegs      = TM.getRegInfo()->getNumOfIntArgRegs();
     if (numFixedArgs < numArgRegs) {
       const TargetFrameInfo &FI = *TM.getFrameInfo();
-      bool ignore;
       int firstArgReg   = TM.getRegInfo()->getUnifiedRegNum(
                              TM.getRegInfo()->getRegClassIDOfType(Type::IntTy),
                              SparcV9IntRegClass::i0);
-      int fpReg         = FI.getIncomingArgBaseRegNum();
-      int argSize       = FI.getSizeOfEachArgOnStack();
-      int firstArgOffset= FI.getFirstIncomingArgOffset(MF,ignore);
+      int fpReg         = SparcV9::i6;
+      int argSize       = 8;
+      int firstArgOffset= SparcV9FrameInfo::FirstIncomingArgOffsetFromFP;
       int nextArgOffset = firstArgOffset + numFixedArgs * argSize;
 
       for (int i=numFixedArgs; i < numArgRegs; ++i) {