Fix the generation of CallerSaves; fixes #7163
authorIan Lynagh <ian@well-typed.com>
Tue, 21 Aug 2012 15:41:30 +0000 (16:41 +0100)
committerIan Lynagh <ian@well-typed.com>
Tue, 21 Aug 2012 15:44:51 +0000 (16:44 +0100)
Simon Marlow spotted that we were #include'ing MachRegs.h several times,
but that doesn't work as (a) it uses ifdeffery to avoid being included
multiple times, and (b) even if we work around that, then the #define's
from previous inclusions are still defined when we #include it again.

So we now put the platform code for each platform in a separate .hs file.

13 files changed:
compiler/codeGen/CallerSaves.hs [deleted file]
compiler/codeGen/CgUtils.hs
compiler/codeGen/CodeGen/CallerSaves.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/ARM.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/NoRegs.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/PPC.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/PPC_Darwin.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/SPARC.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/X86.hs [new file with mode: 0644]
compiler/codeGen/CodeGen/Platform/X86_64.hs [new file with mode: 0644]
compiler/codeGen/StgCmmUtils.hs
compiler/ghc.cabal.in
includes/CallerSaves.part.hs

diff --git a/compiler/codeGen/CallerSaves.hs b/compiler/codeGen/CallerSaves.hs
deleted file mode 100644 (file)
index babee9e..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-
-module CallerSaves (callerSaves) where
-
-import CmmExpr
-import Platform
-
--- | Returns 'True' if this global register is stored in a caller-saves
--- machine register.
-
-callerSaves :: Platform -> GlobalReg -> Bool
-#define MACHREGS_NO_REGS 0
-callerSaves (Platform { platformArch = ArchX86 }) = platformCallerSaves
-  where
-#define MACHREGS_i386 1
-#include "../../includes/CallerSaves.part.hs"
-#undef MACHREGS_i386
-callerSaves (Platform { platformArch = ArchX86_64 }) = platformCallerSaves
-  where
-#define MACHREGS_x86_64 1
-#include "../../includes/CallerSaves.part.hs"
-#undef MACHREGS_x86_64
-callerSaves (Platform { platformArch = ppcArch, platformOS = OSDarwin })
- | ppcArch `elem` [ArchPPC, ArchPPC_64] = platformCallerSaves
-  where
-#define MACHREGS_powerpc 1
-#define MACHREGS_darwin 1
-#include "../../includes/CallerSaves.part.hs"
-#undef MACHREGS_powerpc
-#undef MACHREGS_darwin
-callerSaves (Platform { platformArch = ppcArch })
- | ppcArch `elem` [ArchPPC, ArchPPC_64] = platformCallerSaves
-  where
-#define MACHREGS_powerpc 1
-#include "../../includes/CallerSaves.part.hs"
-#undef MACHREGS_powerpc
-callerSaves (Platform { platformArch = ArchSPARC }) = platformCallerSaves
-  where
-#define MACHREGS_sparc 1
-#include "../../includes/CallerSaves.part.hs"
-#undef MACHREGS_sparc
-callerSaves (Platform { platformArch = ArchARM {} }) = platformCallerSaves
-  where
-#define MACHREGS_arm 1
-#include "../../includes/CallerSaves.part.hs"
-#undef MACHREGS_arm
-callerSaves _ = platformCallerSaves
-  where
-#undef MACHREGS_NO_REGS
-#define MACHREGS_NO_REGS 1
-#include "../../includes/CallerSaves.part.hs"
-
index d64aaa8..b488f16 100644 (file)
@@ -48,7 +48,7 @@ module CgUtils (
 #include "../includes/stg/HaskellMachRegs.h"
 
 import BlockId
-import CallerSaves
+import CodeGen.CallerSaves
 import CgMonad
 import TyCon
 import DataCon
diff --git a/compiler/codeGen/CodeGen/CallerSaves.hs b/compiler/codeGen/CodeGen/CallerSaves.hs
new file mode 100644 (file)
index 0000000..b6c709d
--- /dev/null
@@ -0,0 +1,32 @@
+
+module CodeGen.CallerSaves (callerSaves) where
+
+import CmmExpr
+import Platform
+
+import qualified CodeGen.Platform.ARM        as ARM
+import qualified CodeGen.Platform.PPC        as PPC
+import qualified CodeGen.Platform.PPC_Darwin as PPC_Darwin
+import qualified CodeGen.Platform.SPARC      as SPARC
+import qualified CodeGen.Platform.X86        as X86
+import qualified CodeGen.Platform.X86_64     as X86_64
+import qualified CodeGen.Platform.NoRegs     as NoRegs
+
+-- | Returns 'True' if this global register is stored in a caller-saves
+-- machine register.
+
+callerSaves :: Platform -> GlobalReg -> Bool
+callerSaves platform
+ = case platformArch platform of
+   ArchX86    -> X86.callerSaves
+   ArchX86_64 -> X86_64.callerSaves
+   ArchSPARC  -> SPARC.callerSaves
+   ArchARM {} -> ARM.callerSaves
+   arch
+    | arch `elem` [ArchPPC, ArchPPC_64] ->
+       case platformOS platform of
+       OSDarwin -> PPC_Darwin.callerSaves
+       _        -> PPC.callerSaves
+
+    | otherwise -> NoRegs.callerSaves
+
diff --git a/compiler/codeGen/CodeGen/Platform/ARM.hs b/compiler/codeGen/CodeGen/Platform/ARM.hs
new file mode 100644 (file)
index 0000000..0116139
--- /dev/null
@@ -0,0 +1,9 @@
+
+module CodeGen.Platform.ARM (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 0
+#define MACHREGS_arm 1
+#include "../../../../includes/CallerSaves.part.hs"
+
diff --git a/compiler/codeGen/CodeGen/Platform/NoRegs.hs b/compiler/codeGen/CodeGen/Platform/NoRegs.hs
new file mode 100644 (file)
index 0000000..ff39dd9
--- /dev/null
@@ -0,0 +1,8 @@
+
+module CodeGen.Platform.NoRegs (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 1
+#include "../../../../includes/CallerSaves.part.hs"
+
diff --git a/compiler/codeGen/CodeGen/Platform/PPC.hs b/compiler/codeGen/CodeGen/Platform/PPC.hs
new file mode 100644 (file)
index 0000000..c4c975a
--- /dev/null
@@ -0,0 +1,9 @@
+
+module CodeGen.Platform.PPC (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 0
+#define MACHREGS_powerpc 1
+#include "../../../../includes/CallerSaves.part.hs"
+
diff --git a/compiler/codeGen/CodeGen/Platform/PPC_Darwin.hs b/compiler/codeGen/CodeGen/Platform/PPC_Darwin.hs
new file mode 100644 (file)
index 0000000..a0cbe7e
--- /dev/null
@@ -0,0 +1,10 @@
+
+module CodeGen.Platform.PPC_Darwin (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 0
+#define MACHREGS_powerpc 1
+#define MACHREGS_darwin 1
+#include "../../../../includes/CallerSaves.part.hs"
+
diff --git a/compiler/codeGen/CodeGen/Platform/SPARC.hs b/compiler/codeGen/CodeGen/Platform/SPARC.hs
new file mode 100644 (file)
index 0000000..86b9494
--- /dev/null
@@ -0,0 +1,9 @@
+
+module CodeGen.Platform.SPARC (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 0
+#define MACHREGS_sparc 1
+#include "../../../../includes/CallerSaves.part.hs"
+
diff --git a/compiler/codeGen/CodeGen/Platform/X86.hs b/compiler/codeGen/CodeGen/Platform/X86.hs
new file mode 100644 (file)
index 0000000..c19bf9d
--- /dev/null
@@ -0,0 +1,9 @@
+
+module CodeGen.Platform.X86 (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 0
+#define MACHREGS_i386 1
+#include "../../../../includes/CallerSaves.part.hs"
+
diff --git a/compiler/codeGen/CodeGen/Platform/X86_64.hs b/compiler/codeGen/CodeGen/Platform/X86_64.hs
new file mode 100644 (file)
index 0000000..59cf788
--- /dev/null
@@ -0,0 +1,9 @@
+
+module CodeGen.Platform.X86_64 (callerSaves) where
+
+import CmmExpr
+
+#define MACHREGS_NO_REGS 0
+#define MACHREGS_x86_64 1
+#include "../../../../includes/CallerSaves.part.hs"
+
index 13c8ecc..ad435c7 100644 (file)
@@ -57,7 +57,7 @@ import StgCmmClosure
 import Cmm
 import BlockId
 import MkGraph
-import CallerSaves
+import CodeGen.CallerSaves
 import CLabel
 import CmmUtils
 
index 9eaa0ef..047b83d 100644 (file)
@@ -200,7 +200,14 @@ Library
         PprCmmDecl
         PprCmmExpr
         Bitmap
-        CallerSaves
+        CodeGen.CallerSaves
+        CodeGen.Platform.ARM
+        CodeGen.Platform.NoRegs
+        CodeGen.Platform.PPC
+        CodeGen.Platform.PPC_Darwin
+        CodeGen.Platform.SPARC
+        CodeGen.Platform.X86
+        CodeGen.Platform.X86_64
         CgBindery
         CgCallConv
         CgCase
index f045b64..f5eec5f 100644 (file)
@@ -1,81 +1,81 @@
 
 #include <stg/MachRegs.h>
 
-    platformCallerSaves :: GlobalReg -> Bool
+callerSaves :: GlobalReg -> Bool
 #ifdef CALLER_SAVES_Base
-    platformCallerSaves BaseReg     = True
+callerSaves BaseReg           = True
 #endif
 #ifdef CALLER_SAVES_R1
-    platformCallerSaves (VanillaReg 1 _)    = True
+callerSaves (VanillaReg 1 _)  = True
 #endif
 #ifdef CALLER_SAVES_R2
-    platformCallerSaves (VanillaReg 2 _)    = True
+callerSaves (VanillaReg 2 _)  = True
 #endif
 #ifdef CALLER_SAVES_R3
-    platformCallerSaves (VanillaReg 3 _)    = True
+callerSaves (VanillaReg 3 _)  = True
 #endif
 #ifdef CALLER_SAVES_R4
-    platformCallerSaves (VanillaReg 4 _)    = True
+callerSaves (VanillaReg 4 _)  = True
 #endif
 #ifdef CALLER_SAVES_R5
-    platformCallerSaves (VanillaReg 5 _)    = True
+callerSaves (VanillaReg 5 _)  = True
 #endif
 #ifdef CALLER_SAVES_R6
-    platformCallerSaves (VanillaReg 6 _)    = True
+callerSaves (VanillaReg 6 _)  = True
 #endif
 #ifdef CALLER_SAVES_R7
-    platformCallerSaves (VanillaReg 7 _)    = True
+callerSaves (VanillaReg 7 _)  = True
 #endif
 #ifdef CALLER_SAVES_R8
-    platformCallerSaves (VanillaReg 8 _)    = True
+callerSaves (VanillaReg 8 _)  = True
 #endif
 #ifdef CALLER_SAVES_R9
-    platformCallerSaves (VanillaReg 9 _)    = True
+callerSaves (VanillaReg 9 _)  = True
 #endif
 #ifdef CALLER_SAVES_R10
-    platformCallerSaves (VanillaReg 10 _)   = True
+callerSaves (VanillaReg 10 _) = True
 #endif
 #ifdef CALLER_SAVES_F1
-    platformCallerSaves (FloatReg 1)    = True
+callerSaves (FloatReg 1)      = True
 #endif
 #ifdef CALLER_SAVES_F2
-    platformCallerSaves (FloatReg 2)    = True
+callerSaves (FloatReg 2)      = True
 #endif
 #ifdef CALLER_SAVES_F3
-    platformCallerSaves (FloatReg 3)    = True
+callerSaves (FloatReg 3)      = True
 #endif
 #ifdef CALLER_SAVES_F4
-    platformCallerSaves (FloatReg 4)    = True
+callerSaves (FloatReg 4)      = True
 #endif
 #ifdef CALLER_SAVES_D1
-    platformCallerSaves (DoubleReg 1)   = True
+callerSaves (DoubleReg 1)     = True
 #endif
 #ifdef CALLER_SAVES_D2
-    platformCallerSaves (DoubleReg 2)   = True
+callerSaves (DoubleReg 2)     = True
 #endif
 #ifdef CALLER_SAVES_L1
-    platformCallerSaves (LongReg 1)     = True
+callerSaves (LongReg 1)       = True
 #endif
 #ifdef CALLER_SAVES_Sp
-    platformCallerSaves Sp          = True
+callerSaves Sp                = True
 #endif
 #ifdef CALLER_SAVES_SpLim
-    platformCallerSaves SpLim       = True
+callerSaves SpLim             = True
 #endif
 #ifdef CALLER_SAVES_Hp
-    platformCallerSaves Hp          = True
+callerSaves Hp                = True
 #endif
 #ifdef CALLER_SAVES_HpLim
-    platformCallerSaves HpLim       = True
+callerSaves HpLim             = True
 #endif
 #ifdef CALLER_SAVES_CCCS
-    platformCallerSaves CCCS                = True
+callerSaves CCCS              = True
 #endif
 #ifdef CALLER_SAVES_CurrentTSO
-    platformCallerSaves CurrentTSO      = True
+callerSaves CurrentTSO        = True
 #endif
 #ifdef CALLER_SAVES_CurrentNursery
-    platformCallerSaves CurrentNursery  = True
+callerSaves CurrentNursery    = True
 #endif
-    platformCallerSaves _           = False
+callerSaves _                 = False