tstellar / rpms / llvm

Forked from rpms/llvm 5 years ago
Clone
23fedaf
Index: lib/Target/ARM/ARMFrameLowering.cpp
23fedaf
===================================================================
23fedaf
--- lib/Target/ARM/ARMFrameLowering.cpp	(revision 159085)
23fedaf
+++ lib/Target/ARM/ARMFrameLowering.cpp	(working copy)
23fedaf
@@ -15,6 +15,8 @@
23fedaf
 #include "ARMBaseInstrInfo.h"
23fedaf
 #include "ARMBaseRegisterInfo.h"
23fedaf
 #include "ARMMachineFunctionInfo.h"
23fedaf
+#include "llvm/CallingConv.h"
23fedaf
+#include "llvm/Function.h"
23fedaf
 #include "MCTargetDesc/ARMAddressingModes.h"
23fedaf
 #include "llvm/Function.h"
23fedaf
 #include "llvm/CodeGen/MachineFrameInfo.h"
23fedaf
@@ -151,6 +153,10 @@
23fedaf
   int FramePtrSpillFI = 0;
23fedaf
   int D8SpillFI = 0;
23fedaf
 
23fedaf
+  // All calls are tail calls in GHC calling conv, and functions have no prologue/epilogue.
23fedaf
+  if (MF.getFunction()->getCallingConv() == CallingConv::GHC)
23fedaf
+    return;
23fedaf
+
23fedaf
   // Allocate the vararg register save area. This is not counted in NumBytes.
23fedaf
   if (VARegSaveSize)
23fedaf
     emitSPUpdate(isARM, MBB, MBBI, dl, TII, -VARegSaveSize,
23fedaf
@@ -354,6 +360,10 @@
23fedaf
   int NumBytes = (int)MFI->getStackSize();
23fedaf
   unsigned FramePtr = RegInfo->getFrameRegister(MF);
23fedaf
 
23fedaf
+  // All calls are tail calls in GHC calling conv, and functions have no prologue/epilogue.
23fedaf
+  if (MF.getFunction()->getCallingConv() == CallingConv::GHC)
23fedaf
+    return;
23fedaf
+
23fedaf
   if (!AFI->hasStackFrame()) {
23fedaf
     if (NumBytes != 0)
23fedaf
       emitSPUpdate(isARM, MBB, MBBI, dl, TII, NumBytes);
23fedaf
Index: lib/Target/ARM/ARMISelLowering.cpp
23fedaf
===================================================================
23fedaf
--- lib/Target/ARM/ARMISelLowering.cpp	(revision 159085)
23fedaf
+++ lib/Target/ARM/ARMISelLowering.cpp	(working copy)
23fedaf
@@ -1171,6 +1171,8 @@
23fedaf
     return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS);
23fedaf
   case CallingConv::ARM_APCS:
23fedaf
     return (Return ? RetCC_ARM_APCS : CC_ARM_APCS);
23fedaf
+  case CallingConv::GHC:
23fedaf
+    return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC);
23fedaf
   }
23fedaf
 }
23fedaf
 
23fedaf
Index: lib/Target/ARM/ARMCallingConv.td
23fedaf
===================================================================
23fedaf
--- lib/Target/ARM/ARMCallingConv.td	(revision 159085)
23fedaf
+++ lib/Target/ARM/ARMCallingConv.td	(working copy)
23fedaf
@@ -79,7 +79,26 @@
23fedaf
   CCDelegateTo<RetCC_ARM_APCS>
23fedaf
 ]>;
23fedaf
 
23fedaf
+//===----------------------------------------------------------------------===//
23fedaf
+// ARM APCS Calling Convention for GHC
23fedaf
+//===----------------------------------------------------------------------===//
23fedaf
 
