Added support for fp callee saved registers.
Added fp register clobbering during calls.
Added AsmPrinter support for "fmask", a bitmask that indicates where on the 
stack the fp callee saved registers are.

Fixed the stack frame layout for Mips, now the callee saved regs 
are in the right stack location (a little documentation about how this
stack frame must look like is present in MipsRegisterInfo.cpp).
This was done using the method MipsRegisterInfo::adjustMipsStackFrame
To be more clear, these are examples of what is solves :  

1) FP and RA are also callee saved, and despite they aren't in CSI they 
   must be saved before the fp callee saved registers. 
2) The ABI requires that local varibles are allocated before the callee 
   saved register area, the opposite behavior from the default allocation.
3) CPU and FPU saved register area must be aligned independent of each
   other.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54403 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/Mips/MipsAsmPrinter.cpp b/lib/Target/Mips/MipsAsmPrinter.cpp
index d53fd06..fc7da39 100644
--- a/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -67,15 +67,13 @@
     void printFCCOperand(const MachineInstr *MI, int opNum, 
                          const char *Modifier = 0);
     void printModuleLevelGV(const GlobalVariable* GVar);
-    unsigned int getSavedRegsBitmask(bool isFloat, MachineFunction &MF);
+    void printSavedRegsBitmask(MachineFunction &MF);
     void printHex32(unsigned int Value);
 
     const char *emitCurrentABIString(void);
     void emitFunctionStart(MachineFunction &MF);
     void emitFunctionEnd(MachineFunction &MF);
     void emitFrameDirective(MachineFunction &MF);
-    void emitMaskDirective(MachineFunction &MF);
-    void emitFMaskDirective(MachineFunction &MF);
 
     bool printInstruction(const MachineInstr *MI);  // autogenerated.
     bool runOnMachineFunction(MachineFunction &F);
@@ -131,69 +129,45 @@
 // Mask directives
 //===----------------------------------------------------------------------===//
 
-/// Mask directive for GPR
+// Create a bitmask with all callee saved registers for CPU or Floating Point 
+// registers. For CPU registers consider RA, GP and FP for saving if necessary.
 void MipsAsmPrinter::
-emitMaskDirective(MachineFunction &MF)
-{
-  MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
-
-  int StackSize = MF.getFrameInfo()->getStackSize();
-  int Offset    = (!MipsFI->getTopSavedRegOffset()) ? 0 : 
-                  (-(StackSize-MipsFI->getTopSavedRegOffset()));
-
-  #ifndef NDEBUG
-  DOUT << "--> emitMaskDirective" << '\n';
-  DOUT << "StackSize :  " << StackSize << '\n';
-  DOUT << "getTopSavedReg : " << MipsFI->getTopSavedRegOffset() << '\n';
-  DOUT << "Offset : " << Offset << "\n\n";
-  #endif
-
-  unsigned int Bitmask = getSavedRegsBitmask(false, MF);
-  O << "\t.mask \t"; 
-  printHex32(Bitmask);
-  O << ',' << Offset << '\n';
-}
-
-/// TODO: Mask Directive for Floating Point
-void MipsAsmPrinter::
-emitFMaskDirective(MachineFunction &MF)
-{
-  unsigned int Bitmask = getSavedRegsBitmask(true, MF);
-
-  O << "\t.fmask\t";
-  printHex32(Bitmask);
-  O << ",0" << '\n';
-}
-
-// Create a bitmask with all callee saved registers for CPU
-// or Floating Point registers. For CPU registers consider RA,
-// GP and FP for saving if necessary.
-unsigned int MipsAsmPrinter::
-getSavedRegsBitmask(bool isFloat, MachineFunction &MF)
+printSavedRegsBitmask(MachineFunction &MF)
 {
   const TargetRegisterInfo &RI = *TM.getRegisterInfo();
+  MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
              
-  // Floating Point Registers, TODO
-  if (isFloat)
-    return 0;
+  // CPU and FPU Saved Registers Bitmasks
+  unsigned int CPUBitmask = 0;
+  unsigned int FPUBitmask = 0;
 
-  // CPU Registers
-  unsigned int Bitmask = 0;
-
+  // Set the CPU and FPU Bitmasks
   MachineFrameInfo *MFI = MF.getFrameInfo();
   const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
-  for (unsigned i = 0, e = CSI.size(); i != e; ++i)
-    Bitmask |= (1 << MipsRegisterInfo::getRegisterNumbering(CSI[i].getReg()));
+  for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
+    unsigned RegNum = MipsRegisterInfo::getRegisterNumbering(CSI[i].getReg());
+    if (CSI[i].getRegClass() == Mips::CPURegsRegisterClass)
+      CPUBitmask |= (1 << RegNum);
+    else
+      FPUBitmask |= (1 << RegNum);
+  }
 
+  // Return Address and Frame registers must also be set in CPUBitmask.
   if (RI.hasFP(MF)) 
-    Bitmask |= (1 << MipsRegisterInfo::
+    CPUBitmask |= (1 << MipsRegisterInfo::
                 getRegisterNumbering(RI.getFrameRegister(MF)));
   
   if (MF.getFrameInfo()->hasCalls()) 
-    Bitmask |= (1 << MipsRegisterInfo::
+    CPUBitmask |= (1 << MipsRegisterInfo::
                 getRegisterNumbering(RI.getRARegister()));
 
-  return Bitmask;
+  // Print CPUBitmask
+  O << "\t.mask \t"; printHex32(CPUBitmask); O << ','
+    << MipsFI->getCPUTopSavedRegOff() << '\n';
+
+  // Print FPUBitmask
+  O << "\t.fmask\t"; printHex32(FPUBitmask); O << ","
+    << MipsFI->getFPUTopSavedRegOff() << '\n';
 }
 
 // Print a 32 bit hex number with all numbers.
@@ -269,8 +243,7 @@
   O << CurrentFnName << ":\n";
 
   emitFrameDirective(MF);
-  emitMaskDirective(MF);
-  emitFMaskDirective(MF);
+  printSavedRegsBitmask(MF);
 
   O << '\n';
 }