Simon Jakobi pushed to branch wip/sjakobi/T25450-print-cpu at Glasgow Haskell Compiler / GHC Commits: 2aa5c714 by Simon Jakobi at 2026-05-29T03:40:40+02:00 Add note - - - - - 73ba41d4 by Simon Jakobi at 2026-05-29T03:49:53+02:00 add changelog - - - - - 4800551a by Simon Jakobi at 2026-05-29T03:55:41+02:00 changelog.d: Add MR number - - - - - 3 changed files: - + changelog.d/print-enabled-cpu-features - compiler/GHC/Driver/DynFlags.hs - compiler/GHC/Driver/Session.hs Changes: ===================================== changelog.d/print-enabled-cpu-features ===================================== @@ -0,0 +1,19 @@ +section: compiler +synopsis: Add --print-enabled-cpu-features flag +issues: #25450 +mrs: !16117 + +description: { + GHC now supports a new mode flag ``--print-enabled-cpu-features``, which + prints a JSON object describing the CPU features currently enabled for code + generation, together with a minimal set of ``-m...`` flags that would + reproduce the non-default effective feature set for the current target. + Dynamic options such as ``-mavx2`` and ``-mbmi2`` are respected. :: + + $ ghc -mavx2 --print-enabled-cpu-features + {"tag":"enabled-cpu-features","version":1,"target":"x86_64-linux-gnu", + "features":["SSE2","SSE3","SSSE3","SSE4.1","SSE4.2","AVX","AVX2"], + "as_m_flags":["-mavx2"]} + + This is a first step toward implementing ``-march=native`` (:ghc-ticket:`25450`). +} ===================================== compiler/GHC/Driver/DynFlags.hs ===================================== @@ -1615,6 +1615,7 @@ initPromotionTickContext dflags = -- ----------------------------------------------------------------------------- -- SSE, AVX, FMA +-- See Note [Keeping enabledCpuFeatures in sync] in GHC.Driver.Session isSse3Enabled :: DynFlags -> Bool isSse3Enabled dflags = sseAvxVersion dflags >= Just SSE3 || isAvxEnabled dflags @@ -1705,11 +1706,14 @@ We handle this as follows: -- ----------------------------------------------------------------------------- -- LA664 +-- See Note [Keeping enabledCpuFeatures in sync] in GHC.Driver.Session + isLa664Enabled :: DynFlags -> Bool isLa664Enabled dflags = la664 dflags -- ----------------------------------------------------------------------------- -- BMI2 +-- See Note [Keeping enabledCpuFeatures in sync] in GHC.Driver.Session isBmiEnabled :: DynFlags -> Bool isBmiEnabled dflags = case platformArch (targetPlatform dflags) of ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -3691,6 +3691,22 @@ showEnabledCpuFeatures dflags = showSDocUnsafe $ renderJSON $ JSObject where (features, asMFlags) = enabledCpuFeatures dflags +{- Note [Keeping enabledCpuFeatures in sync] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +`enabledCpuFeatures` must be updated whenever a new CPU feature flag is added +to GHC. The three places to touch are, all in GHC.Driver.DynFlags: + + 1. The flag registration (e.g. `make_ord_flag defGhcFlag "mnewfeat" ...`) + 2. The corresponding `is*Enabled` predicate + 3. The `enabledCpuFeatures` function below — add the feature to `features` + and, if it has a GHC `-m...` flag, to `as_m_flags` via the appropriate + architecture branch. + +See Note [Implications between X86 CPU feature flags] in GHC.Driver.DynFlags +for the implication structure that `x86FeaturesAndFlags` and `x86AsMFlags` +must respect. +-} + enabledCpuFeatures :: DynFlags -> ([String], [String]) enabledCpuFeatures dflags = case platformArch (targetPlatform dflags) of ArchX86_64 -> x86FeaturesAndFlags dflags View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ea38432b0d66ca1b57042e0f5824318... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ea38432b0d66ca1b57042e0f5824318... You're receiving this email because of your account on gitlab.haskell.org.