summaryrefslogtreecommitdiff
path: root/compiler/GHC/SysTools.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2022-03-21 14:57:43 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-17 20:22:02 -0400
commitef3c8d9e077a1d4ede0724075489fb1f12afa3f9 (patch)
tree9bd61626c036af10e0866aa6a5541d33cac60e4c /compiler/GHC/SysTools.hs
parent0e2d16eb76037152c96226f0f65a5ebdee64f7b6 (diff)
downloadhaskell-ef3c8d9e077a1d4ede0724075489fb1f12afa3f9.tar.gz
Don't store LlvmConfig into DynFlags
LlvmConfig contains information read from llvm-passes and llvm-targets files in GHC's top directory. Reading these files is done only when needed (i.e. when the LLVM backend is used) and cached for the whole compiler session. This patch changes the way this is done: - Split LlvmConfig into LlvmConfig and LlvmConfigCache - Store LlvmConfigCache in HscEnv instead of DynFlags: there is no good reason to store it in DynFlags. As it is fixed per session, we store it in the session state instead (HscEnv). - Initializing LlvmConfigCache required some changes to driver functions such as newHscEnv. I've used the opportunity to untangle initHscEnv from initGhcMonad (in top-level GHC module) and to move it to GHC.Driver.Main, close to newHscEnv. - I've also made `cmmPipeline` independent of HscEnv in order to remove the call to newHscEnv in regalloc_unit_tests.
Diffstat (limited to 'compiler/GHC/SysTools.hs')
-rw-r--r--compiler/GHC/SysTools.hs45
1 files changed, 0 insertions, 45 deletions
diff --git a/compiler/GHC/SysTools.hs b/compiler/GHC/SysTools.hs
index adc6e6c241..058fc67d12 100644
--- a/compiler/GHC/SysTools.hs
+++ b/compiler/GHC/SysTools.hs
@@ -14,7 +14,6 @@
module GHC.SysTools (
-- * Initialisation
initSysTools,
- lazyInitLlvmConfig,
-- * Interface to system tools
module GHC.SysTools.Tasks,
@@ -32,7 +31,6 @@ module GHC.SysTools (
import GHC.Prelude
-import GHC.Settings.Utils
import GHC.Utils.Panic
import GHC.Driver.Session
@@ -44,9 +42,7 @@ import GHC.SysTools.BaseDir
import GHC.Settings.IO
import Control.Monad.Trans.Except (runExceptT)
-import System.FilePath
import System.IO
-import System.IO.Unsafe (unsafeInterleaveIO)
import Foreign.Marshal.Alloc (allocaBytes)
import System.Directory (copyFile)
@@ -102,47 +98,6 @@ stuff.
************************************************************************
-}
--- Note [LLVM configuration]
--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- The `llvm-targets` and `llvm-passes` files are shipped with GHC and contain
--- information needed by the LLVM backend to invoke `llc` and `opt`.
--- Specifically:
---
--- * llvm-targets maps autoconf host triples to the corresponding LLVM
--- `data-layout` declarations. This information is extracted from clang using
--- the script in utils/llvm-targets/gen-data-layout.sh and should be updated
--- whenever we target a new version of LLVM.
---
--- * llvm-passes maps GHC optimization levels to sets of LLVM optimization
--- flags that GHC should pass to `opt`.
---
--- This information is contained in files rather the GHC source to allow users
--- to add new targets to GHC without having to recompile the compiler.
---
--- Since this information is only needed by the LLVM backend we load it lazily
--- with unsafeInterleaveIO. Consequently it is important that we lazily pattern
--- match on LlvmConfig until we actually need its contents.
-
-lazyInitLlvmConfig :: String
- -> IO LlvmConfig
-lazyInitLlvmConfig top_dir
- = unsafeInterleaveIO $ do -- see Note [LLVM configuration]
- targets <- readAndParse "llvm-targets"
- passes <- readAndParse "llvm-passes"
- return $ LlvmConfig { llvmTargets = fmap mkLlvmTarget <$> targets,
- llvmPasses = passes }
- where
- readAndParse :: Read a => String -> IO a
- readAndParse name =
- do let llvmConfigFile = top_dir </> name
- llvmConfigStr <- readFile llvmConfigFile
- case maybeReadFuzzy llvmConfigStr of
- Just s -> return s
- Nothing -> pgmError ("Can't parse " ++ show llvmConfigFile)
-
- mkLlvmTarget :: (String, String, String) -> LlvmTarget
- mkLlvmTarget (dl, cpu, attrs) = LlvmTarget dl cpu (words attrs)
-
initSysTools :: String -- TopDir path
-> IO Settings -- Set all the mutable variables above, holding