summaryrefslogtreecommitdiff
path: root/compiler/nativeGen/SPARC/CodeGen.hs
diff options
context:
space:
mode:
authorBen.Lippmeier@anu.edu.au <unknown>2009-02-23 07:12:07 +0000
committerBen.Lippmeier@anu.edu.au <unknown>2009-02-23 07:12:07 +0000
commit42222f95a101fb3647f8728302bbf1098b74e59e (patch)
treec0ab0607ecd93ecd673aa63de3dc445179158ce6 /compiler/nativeGen/SPARC/CodeGen.hs
parent5e048459a28b08601a203b25ae9ead6284e8198a (diff)
downloadhaskell-42222f95a101fb3647f8728302bbf1098b74e59e.tar.gz
SPARC NCG: Split out sanity checking into its own module
Diffstat (limited to 'compiler/nativeGen/SPARC/CodeGen.hs')
-rw-r--r--compiler/nativeGen/SPARC/CodeGen.hs39
1 files changed, 4 insertions, 35 deletions
diff --git a/compiler/nativeGen/SPARC/CodeGen.hs b/compiler/nativeGen/SPARC/CodeGen.hs
index 13907c79e2..6a3455745c 100644
--- a/compiler/nativeGen/SPARC/CodeGen.hs
+++ b/compiler/nativeGen/SPARC/CodeGen.hs
@@ -18,6 +18,7 @@ where
#include "MachDeps.h"
-- NCG stuff:
+import SPARC.CodeGen.Sanity
import SPARC.CodeGen.Amode
import SPARC.CodeGen.CondCode
import SPARC.CodeGen.Gen64
@@ -77,7 +78,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 +93,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