[commit: ghc] master: Add MonadUnique instance for LlvmM (6a2992d)
git at git.haskell.org
git at git.haskell.org
Fri Mar 11 12:27:30 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/6a2992dc4b6582bd95b0cef1a674a99ca8299403/ghc
>---------------------------------------------------------------
commit 6a2992dc4b6582bd95b0cef1a674a99ca8299403
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Fri Mar 11 10:41:05 2016 +0100
Add MonadUnique instance for LlvmM
Reviewers: erikd, austin
Reviewed By: erikd
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1994
>---------------------------------------------------------------
6a2992dc4b6582bd95b0cef1a674a99ca8299403
compiler/llvmGen/LlvmCodeGen/Base.hs | 21 ++++++++++++++-------
compiler/llvmGen/LlvmCodeGen/CodeGen.hs | 4 ++--
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/compiler/llvmGen/LlvmCodeGen/Base.hs b/compiler/llvmGen/LlvmCodeGen/Base.hs
index 3a60891..3e2b795 100644
--- a/compiler/llvmGen/LlvmCodeGen/Base.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Base.hs
@@ -18,7 +18,7 @@ module LlvmCodeGen.Base (
runLlvm, liftStream, withClearVars, varLookup, varInsert,
markStackReg, checkStackReg,
funLookup, funInsert, getLlvmVer, getDynFlags, getDynFlag, getLlvmPlatform,
- dumpIfSetLlvm, renderLlvm, runUs, markUsedVar, getUsedVars,
+ dumpIfSetLlvm, renderLlvm, markUsedVar, getUsedVars,
ghcInternalFunctions,
getMetaUniqueId,
@@ -224,6 +224,19 @@ instance Monad LlvmM where
instance HasDynFlags LlvmM where
getDynFlags = LlvmM $ \env -> return (envDynFlags env, env)
+instance MonadUnique LlvmM where
+ getUniqueSupplyM = do
+ us <- getEnv envUniq
+ let (us1, us2) = splitUniqSupply us
+ modifyEnv (\s -> s { envUniq = us2 })
+ return us1
+
+ getUniqueM = do
+ us <- getEnv envUniq
+ let (u,us') = takeUniqFromSupply us
+ modifyEnv (\s -> s { envUniq = us' })
+ return u
+
-- | Lifting of IO actions. Not exported, as we want to encapsulate IO.
liftIO :: IO a -> LlvmM a
liftIO m = LlvmM $ \env -> do x <- m
@@ -323,12 +336,6 @@ renderLlvm sdoc = do
dumpIfSetLlvm Opt_D_dump_llvm "LLVM Code" sdoc
return ()
--- | Run a @UniqSM@ action with our unique supply
-runUs :: UniqSM a -> LlvmM a
-runUs m = LlvmM $ \env -> do
- let (x, us') = initUs (envUniq env) m
- return (x, env { envUniq = us' })
-
-- | Marks a variable as "used"
markUsedVar :: LlvmVar -> LlvmM ()
markUsedVar v = modifyEnv $ \env -> env { envUsedVars = v : envUsedVars env }
diff --git a/compiler/llvmGen/LlvmCodeGen/CodeGen.hs b/compiler/llvmGen/LlvmCodeGen/CodeGen.hs
index 4bc6248..fa47d6a 100644
--- a/compiler/llvmGen/LlvmCodeGen/CodeGen.hs
+++ b/compiler/llvmGen/LlvmCodeGen/CodeGen.hs
@@ -144,7 +144,7 @@ getInstrinct2 fname fty@(LMFunction funSig) = do
return []
Nothing -> do
funInsert fname fty
- un <- runUs getUniqueM
+ un <- getUniqueM
let lbl = mkAsmTempLabel un
return [CmmData (Section Data lbl) [([],[fty])]]
@@ -1783,7 +1783,7 @@ getHsFunc' name fty
-- | Create a new local var
mkLocalVar :: LlvmType -> LlvmM LlvmVar
mkLocalVar ty = do
- un <- runUs getUniqueM
+ un <- getUniqueM
return $ LMLocalVar un ty
More information about the ghc-commits
mailing list