[Git][ghc/ghc][master] Fix LLVM version detection
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Sat Dec 28 08:06:48 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
a928c326 by ARATA Mizuki at 2024-12-28T03:06:14-05:00
Fix LLVM version detection
With a recent LLVM, `llc -version` emits the version on the first line
if the vendor is set. It emits the version on the second line
otherwise.
Therefore, we need to check the both lines to detect the version.
GHC now emits a warning if it fails to detect the LLVM version,
so we can notice if the output of `llc -version` changes in the future.
Also, the warning for using LLVM < 10 on s390x is removed, because
we assume LLVM >= 13 now.
This fixes the definition of __GLASGOW_HASKELL_LLVM__ macro.
Fixes #25606
- - - - -
5 changed files:
- compiler/GHC/CmmToLlvm.hs
- compiler/GHC/SysTools/Tasks.hs
- docs/users_guide/phases.rst
- + testsuite/tests/llvm/should_compile/T25606.hs
- testsuite/tests/llvm/should_compile/all.T
Changes:
=====================================
compiler/GHC/CmmToLlvm.hs
=====================================
@@ -11,7 +11,7 @@ module GHC.CmmToLlvm
)
where
-import GHC.Prelude hiding ( head )
+import GHC.Prelude
import GHC.Llvm
import GHC.CmmToLlvm.Base
@@ -39,8 +39,7 @@ import GHC.Utils.Logger
import qualified GHC.Data.Stream as Stream
import Control.Monad ( when, forM_ )
-import Data.List.NonEmpty ( head )
-import Data.Maybe ( fromMaybe, catMaybes )
+import Data.Maybe ( fromMaybe, catMaybes, isNothing )
import System.IO
-- -----------------------------------------------------------------------------
@@ -72,11 +71,13 @@ llvmCodeGen logger cfg h dus cmm_stream
"up to" <+> text (llvmVersionStr supportedLlvmVersionUpperBound) <+> "(non inclusive) is supported." <+>
"System LLVM version: " <> text (llvmVersionStr ver) $$
"We will try though..."
- let isS390X = platformArch (llvmCgPlatform cfg) == ArchS390X
- let major_ver = head . llvmVersionNE $ ver
- when (isS390X && major_ver < 10 && doWarn) $ putMsg logger $
- "Warning: For s390x the GHC calling convention is only supported since LLVM version 10." <+>
- "You are using LLVM version: " <> text (llvmVersionStr ver)
+
+ when (isNothing mb_ver) $ do
+ let doWarn = llvmCgDoWarn cfg
+ when doWarn $ putMsg logger $
+ "Failed to detect LLVM version!" $$
+ "Make sure LLVM is installed correctly." $$
+ "We will try though..."
-- HACK: the Nothing case here is potentially wrong here but we
-- currently don't use the LLVM version to guide code generation
=====================================
compiler/GHC/SysTools/Tasks.hs
=====================================
@@ -306,14 +306,17 @@ figureLlvmVersion logger dflags = traceSystoolCommand logger "llc" $ do
(pin, pout, perr, p) <- runInteractiveProcess pgm args'
Nothing Nothing
{- > llc -version
- LLVM (http://llvm.org/):
- LLVM version 3.5.2
+ <vendor> LLVM version 15.0.7
...
+ OR
+ LLVM (http://llvm.org/):
+ LLVM version 14.0.6
-}
hSetBinaryMode pout False
- _ <- hGetLine pout
- vline <- hGetLine pout
- let mb_ver = parseLlvmVersion vline
+ line1 <- hGetLine pout
+ mb_ver <- case parseLlvmVersion line1 of
+ mb_ver@(Just _) -> return mb_ver
+ Nothing -> parseLlvmVersion <$> hGetLine pout -- Try the second line
hClose pin
hClose pout
hClose perr
=====================================
docs/users_guide/phases.rst
=====================================
@@ -502,7 +502,7 @@ defined by your local GHC installation, the following trick is useful:
.. index::
single: __GLASGOW_HASKELL_LLVM__
- Only defined when `:ghc-flag:`-fllvm` is specified. When GHC is using version
+ Only defined when :ghc-flag:`-fllvm` is specified. When GHC is using version
``x.y.z`` of LLVM, the value of ``__GLASGOW_HASKELL_LLVM__`` is the
integer ⟨xyy⟩ (if ⟨y⟩ is a single digit, then a leading zero
is added, so for example when using version 3.7 of LLVM,
=====================================
testsuite/tests/llvm/should_compile/T25606.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE CPP #-}
+
+main :: IO ()
+main = do
+#if defined(__GLASGOW_HASKELL_LLVM__)
+ putStrLn $ "__GLASGOW_HASKELL_LLVM__ = " ++ show __GLASGOW_HASKELL_LLVM__
+#else
+#error __GLASGOW_HASKELL_LLVM__ is not defined
+#endif
=====================================
testsuite/tests/llvm/should_compile/all.T
=====================================
@@ -22,3 +22,4 @@ test('T11649', [normal, normalise_errmsg_fun(ignore_llvm_and_vortex)], compile,
test('T17920fail', cmm_src, compile_fail, ['-no-hs-main'])
test('T25019', unless((arch('x86_64') or arch('i386')) and have_cpu_feature('sse4_2'),skip), compile, ['-msse4.2'])
test('T25353', unless((arch('x86_64') or arch('i386')) and have_cpu_feature('sse4_2'),skip), compile_grep_asm, ['hs', True, '-msse4.2'])
+test('T25606', normal, compile, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a928c326011f1a6bef3289a4c36d4e19b5951229
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a928c326011f1a6bef3289a4c36d4e19b5951229
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20241228/28a66588/attachment-0001.html>
More information about the ghc-commits
mailing list