[Git][ghc/ghc][wip/romes/configure-qunused-args] Configure -Qunused-arguments instead of hardcoding it

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Tue Jun 6 12:28:00 UTC 2023



Rodrigo Mesquita pushed to branch wip/romes/configure-qunused-args at Glasgow Haskell Compiler / GHC


Commits:
f29cd0c1 by Rodrigo Mesquita at 2023-06-06T13:27:10+01:00
Configure -Qunused-arguments instead of hardcoding it

When GHC invokes clang, it currently passes -Qunused-arguments to
discard warnings resulting from GHC using multiple options that aren't
used.

In this commit, we configure -Qunused-arguments into the Cc options
instead of checking if the compiler is clang at runtime and hardcoding
the flag into GHC.

This is part of the effort to centralise toolchain information in
toolchain target files at configure time with the end goal of a runtime
retargetable GHC.

This also means we don't need to call getCompilerInfo ever, which
improves performance considerably (see !10589).

Metric Decrease:
    PmSeriesG
    T10421
    T11303b
    T12150
    T12227
    T12234
    T12425
    T13035
    T13253-spj
    T13386
    T15703
    T16875
    T17836b
    T17977
    T17977b
    T18140
    T18282
    T18304
    T18698a
    T18698b
    T18923
    T20049
    T21839c
    T3064
    T5030
    T5321FD
    T5321Fun
    T5837
    T6048
    T9020
    T9198
    T9872d
    T9961

- - - - -


4 changed files:

- compiler/GHC/Driver/Pipeline/Execute.hs
- configure.ac
- distrib/configure.ac.in
- + m4/fp_cc_ignore_unused_args.m4


Changes:

=====================================
compiler/GHC/Driver/Pipeline/Execute.hs
=====================================
@@ -292,11 +292,7 @@ runAsPhase with_cpp pipe_env hsc_env location input_fn = do
 
         -- LLVM from version 3.0 onwards doesn't support the OS X system
         -- assembler, so we use clang as the assembler instead. (#5636)
-        let (as_prog, get_asm_info) =
-                ( applyAssemblerProg $ backendAssemblerProg (backend dflags)
-                , applyAssemblerInfoGetter $ backendAssemblerInfoGetter (backend dflags)
-                )
-        asmInfo <- get_asm_info logger dflags platform
+        let as_prog = applyAssemblerProg $ backendAssemblerProg (backend dflags)
 
         let cmdline_include_paths = includePaths dflags
         let pic_c_flags = picCCOpts dflags
@@ -330,9 +326,6 @@ runAsPhase with_cpp pipe_env hsc_env location input_fn = do
                        ++ [ GHC.SysTools.Option "-Wa,--no-type-check"
                           | platformArch (targetPlatform dflags) == ArchWasm32]
 
-                       ++ (if any (asmInfo ==) [Clang, AppleClang, AppleClang51]
-                            then [GHC.SysTools.Option "-Qunused-arguments"]
-                            else [])
                        ++ [ GHC.SysTools.Option "-x"
                           , if with_cpp
                               then GHC.SysTools.Option "assembler-with-cpp"
@@ -400,19 +393,6 @@ runForeignJsPhase pipe_env hsc_env _location input_fn = do
   return output_fn
 
 
-applyAssemblerInfoGetter
-    :: DefunctionalizedAssemblerInfoGetter
-    -> Logger -> DynFlags -> Platform -> IO CompilerInfo
-applyAssemblerInfoGetter StandardAssemblerInfoGetter logger dflags _platform =
-    getAssemblerInfo logger dflags
-applyAssemblerInfoGetter JSAssemblerInfoGetter _ _ _ =
-    pure Emscripten
-applyAssemblerInfoGetter DarwinClangAssemblerInfoGetter logger dflags platform =
-    if platformOS platform == OSDarwin then
-        pure Clang
-    else
-        getAssemblerInfo logger dflags
-
 applyAssemblerProg
     :: DefunctionalizedAssemblerProg
     -> Logger -> DynFlags -> Platform -> [Option] -> IO ()


=====================================
configure.ac
=====================================
@@ -663,6 +663,12 @@ FP_CC_SUPPORTS_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_CXX_OPTS_STAGE0
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINKER_OPTS_STAGE1])
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2], [CONF_GCC_LINKER_OPTS_STAGE2])
 
+dnl Pass -Qunused-arguments or otherwise GHC will have very noisy invocations of Clang
+dnl TODO: Do we need -Qunused-arguments in CXX and GCC linker too?
+FP_CC_IGNORE_UNUSED_ARGS([$CC_STAGE0], [CONF_CC_OPTS_STAGE0])
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE1])
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2])
+
 # See rules/distdir-way-opts.mk for details.
 # Flags passed to the C compiler
 AC_SUBST(CONF_CC_OPTS_STAGE0)


=====================================
distrib/configure.ac.in
=====================================
@@ -223,6 +223,10 @@ dnl CONF_CC_OPTS_STAGE[12] accordingly.
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINK_OPTS_STAGE1])
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2], [CONF_GCC_LINK_OPTS_STAGE2])
 
+dnl Pass -Qunused-arguments or otherwise GHC will have very noisy invocations of Clang
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE1])
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2])
+
 dnl TargetWordSize for settings file
 AC_CHECK_SIZEOF(void *, 4)
 if test "x$ac_cv_sizeof_void_p" = "x0"; then


=====================================
m4/fp_cc_ignore_unused_args.m4
=====================================
@@ -0,0 +1,31 @@
+# FP_CC_IGNORE_UNUSED_ARGS
+# ------------------------
+# GHC tends to produce command-lines with unused arguments that elicit
+# warnings from Clang. Clang offers the @-Qunused-arguments@ flag to silence
+# these. See #11684.
+#
+# The primary effect of this is updating CONF_CC_OPTS_STAGE[12] to explicitly
+# pass -Qunused-arguments to Clang, since otherwise Cc invocations by GHC will
+# be very noisy
+#
+# $1 = CC
+# $2 = CC_OPTS variable
+AC_DEFUN([FP_CC_IGNORE_UNUSED_ARGS],
+[
+   AC_MSG_CHECKING([whether $1 supports -Qunused-arguments])
+   echo 'int main() { return 0; }' > conftest.c
+   if $1 -Qunused-arguments -Werror conftest.c > /dev/null 2>&1 ; then
+       CONF_CC_SUPPORTS_TARGET=YES
+       AC_MSG_RESULT([yes])
+   else
+       CONF_CC_SUPPORTS_TARGET=NO
+       AC_MSG_RESULT([no])
+   fi
+   rm -f conftest.c conftest
+
+   if test $CONF_CC_SUPPORTS_TARGET = YES ; then
+       $2="$$2 -Qunused-arguments"
+   fi
+])
+
+



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

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


More information about the ghc-commits mailing list