On Tue, 10 Feb 2026 10:34:34 +0800 fanpeng wrote:
Re-generate the 0004-* patch based on the latest code.
> Yes, It‘s also possible to use only the parameters in
EXTRA_HADRIAN_FLAGS.
>
> In addition, I notice that the content of this patch 0004-* patch will
> conflict, but this modification for Loong64 is necessary if the LLvm
> backend is used.
>
>
> diff --git a/compiler/GHC/CmmToLlvm.hs b/compiler/GHC/CmmToLlvm.hs
> index de5d84c..ac52827 100644
> --- a/compiler/GHC/CmmToLlvm.hs
> +++ b/compiler/GHC/CmmToLlvm.hs
> @@ -219,7 +219,13 @@ cmmMetaLlvmPrelude = do
> ArchX86_64 | llvmCgAvxEnabled cfg ->
[mkStackAlignmentMeta 32]
> _ -> []
> module_flags_metas <- mkModuleFlagsMeta stack_alignment_metas
> - let metas = tbaa_metas ++ module_flags_metas
> + let code_model_metas =
> + case platformArch platform of
> + -- FIXME: We should not rely on LLVM
> + ArchLoongArch64 -> [mkCodeModelMeta CMMedium]
> + _ -> []
> + mcmodel_flags_metas <- mkModuleFlagsMeta code_model_metas
> + let metas = tbaa_metas ++ module_flags_metas ++ mcmodel_flags_metas
> cfg <- getConfig
> renderLlvm (ppLlvmMetas cfg metas)
> (ppLlvmMetas cfg metas)
> @@ -241,6 +247,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
>
>
> On Sun, 25 Jan 2026 09:53:36 +0100 John Paul Adrian Glaubitz wrote:
>
> > Hi fanpeng,
> >
> > On Wed, 2026-01-14 at 06:32 +0000, fanpeng wrote:
> > > And the 0005-* patch is also required for C files.
> >
> > Did you forget this particular patch? I'm not seeing it here.
> >
> > Why not just keep the parameters in EXTRA_HADRIAN_FLAGS?
> >
> > Adrian
> >
> >
>From e70d41406b5d5638b42c4d8222cd03e76bbfeb86 Mon Sep 17 00:00:00 2001
From: Xin Wang <[email protected]>
Date: Mon, 13 Dec 2024 10:45:20 +0800
Subject: [PATCH] llvmGen: Pass mcmodel medium option to LLVM backend on LoongArch
---
compiler/GHC/CmmToLlvm.hs | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
--- a/compiler/GHC/CmmToLlvm.hs
+++ b/compiler/GHC/CmmToLlvm.hs
@@ -219,7 +219,13 @@ cmmMetaLlvmPrelude = do
ArchX86_64 | llvmCgAvxEnabled cfg -> [mkStackAlignmentMeta 32]
_ -> []
module_flags_metas <- mkModuleFlagsMeta stack_alignment_metas
- let metas = tbaa_metas ++ module_flags_metas
+ let code_model_metas =
+ case platformArch platform of
+ -- FIXME: We should not rely on LLVM
+ ArchLoongArch64 -> [mkCodeModelMeta CMMedium]
+ _ -> []
+ mcmodel_flags_metas <- mkModuleFlagsMeta code_model_metas
+ let metas = tbaa_metas ++ module_flags_metas ++ mcmodel_flags_metas
cfg <- getConfig
renderLlvm (ppLlvmMetas cfg metas)
(ppLlvmMetas cfg metas)
@@ -241,6 +247,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