Simon Jakobi pushed to branch wip/sjakobi/T25450-print-cpu at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -197,6 +197,7 @@ module GHC.Driver.Session (
    197 197
             -- * Compiler configuration suitable for display to the user
    
    198 198
             compilerInfo,
    
    199 199
             showEnabledCpuFeatures,
    
    200
    +        enabledCpuFeatures,
    
    200 201
     
    
    201 202
             targetHasRTSWays,
    
    202 203
     
    
    ... ... @@ -3542,104 +3543,6 @@ picPOpts dflags
    3542 3543
      | gopt Opt_PIC dflags = ["-U__PIC__", "-D__PIC__"]
    
    3543 3544
      | otherwise           = []
    
    3544 3545
     
    
    3545
    -showEnabledCpuFeatures :: DynFlags -> String
    
    3546
    -showEnabledCpuFeatures dflags = showSDocUnsafe $ renderJSON $ JSObject
    
    3547
    -  [ ("tag", JSString "enabled-cpu-features")
    
    3548
    -  , ("version", JSInt 1)
    
    3549
    -  , ("target", JSString (platformMisc_targetPlatformString (platformMisc dflags)))
    
    3550
    -  , ("features", JSArray (map JSString features))
    
    3551
    -  , ("as_m_flags", JSArray (map JSString asMFlags))
    
    3552
    -  ]
    
    3553
    -  where
    
    3554
    -    (features, asMFlags) = enabledCpuFeatures dflags
    
    3555
    -
    
    3556
    -enabledCpuFeatures :: DynFlags -> ([String], [String])
    
    3557
    -enabledCpuFeatures dflags = case platformArch (targetPlatform dflags) of
    
    3558
    -  ArchX86_64 -> x86FeaturesAndFlags dflags
    
    3559
    -  ArchX86    -> x86FeaturesAndFlags dflags
    
    3560
    -  ArchAArch64 ->
    
    3561
    -    ( [ "FMA" | isFmaEnabled dflags ]
    
    3562
    -    , []
    
    3563
    -    )
    
    3564
    -  ArchLoongArch64 ->
    
    3565
    -    ( [ "LA664" | isLa664Enabled dflags ]
    
    3566
    -    , [ "-mla664" | la664 dflags ]
    
    3567
    -    )
    
    3568
    -  _ ->
    
    3569
    -    ([], [])
    
    3570
    -
    
    3571
    -x86FeaturesAndFlags :: DynFlags -> ([String], [String])
    
    3572
    -x86FeaturesAndFlags dflags =
    
    3573
    -  ( [ "SSE2"     | isSse2Enabled platform ]
    
    3574
    - ++ [ "SSE3"     | isSse3Enabled dflags ]
    
    3575
    - ++ [ "SSSE3"    | isSsse3Enabled dflags ]
    
    3576
    - ++ [ "SSE4.1"   | isSse4_1Enabled dflags ]
    
    3577
    - ++ [ "SSE4.2"   | isSse4_2Enabled dflags ]
    
    3578
    - ++ [ "AVX"      | isAvxEnabled dflags ]
    
    3579
    - ++ [ "AVX2"     | isAvx2Enabled dflags ]
    
    3580
    - ++ [ "AVX512F"  | isAvx512fEnabled dflags ]
    
    3581
    - ++ [ "AVX512BW" | isAvx512bwEnabled dflags ]
    
    3582
    - ++ [ "AVX512CD" | isAvx512cdEnabled dflags ]
    
    3583
    - ++ [ "AVX512DQ" | isAvx512dqEnabled dflags ]
    
    3584
    - ++ [ "AVX512ER" | isAvx512erEnabled dflags ]
    
    3585
    - ++ [ "AVX512PF" | isAvx512pfEnabled dflags ]
    
    3586
    - ++ [ "AVX512VL" | isAvx512vlEnabled dflags ]
    
    3587
    - ++ [ "BMI1"     | isBmiEnabled dflags ]
    
    3588
    - ++ [ "BMI2"     | isBmi2Enabled dflags ]
    
    3589
    - ++ [ "FMA"      | isFmaEnabled dflags ]
    
    3590
    - ++ [ "GFNI"     | isGfniEnabled dflags ]
    
    3591
    -  , x86AsMFlags dflags
    
    3592
    -  )
    
    3593
    -  where
    
    3594
    -    platform = targetPlatform dflags
    
    3595
    -
    
    3596
    -x86AsMFlags :: DynFlags -> [String]
    
    3597
    -x86AsMFlags dflags =
    
    3598
    -     avx512Flags
    
    3599
    -  ++ vectorFlags
    
    3600
    -  ++ bmiFlags
    
    3601
    -  ++ fmaFlags
    
    3602
    -  ++ gfniFlags
    
    3603
    -  where
    
    3604
    -    avx512Extensions =
    
    3605
    -      [ ("-mavx512bw", avx512bw dflags)
    
    3606
    -      , ("-mavx512cd", avx512cd dflags)
    
    3607
    -      , ("-mavx512dq", avx512dq dflags)
    
    3608
    -      , ("-mavx512er", avx512er dflags)
    
    3609
    -      , ("-mavx512pf", avx512pf dflags)
    
    3610
    -      , ("-mavx512vl", avx512vl dflags)
    
    3611
    -      ]
    
    3612
    -
    
    3613
    -    hasAvx512Extension = any snd avx512Extensions
    
    3614
    -    hasAvx512 = avx512f dflags || hasAvx512Extension
    
    3615
    -
    
    3616
    -    avx512Flags =
    
    3617
    -      [ "-mavx512f" | avx512f dflags && not hasAvx512Extension ]
    
    3618
    -      ++ [ flag | (flag, True) <- avx512Extensions ]
    
    3619
    -
    
    3620
    -    vectorFlags
    
    3621
    -      | hasAvx512 = []
    
    3622
    -      | otherwise =
    
    3623
    -          case sseAvxVersion dflags of
    
    3624
    -            Just AVX2  -> ["-mavx2"]
    
    3625
    -            Just AVX1  -> ["-mavx"]
    
    3626
    -            Just SSE42 -> ["-msse4.2"]
    
    3627
    -            Just SSE4  -> ["-msse4"]
    
    3628
    -            Just SSSE3 -> ["-mssse3"]
    
    3629
    -            Just SSE3  -> ["-msse3"]
    
    3630
    -            _          -> []
    
    3631
    -
    
    3632
    -    bmiFlags = case bmiVersion dflags of
    
    3633
    -      Just BMI2 -> ["-mbmi2"]
    
    3634
    -      Just BMI1 -> ["-mbmi"]
    
    3635
    -      Nothing   -> []
    
    3636
    -
    
    3637
    -    fmaFlags
    
    3638
    -      | fma dflags && not hasAvx512 = ["-mfma"]
    
    3639
    -      | otherwise = []
    
    3640
    -
    
    3641
    -    gfniFlags = [ "-mgfni" | gfni dflags ]
    
    3642
    -
    
    3643 3546
     -- -----------------------------------------------------------------------------
    
    3644 3547
     -- Compiler Info
    
    3645 3548
     
    
    ... ... @@ -3777,6 +3680,106 @@ compilerInfo dflags
    3777 3680
         queryCmdMaybe p f = expandDirectories (query (maybe "" (prgPath . p) . f))
    
    3778 3681
         queryFlagsMaybe p f = query (maybe "" (unwords . map escapeArg . prgFlags . p) . f)
    
    3779 3682
     
    
    3683
    +showEnabledCpuFeatures :: DynFlags -> String
    
    3684
    +showEnabledCpuFeatures dflags = showSDocUnsafe $ renderJSON $ JSObject
    
    3685
    +  [ ("tag", JSString "enabled-cpu-features")
    
    3686
    +  , ("version", JSInt 1)
    
    3687
    +  , ("target", JSString (platformMisc_targetPlatformString (platformMisc dflags)))
    
    3688
    +  , ("features", JSArray (map JSString features))
    
    3689
    +  , ("as_m_flags", JSArray (map JSString asMFlags))
    
    3690
    +  ]
    
    3691
    +  where
    
    3692
    +    (features, asMFlags) = enabledCpuFeatures dflags
    
    3693
    +
    
    3694
    +enabledCpuFeatures :: DynFlags -> ([String], [String])
    
    3695
    +enabledCpuFeatures dflags = case platformArch (targetPlatform dflags) of
    
    3696
    +  ArchX86_64 -> x86FeaturesAndFlags dflags
    
    3697
    +  ArchX86    -> x86FeaturesAndFlags dflags
    
    3698
    +  ArchAArch64 ->
    
    3699
    +    ( [ "FMA" | isFmaEnabled dflags ]
    
    3700
    +    , [ "-mfma" | fma dflags ]
    
    3701
    +    )
    
    3702
    +  ArchLoongArch64 ->
    
    3703
    +    ( [ "LA664" | isLa664Enabled dflags ]
    
    3704
    +    , [ "-mla664" | isLa664Enabled dflags ]
    
    3705
    +    )
    
    3706
    +  _ ->
    
    3707
    +    ([], [])
    
    3708
    +
    
    3709
    +x86FeaturesAndFlags :: DynFlags -> ([String], [String])
    
    3710
    +x86FeaturesAndFlags dflags =
    
    3711
    +  -- SSE2 is determined by the target platform rather than a dynamic flag,
    
    3712
    +  -- hence isSse2Enabled takes Platform while the others take DynFlags.
    
    3713
    +  ( [ "SSE2"     | isSse2Enabled platform ]
    
    3714
    + ++ [ "SSE3"     | isSse3Enabled dflags ]
    
    3715
    + ++ [ "SSSE3"    | isSsse3Enabled dflags ]
    
    3716
    + ++ [ "SSE4.1"   | isSse4_1Enabled dflags ]
    
    3717
    + ++ [ "SSE4.2"   | isSse4_2Enabled dflags ]
    
    3718
    + ++ [ "AVX"      | isAvxEnabled dflags ]
    
    3719
    + ++ [ "AVX2"     | isAvx2Enabled dflags ]
    
    3720
    + ++ [ "AVX512F"  | isAvx512fEnabled dflags ]
    
    3721
    + ++ [ "AVX512BW" | isAvx512bwEnabled dflags ]
    
    3722
    + ++ [ "AVX512CD" | isAvx512cdEnabled dflags ]
    
    3723
    + ++ [ "AVX512DQ" | isAvx512dqEnabled dflags ]
    
    3724
    + ++ [ "AVX512ER" | isAvx512erEnabled dflags ]
    
    3725
    + ++ [ "AVX512PF" | isAvx512pfEnabled dflags ]
    
    3726
    + ++ [ "AVX512VL" | isAvx512vlEnabled dflags ]
    
    3727
    + ++ [ "BMI1"     | isBmiEnabled dflags ]
    
    3728
    + ++ [ "BMI2"     | isBmi2Enabled dflags ]
    
    3729
    + ++ [ "FMA"      | isFmaEnabled dflags ]
    
    3730
    + ++ [ "GFNI"     | isGfniEnabled dflags ]
    
    3731
    +  , x86AsMFlags dflags
    
    3732
    +  )
    
    3733
    +  where
    
    3734
    +    platform = targetPlatform dflags
    
    3735
    +
    
    3736
    +x86AsMFlags :: DynFlags -> [String]
    
    3737
    +x86AsMFlags dflags =
    
    3738
    +     avx512Flags
    
    3739
    +  ++ vectorFlags
    
    3740
    +  ++ bmiFlags
    
    3741
    +  ++ fmaFlags
    
    3742
    +  ++ gfniFlags
    
    3743
    +  where
    
    3744
    +    avx512Extensions =
    
    3745
    +      [ ("-mavx512bw", avx512bw dflags)
    
    3746
    +      , ("-mavx512cd", avx512cd dflags)
    
    3747
    +      , ("-mavx512dq", avx512dq dflags)
    
    3748
    +      , ("-mavx512er", avx512er dflags)
    
    3749
    +      , ("-mavx512pf", avx512pf dflags)
    
    3750
    +      , ("-mavx512vl", avx512vl dflags)
    
    3751
    +      ]
    
    3752
    +
    
    3753
    +    hasAvx512Extension = any snd avx512Extensions
    
    3754
    +    hasAvx512 = avx512f dflags || hasAvx512Extension
    
    3755
    +
    
    3756
    +    avx512Flags =
    
    3757
    +      [ "-mavx512f" | avx512f dflags && not hasAvx512Extension ]
    
    3758
    +      ++ [ flag | (flag, True) <- avx512Extensions ]
    
    3759
    +
    
    3760
    +    vectorFlags
    
    3761
    +      | hasAvx512 = []
    
    3762
    +      | otherwise =
    
    3763
    +          case sseAvxVersion dflags of
    
    3764
    +            Just AVX2  -> ["-mavx2"]
    
    3765
    +            Just AVX1  -> ["-mavx"]
    
    3766
    +            Just SSE42 -> ["-msse4.2"]
    
    3767
    +            Just SSE4  -> ["-msse4"]
    
    3768
    +            Just SSSE3 -> ["-mssse3"]
    
    3769
    +            Just SSE3  -> ["-msse3"]
    
    3770
    +            _          -> []
    
    3771
    +
    
    3772
    +    bmiFlags = case bmiVersion dflags of
    
    3773
    +      Just BMI2 -> ["-mbmi2"]
    
    3774
    +      Just BMI1 -> ["-mbmi"]
    
    3775
    +      Nothing   -> []
    
    3776
    +
    
    3777
    +    fmaFlags
    
    3778
    +      | fma dflags && not hasAvx512 = ["-mfma"]
    
    3779
    +      | otherwise = []
    
    3780
    +
    
    3781
    +    gfniFlags = [ "-mgfni" | gfni dflags ]
    
    3782
    +
    
    3780 3783
     -- | Query if the target RTS has the given 'Ways'. It's computed from
    
    3781 3784
     -- the @"RTS ways"@ field in the settings file.
    
    3782 3785
     targetHasRTSWays :: DynFlags -> Ways -> Bool
    

  • ghc/Main.hs
    ... ... @@ -280,7 +280,7 @@ main' postLoadMode units dflags0 args flagWarnings = do
    280 280
                ShowPackages           -> liftIO $ showUnits hsc_env
    
    281 281
                DoFrontend f           -> doFrontend f srcs
    
    282 282
                DoBackpack             -> doBackpack (map fst srcs)
    
    283
    -           PrintEnabledCpuFeatures -> panic "main': unexpected PrintEnabledCpuFeatures"
    
    283
    +           PrintEnabledCpuFeatures -> panic "impossible: PrintEnabledCpuFeatures handled before session setup"
    
    284 284
     
    
    285 285
           liftIO $ dumpFinalStats logger
    
    286 286