23fedaf
+def CC_ARM_APCS_GHC : CallingConv<[
23fedaf
+  // Handle all vector types as either f64 or v2f64.
23fedaf
+  CCIfType<[v1i64, v2i32, v4i16, v8i8, v2f32], CCBitConvertToType<f64>>,
23fedaf
+  CCIfType<[v2i64, v4i32, v8i16, v16i8, v4f32], CCBitConvertToType<v2f64>>,
23fedaf
+
23fedaf
+  CCIfType<[v2f64], CCAssignToReg<[Q4, Q5]>>,
23fedaf
+  CCIfType<[f64], CCAssignToReg<[D8, D9, D10, D11]>>,
23fedaf
+  CCIfType<[f32], CCAssignToReg<[S16, S17, S18, S19, S20, S21, S22, S23]>>,
23fedaf
+
23fedaf
+  // Promote i8/i16 arguments to i32.
23fedaf
+  CCIfType<[i8, i16], CCPromoteToType<i32>>,
23fedaf
+
23fedaf
+  // Pass in STG registers: Base, Sp, Hp, R1, R2, R3, R4, SpLim
23fedaf
+  CCIfType<[i32], CCAssignToReg<[R4, R5, R6, R7, R8, R9, R10, R11]>>
23fedaf
+]>;
23fedaf
+
23fedaf
 //===----------------------------------------------------------------------===//
23fedaf
 // ARM AAPCS (EABI) Calling Convention, common parts
23fedaf
 //===----------------------------------------------------------------------===//
23fedaf
@@ -171,3 +190,9 @@
23fedaf
 // iOS ABI deviates from ARM standard ABI. R9 is not a callee-saved register.
23fedaf
 // Also save R7-R4 first to match the stack frame fixed spill areas.
23fedaf
 def CSR_iOS : CalleeSavedRegs<(add LR, R7, R6, R5, R4, (sub CSR_AAPCS, R9))>;
23fedaf
+
23fedaf
+// GHC set of callee saved regs is empty as all those regs are
23fedaf
+// used for passing STG regs around
23fedaf
+// sub/add LR is a workaround for not being able to compile empty list:
23fedaf
+// def CSR_GHC : CalleeSavedRegs<()>;
23fedaf
+def CSR_GHC : CalleeSavedRegs<(sub (add LR), LR)>;
23fedaf
Index: lib/Target/ARM/ARMFastISel.cpp
23fedaf
===================================================================
23fedaf
--- lib/Target/ARM/ARMFastISel.cpp	(revision 159085)
23fedaf
+++ lib/Target/ARM/ARMFastISel.cpp	(working copy)
23fedaf
@@ -1835,6 +1835,11 @@
23fedaf
     return (Return ? RetCC_ARM_AAPCS: CC_ARM_AAPCS);
23fedaf
   case CallingConv::ARM_APCS:
23fedaf
     return (Return ? RetCC_ARM_APCS: CC_ARM_APCS);
23fedaf
+  case CallingConv::GHC:
23fedaf
+    if (Return)
23fedaf
+      llvm_unreachable("Can't return in GHC call convention");
23fedaf
+    else
23fedaf
+      return CC_ARM_APCS_GHC;
23fedaf
   }
23fedaf
 }
23fedaf
 
23fedaf
--- lib/Target/ARM/ARMBaseRegisterInfo.cpp.orig	2012-07-12 09:59:58.181723592 +0100
23fedaf
+++ lib/Target/ARM/ARMBaseRegisterInfo.cpp	2012-07-12 10:01:15.301344412 +0100
23fedaf
@@ -62,7 +62,19 @@
23fedaf
 
23fedaf
 const uint16_t*
23fedaf
 ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const {
23fedaf
-  return (STI.isTargetIOS()) ? CSR_iOS_SaveList : CSR_AAPCS_SaveList;
23fedaf
+  bool ghcCall = false;
23fedaf
+
23fedaf
+  if (MF) {
23fedaf
+    const Function *F = MF->getFunction();
23fedaf
+    ghcCall = (F ? F->getCallingConv() == CallingConv::GHC : false);
23fedaf
+  }
23fedaf
+
23fedaf
+  if (ghcCall) {
23fedaf
+      return CSR_GHC_SaveList;
23fedaf
+  }
23fedaf
+  else {
23fedaf
+      return (STI.isTargetIOS()) ? CSR_iOS_SaveList : CSR_AAPCS_SaveList;
23fedaf
+  }
23fedaf
 }
23fedaf
 
23fedaf
 const uint32_t*