← Back to Pull requests

FlangEnzymeMLIR: a flang plugin for Enzyme's MLIR passes, loaded by FlangEnzyme #3848

Closed
unknown closed this pull request without merging on Nov 19, 2026 21:57 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 14:06 UTC
Author

<!-- claude-projects-attribution: {"github_login":"vchuravy"} -->
_Requested by Valentin · project thread_

This is the smallest part of #2968 that the FIR type annotations (#3430) need, together with the FlangEnzyme loader from #3436. It adds no passes yet: FlangEnzymeMLIR is an empty plugin shell, with the build, test and CI wiring around it. #3430 is stacked on top of this PR and adds the first pass.

What is in it

  • Plugin: FlangEnzymeMLIR-<v>, a module for flang -fc1 -load, in Enzyme/MLIR/Flang. It resolves MLIR, FIR and flang symbols from the host.

  • Loader (from #3436): FlangEnzyme dlopens FlangEnzymeMLIR when the host exports fir::registerPassPipelineConfigCallback, which it tests through a weak declaration. So --config=FlangEnzyme-<v>.cfg is enough, and no extra -Xflang -load is needed. Outside flang (e.g. opt) nothing is loaded.

  • CMake options:

  • - ENZYME_FLANG=ON implies ENZYME_MLIR=ON on LLVM 24 or newer, the first version with flang's pipeline callback.
    - ENZYME_FLANG_MLIR builds the plugin. It defaults to ON when ENZYME_FLANG is on and LLVM is 24 or newer, and needs Flang's CMake package.
    - ENZYME_FLANG_MLIR_LOADER (default ON) builds the loader into FlangEnzyme; turn it off to keep the two plugins independent.
  • Tests: lit gets %flang_fc1 and %flang_enzyme substitutions and a flang_enzyme_mlir feature (LLVM 24 or newer). test/MLIR/FIR adds check-enzymemlir-fir with a smoke test that the plugin loads.

  • CI: the existing enzyme-mlir.yml job now builds flang as part of its LLVM build (with FLANG_PLUGIN_SUPPORT=ON) and configures Enzyme with ENZYME_FLANG and ENZYME_FORTRAN. The LLVM cache key changes so that cached builds without flang are not reused.
  • What is left out of #2968

    These parts are not needed for type annotations:

  • The HLFIR differentiation and call lowering: HLFIREnzymeCallLowering, EnzymeFortranAutoDiffRegistration, HLFIRAutoDiffOpInterfaceImpl.h, and the lower_fortran_calls test.

  • The fir-opt plugin enzyme-fir-plugin.cpp, along with %fir_enzyme and enzyme_module.
  • Those can follow on top of this PR if they are wanted.

    Known rough edge

    flang -fc1 does not find the intrinsic modules by itself, so lit asks the driver for the directory of __fortran_builtins.mod and passes it with -fintrinsic-modules-path. Flang's module layout is being reworked upstream; this lookup should be revisited once that settles.

    Why

    MITgcm with flang plus Enzyme fails in TypeAnalysis on untyped integer COMMON blocks. flang's TBAA tags carry no scalar type, so TypeAnalysis gets nothing from them. The FIR type annotations in #3430 fix this by emitting !enzyme_type from FIR, and they need this plugin to run inside flang.

    Supersedes #3436.

    🤖 Generated with Claude Code

    Diff: 374 lines (+280 / -94) across 4 files Reviewer: vchuravy Review duration: 9110m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 374 lines diff across 4 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.355
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #3848"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.9% · Safe to merge
    18.9%