Skip to content

Implement s390x LLVM backend.

Stefan Schulze Frielinghaus requested to merge (removed):s390x-llvm into master

Implement s390x LLVM backend

This patch adds support for the s390x architecture for the LLVM code generator. The patch includes a register mapping of STG registers onto s390x machine registers which enables a registerised build.

Bootstrapping

Bootstrapping a registerised GHC using an unregisterised one is not trivial on s390x at the moment. This probably also holds for other architectures.

  • There seem to be multiple problems while building stage0 using wrong header files, see e.g. issue #17111 (closed) or #15913 One way to circumvent this problem is to build an unregisterised version of GHC including the registerise patch. Then use this unregisterised build of GHC in order to build a registerised GHC. In other words:
git clone https://gitlab.haskell.org/ghc/ghc.git
cd ghc
git apply registerise-s390x.patch   # the patch proposed by this MR
cat <<EOF >> includes/stg/MiscClosures.h
#if __GLASGOW_HASKELL__ < 809
RTS_FUN_DECL(stg_atomicModifyMutVarzh);
#endif
EOF
./boot
./configure --enable-unregisterised --prefix=/tmp/ghc-unreg
make
make install
git clean -dfxq
git submodule foreach git clean -dfxq
./boot
./configure GHC=/tmp/ghc-unreg/bin/ghc
make
rm -rf /tmp/ghc-unreg

The fix proposed in issue #15913 i.e. the unregisterised-wrapper which adds another include directory does not work anymore. This seems to be an effect of commit 05419e55 which changes the handling of header files. Another option is to backport this patch to GHC 8.6.5 and use the wrapper-quirk in order to build a registerised GHC from master.

  • At the time of writing this, a recent commit removed the inclusion of some header files including one in which the macro WORDS_BIGENDIAN is defined. You can quick fix this by adding the macro into compiler/HsVersion.hs see issue #17337 (closed)

  • While bootstrapping with an unregisterised and unthreaded RTS you have to fix Hadrian:

diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal
index 818114a4d4..4ffe0161d1 100644
--- a/hadrian/hadrian.cabal
+++ b/hadrian/hadrian.cabal
@@ -146,5 +146,5 @@ executable hadrian
                        --        waiting for external processes
                        -- * -qg: Don't use parallel GC as the synchronization
                        --        time tends to eat any benefit.
-                       "-with-rtsopts=-I0 -qg"
-                       -threaded
+                       -- "-with-rtsopts=-I0 -qg"
+                       -- -threaded
  • Using an unregisterised GHC several unused variables are set but never used. Thus don't error on them:
diff --git a/hadrian/src/Settings/Warnings.hs b/hadrian/src/Settings/Warnings.hs
index ea89fea3ef..5216deee96 100644
--- a/hadrian/src/Settings/Warnings.hs
+++ b/hadrian/src/Settings/Warnings.hs
@@ -12,8 +12,8 @@ defaultGhcWarningsArgs :: Args
 defaultGhcWarningsArgs = mconcat
     [ notStage0 ? arg "-Wnoncanonical-monad-instances"
     , (not <$> flag GccIsClang) ? mconcat
-      [ not windowsHost ? arg "-optc-Werror=unused-but-set-variable"
-      , arg "-optc-Wno-error=inline" ]
+      -- [ not windowsHost ? arg "-optc-Werror=unused-but-set-variable"
+      [ arg "-optc-Wno-error=inline" ]
     , flag GccIsClang ? arg "-optc-Wno-unknown-pragmas" ]
  • Using system libffi with Hadrian seems to be broken at the moment, see issue #16950 (closed)

  • The libffi tarball currently shipped with GHC is outdated with regard to s390x where e.g. the header file internal.h is missing. However, recent upstream versions of libffi include this, e.g., in upstream commit c2a6859. You may also want to have a look at issue libffi-tarballs#1 (closed)

  • StgRun/StgReturn are implemented in assembler files. This requires the Hadrian patches proposed in MR !1909 (closed)

  • There seems to be a big endian bug in containers library which is tracked in issue #16998 Thus atm you have to remove unboxed arrays:

diff --git a/containers/include/containers.h b/containers/include/containers.h
index cd201ca..bd53f9f 100644
--- a/containers/include/containers.h
+++ b/containers/include/containers.h
@@ -35,7 +35,7 @@
 
 #ifdef __GLASGOW_HASKELL__
 # define USE_ST_MONAD 1
-# define USE_UNBOXED_ARRAYS 1
 #endif

Testsuite

Results of running ./validate of a registerised GHC on top of commit d584e3f0 using LLVM 7.0.1 and the quirks fixed from above:

Failed tests: PartialDownsweep T10052 T10508_api T12674 T13825-debugger T16392 T3372 T493 T5313 T5435_v_asm_a T5435_v_asm_b T5435_v_gcc T8628 T8639_api dynCompileExpr ghci004 ghci006 ghcilink004 haddockHoogleTest haddockHtmlTest haddockHypsrcTest haddockLatexTest keep-cafs keep-cafs-fail linker_unload linker_unload_multiple_objs linkwhole openFile008 print002 print022 prog001 regalloc_unit_tests

where the following failing tests can be ignored since they depend on the RTS linker which is not implemented so far:

T10052 T10508_api T16392 T3372 T5313 T5435_v_asm_a T5435_v_asm_b T5435_v_gcc T8628 T8639_api dynCompileExpr ghci004 ghci006 ghcilink004 keep-cafs linker_unload linker_unload_multiple_objs linkwhole prog001

The test regalloc_unit_tests may also be ignored on s390x since freeReg is not implemented.

The following tests succeed if run manually via make TEST=foo. Thus I do not know why they fail while running ./validate:

T12674 haddockHoogleTest haddockHtmlTest haddockHypsrcTest haddockLatexTest

This leaves us with the following testcases which fail without any excuse:

PartialDownsweep T13825-debugger T493 keep-cafs-fail openFile008 print002 print022

Please find attached testsuite_summary.txt

LLVM Calling Convention

A patch for LLVM has been created and if you are fine with this patch for GHC, then I will post a patch for LLVM.

Merge request reports