genLoad_slow :: Atomic -> CmmExpr -> CmmType -> [MetaAnnot] -> LlvmM ExprData
genLoad_slow atomic e ty meta = runExprData $ do
    iptr <- exprToVarW e
    dflags <- getDynFlags
    case getVarType iptr of
         LMPointer _ -> do
                    doExprW (cmmToLlvmType ty) (MExpr meta $ loadInstr iptr)

         i@(LMInt _) | i == llvmWord dflags -> do
                    let pty = LMPointer $ cmmToLlvmType ty
                    ptr <- doExprW pty $ Cast LM_Inttoptr iptr pty
                    doExprW (cmmToLlvmType ty) (MExpr meta $ loadInstr ptr)

         other -> do pprPanic "exprToVar: CmmLoad expression is not right type!"
                        (PprCmm.pprExpr e <+> text (
                            "Size of Ptr: " ++ show (llvmPtrBits dflags) ++
                            ", Size of var: " ++ show (llvmWidthInBits dflags other) ++
                            ", Var: " ++ showSDoc dflags (ppr iptr)))
  where
    loadInstr ptr | atomic    = ALoad SyncSeqCst False ptr
                  | otherwise = Load ptr


-- | Handle CmmReg expression. This will return a pointer to the stack
-- location of the register. Throws an error if it isn't allocated on
-- the stack.
genLoad_slow :: Atomic -> CmmExpr -> CmmType -> [MetaAnnot] -> LlvmM ExprData
genLoad_slow atomic e ty meta = runExprData $ do
    iptr <- exprToVarW e
    dflags <- getDynFlags
    case getVarType iptr of
         LMPointer _ -> do
                    doExprW (cmmToLlvmType ty) (MExpr meta $ loadInstr iptr)

         i@(LMInt _) | i == llvmWord dflags -> do
                    let pty = LMPointer $ cmmToLlvmType ty
                    ptr <- doExprW pty $ Cast LM_Inttoptr iptr pty
                    doExprW (cmmToLlvmType ty) (MExpr meta $ loadInstr ptr)

         other -> do pprPanic "exprToVar: CmmLoad expression is not right type!"
                        (PprCmm.pprExpr e <+> text (
                            "Size of Ptr: " ++ show (llvmPtrBits dflags) ++
                            ", Size of var: " ++ show (llvmWidthInBits dflags other) ++
                            ", Var: " ++ showSDoc dflags (ppr iptr)))
  where
    loadInstr ptr | atomic    = ALoad SyncSeqCst False ptr
                  | otherwise = Load ptr


-- | Handle CmmReg expression. This will return a pointer to the stack
-- location of the register. Throws an error if it isn't allocated on
-- the stack.
genLoad_slow atomic e ty meta = runExprData $ do
    iptr <- exprToVarW e
    dflags <- getDynFlags
    case getVarType iptr of
         LMPointer _ -> do
                    doExprW (cmmToLlvmType ty) (MExpr meta $ loadInstr iptr)

         i@(LMInt _) | i == llvmWord dflags -> do
                    let pty = LMPointer $ cmmToLlvmType ty
                    ptr <- doExprW pty $ Cast LM_Inttoptr iptr pty
                    doExprW (cmmToLlvmType ty) (MExpr meta $ loadInstr ptr)

         other -> do pprPanic "exprToVar: CmmLoad expression is not right type!"
                        (PprCmm.pprExpr e <+> text (
                            "Size of Ptr: " ++ show (llvmPtrBits dflags) ++
                            ", Size of var: " ++ show (llvmWidthInBits dflags other) ++
                            ", Var: " ++ showSDoc dflags (ppr iptr)))
  where
    loadInstr ptr | atomic    = ALoad SyncSeqCst False ptr
                  | otherwise = Load ptr


-- | Handle CmmReg expression. This will return a pointer to the stack
-- location of the register. Throws an error if it isn't allocated on
-- the stack.