[Git][ghc/ghc][master] Add -mcmodel=medium moduleflag to generated LLVM IR on LoongArch platform

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Nov 26 21:08:41 UTC 2024



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
e70d4140 by Wang Xin at 2024-11-26T16:08:10-05:00
Add -mcmodel=medium moduleflag to generated LLVM IR on LoongArch platform

With the Medium code model, the jump range of the generated jump
instruction is larger than that of the Small code model. It's a
temporary fix of the problem descriped in https://gitlab.haskell
.org/ghc/ghc/-/issues/25495. This commit requires that the LLVM
used contains the code of commit 9dd1d451d9719aa91b3bdd59c0c6679
83e1baf05, i.e., version 8.0 and later. Actually we should not
rely on LLVM, so the only way to solve this problem is to implement
the LoongArch backend.

Add new type for codemodel

- - - - -


1 changed file:

- compiler/GHC/CmmToLlvm.hs


Changes:

=====================================
compiler/GHC/CmmToLlvm.hs
=====================================
@@ -221,7 +221,12 @@ cmmMetaLlvmPrelude = do
           case platformArch platform of
             ArchX86_64 | llvmCgAvxEnabled cfg -> [mkStackAlignmentMeta 32]
             _                                 -> []
-  module_flags_metas <- mkModuleFlagsMeta stack_alignment_metas
+  let codel_model_metas =
+          case platformArch platform of
+            -- FIXME: We should not rely on LLVM
+            ArchLoongArch64 -> [mkCodeModelMeta CMMedium]
+            _                                 -> []
+  module_flags_metas <- mkModuleFlagsMeta (stack_alignment_metas ++ codel_model_metas)
   let metas = tbaa_metas ++ module_flags_metas
   cfg <- getConfig
   renderLlvm (ppLlvmMetas cfg metas)
@@ -244,6 +249,15 @@ mkStackAlignmentMeta :: Integer -> ModuleFlag
 mkStackAlignmentMeta alignment =
     ModuleFlag MFBError "override-stack-alignment" (MetaLit $ LMIntLit alignment i32)
 
+-- LLVM's @LLVM::CodeModel::Model@ enumeration
+data CodeModel = CMMedium
+
+-- Pass -mcmodel=medium option to LLVM on LoongArch64
+mkCodeModelMeta :: CodeModel -> ModuleFlag
+mkCodeModelMeta codemodel =
+    ModuleFlag MFBError "Code Model" (MetaLit $ LMIntLit n i32)
+  where
+    n = case codemodel of CMMedium -> 3 -- as of LLVM 8
 
 -- -----------------------------------------------------------------------------
 -- | Marks variables as used where necessary



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e70d41406b5d5638b42c4d8222cd03e76bbfeb86

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e70d41406b5d5638b42c4d8222cd03e76bbfeb86
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/20241126/af8d1e83/attachment-0001.html>


More information about the ghc-commits mailing list