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.
24 -> NatBasicBlock Instr -> NatBasicBlock Instr
26 checkBlock cmm block@(BasicBlock _ instrs)
27 | checkBlockInstrs instrs
32 ("SPARC.CodeGen: bad block\n")
33 ( vcat [ text " -- cmm -----------------\n"
35 , text " -- native code ---------\n"
39 checkBlockInstrs :: [Instr] -> Bool
42 -- An unconditional jumps end the block.
43 -- There must be an unconditional jump in the block, otherwise
44 -- the register liveness determinator will get the liveness
47 -- If the block ends with a cmm call that never returns
48 -- then there can be unreachable instructions after the jump,
49 -- but we don't mind here.
51 | instr : NOP : _ <- ii
52 , isUnconditionalJump instr
55 -- All jumps must have a NOP in their branch delay slot.
56 -- The liveness determinator and register allocators aren't smart
57 -- enough to handle branch delay slots.
59 | instr : NOP : is <- ii
60 , isJumpishInstr instr
65 = checkBlockInstrs (i2:is)
67 -- this block is no good