X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FSPARC%2FCodeGen.hs;h=beb48d66569c5ca3d7cab0fb13d54b652d118c72;hb=f537dd87c4a07526e2b1fc1bd1c125d652833641;hp=13907c79e20ec76adc29ee617679c733353ad7b6;hpb=724c086f69f2974212915f56fe809a61c7b5bfec;p=ghc-hetmet.git diff --git a/compiler/nativeGen/SPARC/CodeGen.hs b/compiler/nativeGen/SPARC/CodeGen.hs index 13907c7..beb48d6 100644 --- a/compiler/nativeGen/SPARC/CodeGen.hs +++ b/compiler/nativeGen/SPARC/CodeGen.hs @@ -8,6 +8,7 @@ module SPARC.CodeGen ( cmmTopCodeGen, + generateJumpTableForInstr, InstrBlock ) @@ -15,9 +16,10 @@ where #include "HsVersions.h" #include "nativeGen/NCG.h" -#include "MachDeps.h" +#include "../includes/MachDeps.h" -- NCG stuff: +import SPARC.CodeGen.Sanity import SPARC.CodeGen.Amode import SPARC.CodeGen.CondCode import SPARC.CodeGen.Gen64 @@ -35,14 +37,14 @@ import NCGMonad -- Our intermediate code: import BlockId -import Cmm +import OldCmm import CLabel -- The rest: import StaticFlags ( opt_PIC ) import OrdList -import qualified Outputable as O import Outputable +import Unique import Control.Monad ( mapAndUnzipM ) import DynFlags @@ -54,11 +56,11 @@ cmmTopCodeGen -> NatM [NatCmmTop Instr] cmmTopCodeGen _ - (CmmProc info lab params (ListGraph blocks)) + (CmmProc info lab (ListGraph blocks)) = do (nat_blocks,statics) <- mapAndUnzipM basicBlockCodeGen blocks - let proc = CmmProc info lab params (ListGraph $ concat nat_blocks) + let proc = CmmProc info lab (ListGraph $ concat nat_blocks) let tops = proc : concat statics return tops @@ -77,7 +79,7 @@ basicBlockCodeGen -> NatM ( [NatBasicBlock Instr] , [NatCmmTop Instr]) -basicBlockCodeGen (BasicBlock id stmts) = do +basicBlockCodeGen cmm@(BasicBlock id stmts) = do instrs <- stmtsToInstrs stmts let (top,other_blocks,statics) @@ -92,46 +94,14 @@ basicBlockCodeGen (BasicBlock id stmts) = do mkBlocks instr (instrs,blocks,statics) = (instr:instrs, blocks, statics) + -- do intra-block sanity checking blocksChecked - = map checkBlockEnd + = map (checkBlock cmm) $ BasicBlock id top : other_blocks return (blocksChecked, statics) --- | Enforce the invariant that all basic blocks must end with a jump. --- For SPARC this is a jump, then a nop for the branch delay slot. --- --- If the branch isn't there then the register liveness determinator --- will get the liveness information wrong. This will cause a bad --- allocation, which is seriously difficult to debug. --- --- If there is an instr in the branch delay slot, then the allocator --- will also get confused and give a bad allocation. --- -checkBlockEnd - :: NatBasicBlock Instr -> NatBasicBlock Instr - -checkBlockEnd block@(BasicBlock _ instrs) - | Just (i1, i2) <- takeLast2 instrs - , isJumpishInstr i1 - , NOP <- i2 - = block - - | otherwise - = pprPanic - ("SPARC.CodeGen: bad instrs at end of block\n") - (text "block:\n" <> ppr block) - -takeLast2 :: [a] -> Maybe (a, a) -takeLast2 xx - = case xx of - [] -> Nothing - _:[] -> Nothing - x1:x2:[] -> Just (x1, x2) - _:xs -> takeLast2 xs - - -- | Convert some Cmm statements to SPARC instructions. stmtsToInstrs :: [CmmStmt] -> NatM InstrBlock stmtsToInstrs stmts @@ -193,8 +163,8 @@ temporary, then do the other computation, and then use the temporary: -- | Convert a BlockId to some CmmStatic data jumpTableEntry :: Maybe BlockId -> CmmStatic jumpTableEntry Nothing = CmmStaticLit (CmmInt 0 wordWidth) -jumpTableEntry (Just (BlockId id)) = CmmStaticLit (CmmLabel blockLabel) - where blockLabel = mkAsmTempLabel id +jumpTableEntry (Just blockid) = CmmStaticLit (CmmLabel blockLabel) + where blockLabel = mkAsmTempLabel (getUnique blockid) @@ -330,15 +300,11 @@ genSwitch expr ids dst <- getNewRegNat II32 label <- getNewLabelNat - let jumpTable = map jumpTableEntry ids return $ e_code `appOL` toOL - -- the jump table - [ LDATA ReadOnlyData (CmmDataLabel label : jumpTable) - - -- load base of jump table - , SETHI (HI (ImmCLbl label)) base_reg + [ -- load base of jump table + SETHI (HI (ImmCLbl label)) base_reg , OR False base_reg (RIImm $ LO $ ImmCLbl label) base_reg -- the addrs in the table are 32 bits wide.. @@ -346,6 +312,11 @@ genSwitch expr ids -- load and jump to the destination , LD II32 (AddrRegReg base_reg offset_reg) dst - , JMP_TBL (AddrRegImm dst (ImmInt 0)) [i | Just i <- ids] + , JMP_TBL (AddrRegImm dst (ImmInt 0)) ids label , NOP ] +generateJumpTableForInstr :: Instr -> Maybe (NatCmmTop Instr) +generateJumpTableForInstr (JMP_TBL _ ids label) = + let jumpTable = map jumpTableEntry ids + in Just (CmmData ReadOnlyData (CmmDataLabel label : jumpTable)) +generateJumpTableForInstr _ = Nothing