← Back to Pull requests

[MLIR] Type tree attribute and its translation to LLVM Enzyme's type metadata #3893

Closed
unknown closed this pull request without merging on Nov 18, 2026 17:58 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 10:36 UTC
Author

Split out of #3430 (review: emit MLIR attributes and convert them to LLVM metadata instead of round-tripping through strings). Nothing Fortran-specific here; #3430 is rebased on top of this.

#enzyme.type_tree is Enzyme's TypeTree as a nested attribute in the enzyme dialect. A node has the concrete type of the value, if known (integer, pointer, anything, or a floating-point type), and the subtrees of the memory it points to, each at a byte offset, with -1 for every offset:

#enzyme.type_tree<{-1: pointer {0: f64, 8: integer}}>   // pointer to {double, int}
#enzyme.type_tree<bf16>                                  // a bf16 value
#enzyme.type_tree<>                                      // nothing known

  • The node's type is the new TypeTreeKind enum (EnzymeEnums.td), so the dialect does not include LLVM Enzyme's BaseType.h.

  • The builder and the parser sort subtrees by offset. The verifier rejects a duplicate offset, an offset below -1, an empty subtree, and a floating-point type on a non-float node (or a float node without one).
  • Attributes, verified by the dialect (verifyOperationAttribute, verifyRegionArgAttribute) rather than by the translation:

  • enzyme.type: a type tree, on any op or function argument.

  • enzyme.arg_types: on a call (CallOpInterface), one type tree or unit per argument operand.

  • enzyme.ret_types: on a function (FunctionOpInterface), one type tree or unit per result.
  • The names are EnzymeDialect::getTypeTreeAttrName.

    MLIREnzymeToLLVMIRTranslation (Target/EnzymeToLLVMIRTranslation.cpp, registerEnzymeDialectTranslation) turns them into what LLVM Enzyme's type analysis already reads, without parsing anything:

  • enzyme.type on a global → !enzyme_type metadata; on another op → !enzyme_type on every instruction it lowers to; on a function argument → its "enzyme_type" attribute.

  • enzyme.arg_types → the "enzyme_type" of each call argument.

  • enzyme.ret_types → the "enzyme_type" of the function result.
  • The metadata is built recursively from the tree in the encoding of TypeTree::toMD. "enzyme_type" attributes stay strings in TypeTree::str syntax ({[-1]:Pointer, [-1,0]:Float@double}), because LLVM Enzyme reads them as strings. Concrete type names come from ConcreteType, which is included as TypeAnalysis/ConcreteType.h. enzymemlir-translate gets an -enzyme-to-llvmir translation that registers this interface; -activity-to-llvm keeps its own, since a dialect can have only one LLVM translation interface.

    Tests:

  • MLIR/Passes/type_tree_attr.mlir: round trip, subtree sorting, and one negative case per verifier diagnostic.

  • MLIR/Passes/type_tree_to_llvm.mlir: global, argument, result, call and instruction translation. It requires the new lit feature enzymemlir-translate, which is set when the %etranslate binary exists.
  • Tested locally against LLVM main (with the 4 LLVM 24 port commits reverted to match that toolchain): check-enzymemlir passes, 239 passed and 1 expected failure, including both new tests.

    ---
    _Generated by Claude Code_

    Diff: 396 lines (+297 / -99) across 4 files Reviewer: vchuravy Review duration: 3321m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 396 lines diff across 4 files
    0.43
    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.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3893"
    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: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    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: 17.1% · Safe to merge
    17.1%