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

Commits:

3 changed files:

Changes:

  • changelog.d/print-enabled-cpu-features
    1
    +section: compiler
    
    2
    +synopsis: Add --print-enabled-cpu-features flag
    
    3
    +issues: #25450
    
    4
    +mrs: !16117
    
    5
    +
    
    6
    +description: {
    
    7
    +  GHC now supports a new mode flag ``--print-enabled-cpu-features``, which
    
    8
    +  prints a JSON object describing the CPU features currently enabled for code
    
    9
    +  generation, together with a minimal set of ``-m...`` flags that would
    
    10
    +  reproduce the non-default effective feature set for the current target.
    
    11
    +  Dynamic options such as ``-mavx2`` and ``-mbmi2`` are respected. ::
    
    12
    +
    
    13
    +    $ ghc -mavx2 --print-enabled-cpu-features
    
    14
    +    {"tag":"enabled-cpu-features","version":1,"target":"x86_64-linux-gnu",
    
    15
    +     "features":["SSE2","SSE3","SSSE3","SSE4.1","SSE4.2","AVX","AVX2"],
    
    16
    +     "as_m_flags":["-mavx2"]}
    
    17
    +
    
    18
    +  This is a first step toward implementing ``-march=native`` (:ghc-ticket:`25450`).
    
    19
    +}

  • compiler/GHC/Driver/DynFlags.hs
    ... ... @@ -1615,6 +1615,7 @@ initPromotionTickContext dflags =
    1615 1615
     
    
    1616 1616
     -- -----------------------------------------------------------------------------
    
    1617 1617
     -- SSE, AVX, FMA
    
    1618
    +-- See Note [Keeping enabledCpuFeatures in sync] in GHC.Driver.Session
    
    1618 1619
     
    
    1619 1620
     isSse3Enabled :: DynFlags -> Bool
    
    1620 1621
     isSse3Enabled dflags = sseAvxVersion dflags >= Just SSE3 || isAvxEnabled dflags
    
    ... ... @@ -1705,11 +1706,14 @@ We handle this as follows:
    1705 1706
     
    
    1706 1707
     -- -----------------------------------------------------------------------------
    
    1707 1708
     -- LA664
    
    1709
    +-- See Note [Keeping enabledCpuFeatures in sync] in GHC.Driver.Session
    
    1710
    +
    
    1708 1711
     isLa664Enabled :: DynFlags -> Bool
    
    1709 1712
     isLa664Enabled dflags = la664 dflags
    
    1710 1713
     
    
    1711 1714
     -- -----------------------------------------------------------------------------
    
    1712 1715
     -- BMI2
    
    1716
    +-- See Note [Keeping enabledCpuFeatures in sync] in GHC.Driver.Session
    
    1713 1717
     
    
    1714 1718
     isBmiEnabled :: DynFlags -> Bool
    
    1715 1719
     isBmiEnabled dflags = case platformArch (targetPlatform dflags) of
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -3691,6 +3691,22 @@ showEnabledCpuFeatures dflags = showSDocUnsafe $ renderJSON $ JSObject
    3691 3691
       where
    
    3692 3692
         (features, asMFlags) = enabledCpuFeatures dflags
    
    3693 3693
     
    
    3694
    +{- Note [Keeping enabledCpuFeatures in sync]
    
    3695
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    3696
    +`enabledCpuFeatures` must be updated whenever a new CPU feature flag is added
    
    3697
    +to GHC. The three places to touch are, all in GHC.Driver.DynFlags:
    
    3698
    +
    
    3699
    +  1. The flag registration (e.g. `make_ord_flag defGhcFlag "mnewfeat" ...`)
    
    3700
    +  2. The corresponding `is*Enabled` predicate
    
    3701
    +  3. The `enabledCpuFeatures` function below — add the feature to `features`
    
    3702
    +     and, if it has a GHC `-m...` flag, to `as_m_flags` via the appropriate
    
    3703
    +     architecture branch.
    
    3704
    +
    
    3705
    +See Note [Implications between X86 CPU feature flags] in GHC.Driver.DynFlags
    
    3706
    +for the implication structure that `x86FeaturesAndFlags` and `x86AsMFlags`
    
    3707
    +must respect.
    
    3708
    +-}
    
    3709
    +
    
    3694 3710
     enabledCpuFeatures :: DynFlags -> ([String], [String])
    
    3695 3711
     enabledCpuFeatures dflags = case platformArch (targetPlatform dflags) of
    
    3696 3712
       ArchX86_64 -> x86FeaturesAndFlags dflags