X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FX86%2FRegInfo.hs;fp=compiler%2FnativeGen%2FX86%2FRegInfo.hs;h=39ff4063b02a7227e62d2db445101a0d211b0dee;hb=31a9d04804d9cacda35695c5397590516b964964;hp=a3bf8e4655e0a196a50b1ac28217f4c4d7f3cba8;hpb=6d38e24ea3da7ca9b435e9b1e59b2de8fcd91da4;p=ghc-hetmet.git diff --git a/compiler/nativeGen/X86/RegInfo.hs b/compiler/nativeGen/X86/RegInfo.hs index a3bf8e4..39ff406 100644 --- a/compiler/nativeGen/X86/RegInfo.hs +++ b/compiler/nativeGen/X86/RegInfo.hs @@ -51,14 +51,17 @@ canShortcut (JMP (OpImm imm)) = Just (DestImm imm) canShortcut _ = Nothing +-- The helper ensures that we don't follow cycles. shortcutJump :: (BlockId -> Maybe JumpDest) -> Instr -> Instr -shortcutJump fn insn@(JXX cc id) = - case fn id of - Nothing -> insn - Just (DestBlockId id') -> shortcutJump fn (JXX cc id') - Just (DestImm imm) -> shortcutJump fn (JXX_GBL cc imm) - -shortcutJump _ other = other +shortcutJump fn insn = shortcutJump' fn emptyBlockSet insn + where shortcutJump' fn seen insn@(JXX cc id) = + if elemBlockSet id seen then insn + else case fn id of + Nothing -> insn + Just (DestBlockId id') -> shortcutJump' fn seen' (JXX cc id') + Just (DestImm imm) -> shortcutJump' fn seen' (JXX_GBL cc imm) + where seen' = extendBlockSet seen id + shortcutJump' _ _ other = other -- Here because it knows about JumpDest