nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 103 lines 4.5 kB view raw
1From c1229507e29e5c44b6f23d6f2afb5d55e7fb9606 Mon Sep 17 00:00:00 2001 2From: ARATA Mizuki <minorinoki@gmail.com> 3Date: Wed, 25 Dec 2024 22:50:46 +0900 4Subject: [PATCH] Fix LLVM version detection 5 6With a recent LLVM, `llc -version` emits the version on the first line 7if the vendor is set. It emits the version on the second line 8otherwise. 9 10Therefore, we need to check the both lines to detect the version. 11 12GHC now emits a warning if it fails to detect the LLVM version, 13so we can notice if the output of `llc -version` changes in the future. 14 15Also, the warning for using LLVM < 10 on s390x is removed, because 16we assume LLVM >= 13 now. 17 18This fixes the definition of __GLASGOW_HASKELL_LLVM__ macro. 19 20Fixes #25606 21 22(cherry picked from commit a928c326011f1a6bef3289a4c36d4e19b5951229) 23--- 24 compiler/GHC/CmmToLlvm.hs | 14 ++++++++------ 25 compiler/GHC/SysTools/Tasks.hs | 13 ++++++++----- 26 docs/users_guide/phases.rst | 2 +- 27 3 files changed, 17 insertions(+), 12 deletions(-) 28 29diff --git a/compiler/GHC/CmmToLlvm.hs b/compiler/GHC/CmmToLlvm.hs 30index ecf111c636..76541c477c 100644 31--- a/compiler/GHC/CmmToLlvm.hs 32+++ b/compiler/GHC/CmmToLlvm.hs 33@@ -38,7 +38,7 @@ import GHC.Utils.Logger 34 import qualified GHC.Data.Stream as Stream 35 36 import Control.Monad ( when, forM_ ) 37-import Data.Maybe ( fromMaybe, catMaybes ) 38+import Data.Maybe ( fromMaybe, catMaybes, isNothing ) 39 import System.IO 40 41 -- ----------------------------------------------------------------------------- 42@@ -68,11 +68,13 @@ llvmCodeGen logger cfg h cmm_stream 43 "up to" <+> text (llvmVersionStr supportedLlvmVersionUpperBound) <+> "(non inclusive) is supported." <+> 44 "System LLVM version: " <> text (llvmVersionStr ver) $$ 45 "We will try though..." 46- let isS390X = platformArch (llvmCgPlatform cfg) == ArchS390X 47- let major_ver = head . llvmVersionList $ ver 48- when (isS390X && major_ver < 10 && doWarn) $ putMsg logger $ 49- "Warning: For s390x the GHC calling convention is only supported since LLVM version 10." <+> 50- "You are using LLVM version: " <> text (llvmVersionStr ver) 51+ 52+ when (isNothing mb_ver) $ do 53+ let doWarn = llvmCgDoWarn cfg 54+ when doWarn $ putMsg logger $ 55+ "Failed to detect LLVM version!" $$ 56+ "Make sure LLVM is installed correctly." $$ 57+ "We will try though..." 58 59 -- HACK: the Nothing case here is potentially wrong here but we 60 -- currently don't use the LLVM version to guide code generation 61diff --git a/compiler/GHC/SysTools/Tasks.hs b/compiler/GHC/SysTools/Tasks.hs 62index 7cd5188d5f..165e1602cf 100644 63--- a/compiler/GHC/SysTools/Tasks.hs 64+++ b/compiler/GHC/SysTools/Tasks.hs 65@@ -236,14 +236,17 @@ figureLlvmVersion logger dflags = traceToolCommand logger "llc" $ do 66 (pin, pout, perr, p) <- runInteractiveProcess pgm args' 67 Nothing Nothing 68 {- > llc -version 69- LLVM (http://llvm.org/): 70- LLVM version 3.5.2 71+ <vendor> LLVM version 15.0.7 72 ... 73+ OR 74+ LLVM (http://llvm.org/): 75+ LLVM version 14.0.6 76 -} 77 hSetBinaryMode pout False 78- _ <- hGetLine pout 79- vline <- hGetLine pout 80- let mb_ver = parseLlvmVersion vline 81+ line1 <- hGetLine pout 82+ mb_ver <- case parseLlvmVersion line1 of 83+ mb_ver@(Just _) -> return mb_ver 84+ Nothing -> parseLlvmVersion <$> hGetLine pout -- Try the second line 85 hClose pin 86 hClose pout 87 hClose perr 88diff --git a/docs/users_guide/phases.rst b/docs/users_guide/phases.rst 89index 6a2d4b3c20..9ccd2aa034 100644 90--- a/docs/users_guide/phases.rst 91+++ b/docs/users_guide/phases.rst 92@@ -474,7 +474,7 @@ defined by your local GHC installation, the following trick is useful: 93 .. index:: 94 single: __GLASGOW_HASKELL_LLVM__ 95 96- Only defined when `:ghc-flag:`-fllvm` is specified. When GHC is using version 97+ Only defined when :ghc-flag:`-fllvm` is specified. When GHC is using version 98 ``x.y.z`` of LLVM, the value of ``__GLASGOW_HASKELL_LLVM__`` is the 99 integer ⟨xyy⟩ (if ⟨y⟩ is a single digit, then a leading zero 100 is added, so for example when using version 3.7 of LLVM, 101-- 1022.50.1 103