callishPrimOpSupported :: DynFlags -> PrimOp -> Either CallishMachOp GenericOp
callishPrimOpSupported dflags op
  = case op of
      IntQuotRemOp   | ncg && x86ish  -> Left (MO_S_QuotRem  (wordWidth dflags))
                     | otherwise      -> Right (genericIntQuotRemOp dflags)

      WordQuotRemOp  | ncg && x86ish  -> Left (MO_U_QuotRem  (wordWidth dflags))
                     | otherwise      -> Right (genericWordQuotRemOp dflags)

      WordQuotRem2Op | (ncg && x86ish)
                          || llvm     -> Left (MO_U_QuotRem2 (wordWidth dflags))
                     | otherwise      -> Right (genericWordQuotRem2Op dflags)

      WordAdd2Op     | (ncg && x86ish)
                         || llvm      -> Left (MO_Add2       (wordWidth dflags))
                     | otherwise      -> Right genericWordAdd2Op

      IntAddCOp      | (ncg && x86ish)
                         || llvm      -> Left (MO_AddIntC    (wordWidth dflags))
                     | otherwise      -> Right genericIntAddCOp

      IntSubCOp      | (ncg && x86ish)
                         || llvm      -> Left (MO_SubIntC    (wordWidth dflags))
                     | otherwise      -> Right genericIntSubCOp

      WordMul2Op     | ncg && x86ish
                         || llvm      -> Left (MO_U_Mul2     (wordWidth dflags))
                     | otherwise      -> Right genericWordMul2Op

      _ -> pprPanic "emitPrimOp: can't translate PrimOp " (ppr op)
 where
  ncg = case hscTarget dflags of
           HscAsm -> True
           _      -> False
  llvm = case hscTarget dflags of
           HscLlvm -> True
           _       -> False
  x86ish = case platformArch (targetPlatform dflags) of
             ArchX86    -> True
             ArchX86_64 -> True
             _          -> False
callishPrimOpSupported :: DynFlags -> PrimOp -> Either CallishMachOp GenericOp
callishPrimOpSupported dflags op
  = case op of
      IntQuotRemOp   | ncg && x86ish  -> Left (MO_S_QuotRem  (wordWidth dflags))
                     | otherwise      -> Right (genericIntQuotRemOp dflags)

      WordQuotRemOp  | ncg && x86ish  -> Left (MO_U_QuotRem  (wordWidth dflags))
                     | otherwise      -> Right (genericWordQuotRemOp dflags)

      WordQuotRem2Op | (ncg && x86ish)
                          || llvm     -> Left (MO_U_QuotRem2 (wordWidth dflags))
                     | otherwise      -> Right (genericWordQuotRem2Op dflags)

      WordAdd2Op     | (ncg && x86ish)
                         || llvm      -> Left (MO_Add2       (wordWidth dflags))
                     | otherwise      -> Right genericWordAdd2Op

      IntAddCOp      | (ncg && x86ish)
                         || llvm      -> Left (MO_AddIntC    (wordWidth dflags))
                     | otherwise      -> Right genericIntAddCOp

      IntSubCOp      | (ncg && x86ish)
                         || llvm      -> Left (MO_SubIntC    (wordWidth dflags))
                     | otherwise      -> Right genericIntSubCOp

      WordMul2Op     | ncg && x86ish
                         || llvm      -> Left (MO_U_Mul2     (wordWidth dflags))
                     | otherwise      -> Right genericWordMul2Op

      _ -> pprPanic "emitPrimOp: can't translate PrimOp " (ppr op)
 where
  ncg = case hscTarget dflags of
           HscAsm -> True
           _      -> False
  llvm = case hscTarget dflags of
           HscLlvm -> True
           _       -> False
  x86ish = case platformArch (targetPlatform dflags) of
             ArchX86    -> True
             ArchX86_64 -> True
             _          -> False
callishPrimOpSupported dflags op
  = case op of
      IntQuotRemOp   | ncg && x86ish  -> Left (MO_S_QuotRem  (wordWidth dflags))
                     | otherwise      -> Right (genericIntQuotRemOp dflags)

      WordQuotRemOp  | ncg && x86ish  -> Left (MO_U_QuotRem  (wordWidth dflags))
                     | otherwise      -> Right (genericWordQuotRemOp dflags)

      WordQuotRem2Op | (ncg && x86ish)
                          || llvm     -> Left (MO_U_QuotRem2 (wordWidth dflags))
                     | otherwise      -> Right (genericWordQuotRem2Op dflags)

      WordAdd2Op     | (ncg && x86ish)
                         || llvm      -> Left (MO_Add2       (wordWidth dflags))
                     | otherwise      -> Right genericWordAdd2Op

      IntAddCOp      | (ncg && x86ish)
                         || llvm      -> Left (MO_AddIntC    (wordWidth dflags))
                     | otherwise      -> Right genericIntAddCOp

      IntSubCOp      | (ncg && x86ish)
                         || llvm      -> Left (MO_SubIntC    (wordWidth dflags))
                     | otherwise      -> Right genericIntSubCOp

      WordMul2Op     | ncg && x86ish
                         || llvm      -> Left (MO_U_Mul2     (wordWidth dflags))
                     | otherwise      -> Right genericWordMul2Op

      _ -> pprPanic "emitPrimOp: can't translate PrimOp " (ppr op)
 where
  ncg = case hscTarget dflags of
           HscAsm -> True
           _      -> False
  llvm = case hscTarget dflags of
           HscLlvm -> True
           _       -> False
  x86ish = case platformArch (targetPlatform dflags) of
             ArchX86    -> True
             ArchX86_64 -> True
             _          -> False