summaryrefslogtreecommitdiff
path: root/compiler/nativeGen
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/nativeGen')
-rw-r--r--compiler/nativeGen/AsmCodeGen.lhs7
-rw-r--r--compiler/nativeGen/NCG.h4
-rw-r--r--compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs4
-rw-r--r--compiler/nativeGen/X86/CodeGen.hs15
-rw-r--r--compiler/nativeGen/X86/Instr.hs39
5 files changed, 38 insertions, 31 deletions
diff --git a/compiler/nativeGen/AsmCodeGen.lhs b/compiler/nativeGen/AsmCodeGen.lhs
index e845cdeb7c..b5144d6972 100644
--- a/compiler/nativeGen/AsmCodeGen.lhs
+++ b/compiler/nativeGen/AsmCodeGen.lhs
@@ -150,7 +150,8 @@ data NcgImpl statics instr jumpDest = NcgImpl {
--------------------
nativeCodeGen :: DynFlags -> Handle -> UniqSupply -> [RawCmmGroup] -> IO ()
nativeCodeGen dflags h us cmms
- = let nCG' :: (PlatformOutputable statics, PlatformOutputable instr, Instruction instr) => NcgImpl statics instr jumpDest -> IO ()
+ = let platform = targetPlatform dflags
+ nCG' :: (PlatformOutputable statics, PlatformOutputable instr, Instruction instr) => NcgImpl statics instr jumpDest -> IO ()
nCG' ncgImpl = nativeCodeGen' dflags ncgImpl h us cmms
x86NcgImpl = NcgImpl {
cmmTopCodeGen = X86.CodeGen.cmmTopCodeGen
@@ -160,13 +161,13 @@ nativeCodeGen dflags h us cmms
,shortcutStatics = X86.Instr.shortcutStatics
,shortcutJump = X86.Instr.shortcutJump
,pprNatCmmDecl = X86.Ppr.pprNatCmmDecl
- ,maxSpillSlots = X86.Instr.maxSpillSlots
+ ,maxSpillSlots = X86.Instr.maxSpillSlots (target32Bit platform)
,allocatableRegs = X86.Regs.allocatableRegs
,ncg_x86fp_kludge = id
,ncgExpandTop = id
,ncgMakeFarBranches = id
}
- in case platformArch $ targetPlatform dflags of
+ in case platformArch platform of
ArchX86 -> nCG' (x86NcgImpl { ncg_x86fp_kludge = map x86fp_kludge })
ArchX86_64 -> nCG' x86NcgImpl
ArchPPC ->
diff --git a/compiler/nativeGen/NCG.h b/compiler/nativeGen/NCG.h
index abeb566000..bca1de41e3 100644
--- a/compiler/nativeGen/NCG.h
+++ b/compiler/nativeGen/NCG.h
@@ -11,8 +11,4 @@
#include "ghc_boot_platform.h"
-#if i386_TARGET_ARCH
-# define IF_ARCH_i386(x,y) x
-#else
-# define IF_ARCH_i386(x,y) y
#endif
diff --git a/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs b/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs
index 455bac7ecf..6d17a4f077 100644
--- a/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs
+++ b/compiler/nativeGen/RegAlloc/Linear/FreeRegs.hs
@@ -61,8 +61,8 @@ instance FR SPARC.FreeRegs where
maxSpillSlots :: Platform -> Int
maxSpillSlots platform
= case platformArch platform of
- ArchX86 -> X86.Instr.maxSpillSlots
- ArchX86_64 -> X86.Instr.maxSpillSlots
+ ArchX86 -> X86.Instr.maxSpillSlots True -- 32bit
+ ArchX86_64 -> X86.Instr.maxSpillSlots False -- not 32bit
ArchPPC -> PPC.Instr.maxSpillSlots
ArchSPARC -> SPARC.Instr.maxSpillSlots
ArchARM _ _ -> panic "maxSpillSlots ArchARM"
diff --git a/compiler/nativeGen/X86/CodeGen.hs b/compiler/nativeGen/X86/CodeGen.hs
index 6d10c01f86..1efa327002 100644
--- a/compiler/nativeGen/X86/CodeGen.hs
+++ b/compiler/nativeGen/X86/CodeGen.hs
@@ -846,12 +846,15 @@ getRegister' is32Bit (CmmLoad mem pk)
return (Any size code)
where size = intSize $ typeWidth pk
-getRegister' _ (CmmLit (CmmInt 0 width))
+getRegister' is32Bit (CmmLit (CmmInt 0 width))
= let
size = intSize width
-- x86_64: 32-bit xor is one byte shorter, and zero-extends to 64 bits
- size1 = IF_ARCH_i386( size, case size of II64 -> II32; _ -> size )
+ size1 = if is32Bit then size
+ else case size of
+ II64 -> II32
+ _ -> size
code dst
= unitOL (XOR size1 (OpReg dst) (OpReg dst))
in
@@ -1055,7 +1058,7 @@ getNonClobberedOperand (CmmLoad mem pk) = do
is32Bit <- is32BitPlatform
use_sse2 <- sse2Enabled
if (not (isFloatType pk) || use_sse2)
- && IF_ARCH_i386(not (isWord64 pk), True)
+ && (if is32Bit then not (isWord64 pk) else True)
then do
Amode src mem_code <- getAmode mem
(src',save_code) <-
@@ -1103,8 +1106,9 @@ getOperand (CmmLit lit) = do
else getOperand_generic (CmmLit lit)
getOperand (CmmLoad mem pk) = do
+ is32Bit <- is32BitPlatform
use_sse2 <- sse2Enabled
- if (not (isFloatType pk) || use_sse2) && IF_ARCH_i386(not (isWord64 pk), True)
+ if (not (isFloatType pk) || use_sse2) && (if is32Bit then not (isWord64 pk) else True)
then do
Amode src mem_code <- getAmode mem
return (OpAddr src, mem_code)
@@ -1164,8 +1168,9 @@ isSuitableFloatingPointLit _ = False
getRegOrMem :: CmmExpr -> NatM (Operand, InstrBlock)
getRegOrMem e@(CmmLoad mem pk) = do
+ is32Bit <- is32BitPlatform
use_sse2 <- sse2Enabled
- if (not (isFloatType pk) || use_sse2) && IF_ARCH_i386(not (isWord64 pk), True)
+ if (not (isFloatType pk) || use_sse2) && (if is32Bit then not (isWord64 pk) else True)
then do
Amode src mem_code <- getAmode mem
return (OpAddr src, mem_code)
diff --git a/compiler/nativeGen/X86/Instr.hs b/compiler/nativeGen/X86/Instr.hs
index d7dfd29576..81504200b7 100644
--- a/compiler/nativeGen/X86/Instr.hs
+++ b/compiler/nativeGen/X86/Instr.hs
@@ -9,7 +9,10 @@
#include "HsVersions.h"
#include "nativeGen/NCG.h"
-module X86.Instr
+module X86.Instr (Instr(..), Operand(..),
+ getJumpDestBlockId, canShortcut, shortcutStatics,
+ shortcutJump, i386_insert_ffrees,
+ maxSpillSlots, archWordSize)
where
import X86.Cond
@@ -613,16 +616,16 @@ x86_mkSpillInstr
-> Instr
x86_mkSpillInstr platform reg delta slot
- = let off = spillSlotToOffset slot
+ = let off = spillSlotToOffset is32Bit slot
in
- let off_w = (off-delta) `div` IF_ARCH_i386(4,8)
+ let off_w = (off - delta) `div` (if is32Bit then 4 else 8)
in case targetClassOfReg platform reg of
- RcInteger -> MOV (archWordSize (target32Bit platform))
+ RcInteger -> MOV (archWordSize is32Bit)
(OpReg reg) (OpAddr (spRel platform off_w))
RcDouble -> GST FF80 reg (spRel platform off_w) {- RcFloat/RcDouble -}
RcDoubleSSE -> MOV FF64 (OpReg reg) (OpAddr (spRel platform off_w))
_ -> panic "X86.mkSpillInstr: no match"
-
+ where is32Bit = target32Bit platform
-- | Make a spill reload instruction.
x86_mkLoadInstr
@@ -633,33 +636,35 @@ x86_mkLoadInstr
-> Instr
x86_mkLoadInstr platform reg delta slot
- = let off = spillSlotToOffset slot
+ = let off = spillSlotToOffset is32Bit slot
in
- let off_w = (off-delta) `div` IF_ARCH_i386(4,8)
+ let off_w = (off-delta) `div` (if is32Bit then 4 else 8)
in case targetClassOfReg platform reg of
- RcInteger -> MOV (archWordSize (target32Bit platform))
+ RcInteger -> MOV (archWordSize is32Bit)
(OpAddr (spRel platform off_w)) (OpReg reg)
RcDouble -> GLD FF80 (spRel platform off_w) reg {- RcFloat/RcDouble -}
RcDoubleSSE -> MOV FF64 (OpAddr (spRel platform off_w)) (OpReg reg)
_ -> panic "X86.x86_mkLoadInstr"
+ where is32Bit = target32Bit platform
-spillSlotSize :: Int
-spillSlotSize = IF_ARCH_i386(12, 8)
+spillSlotSize :: Bool -> Int
+spillSlotSize is32Bit = if is32Bit then 12 else 8
-maxSpillSlots :: Int
-maxSpillSlots = ((rESERVED_C_STACK_BYTES - 64) `div` spillSlotSize) - 1
+maxSpillSlots :: Bool -> Int
+maxSpillSlots is32Bit
+ = ((rESERVED_C_STACK_BYTES - 64) `div` spillSlotSize is32Bit) - 1
-- convert a spill slot number to a *byte* offset, with no sign:
-- decide on a per arch basis whether you are spilling above or below
-- the C stack pointer.
-spillSlotToOffset :: Int -> Int
-spillSlotToOffset slot
- | slot >= 0 && slot < maxSpillSlots
- = 64 + spillSlotSize * slot
+spillSlotToOffset :: Bool -> Int -> Int
+spillSlotToOffset is32Bit slot
+ | slot >= 0 && slot < maxSpillSlots is32Bit
+ = 64 + spillSlotSize is32Bit * slot
| otherwise
= pprPanic "spillSlotToOffset:"
( text "invalid spill location: " <> int slot
- $$ text "maxSpillSlots: " <> int maxSpillSlots)
+ $$ text "maxSpillSlots: " <> int (maxSpillSlots is32Bit))
--------------------------------------------------------------------------------