2 -- | One ounce of sanity checking is worth 10000000000000000 ounces
3 -- of staring blindly at assembly code trying to find the problem..
5 module SPARC.CodeGen.Sanity (
20 -- | Enforce intra-block invariants.
23 :: CmmBasicBlock -> NatBasicBlock Instr -> NatBasicBlock Instr
25 checkBlock cmm block@(BasicBlock _ instrs)
26 | checkBlockInstrs instrs
31 ("SPARC.CodeGen: bad block\n")
32 ( vcat [ text " -- cmm -----------------\n"
34 , text " -- native code ---------\n"
38 checkBlockInstrs :: [Instr] -> Bool
41 -- An unconditional jumps end the block.
42 -- There must be an unconditional jump in the block, otherwise
43 -- the register liveness determinator will get the liveness
46 -- If the block ends with a cmm call that never returns
47 -- then there can be unreachable instructions after the jump,
48 -- but we don't mind here.
50 | instr : NOP : _ <- ii
51 , isUnconditionalJump instr
54 -- All jumps must have a NOP in their branch delay slot.
55 -- The liveness determinator and register allocators aren't smart
56 -- enough to handle branch delay slots.
58 | instr : NOP : is <- ii
59 , isJumpishInstr instr
64 = checkBlockInstrs (i2:is)
66 -- this block is no good