Documentation

SSA.Core.MLIRSyntax.Transform

Transform* typeclasses #

This file defines TransformTy, TransformExpr, and TransformReturn typeclasses, which dictate how generic MLIR syntax (as defined in MLIRSyntax.AST) can be transformed into an instance of Com or Expr for a specific dialect.

instance MLIR.AST.instCoeExprCtxtTy {eff : EffectKind} {d : Dialect} [DialectSignature d] {t : d.Ty} {Γ : Ctxt d.Ty} {Γ' : Γ.DerivedCtxt} :
Coe (Expr d Γ eff t) (Expr d Γ'.ctxt eff t)
Equations
  • MLIR.AST.instCoeExprCtxtTy = { coe := fun (e : Expr d Γ eff t) => Expr.changeVars Γ'.diff.toHom e }

Even though we technically only need to know the Ty type, our typeclass hierarchy is fully based on Op. It is thus more convenient to incorporate Op in these types, so that there will be no ambiguity errors.

@[reducible, inline]
abbrev MLIR.AST.ExceptM (d : Dialect) (α : Type u_1) :
Type u_1
Equations
Instances For
    @[reducible, inline]
    abbrev MLIR.AST.BuilderM (d : Dialect) (α : Type) :
    Equations
    Instances For
      @[reducible, inline]
      abbrev MLIR.AST.ReaderM (d : Dialect) (α : Type) :
      Equations
      Instances For
        Equations
        Equations
        Equations
        Instances For

          These typeclasses provide a natural flow to how users should implement TransformDialect.

          Instances
            Instances
              def MLIR.AST.addValToMapping {d : Dialect} (Γ : Ctxt d.Ty) (name : String) (ty : d.Ty) :
              MLIR.AST.BuilderM d ((Γ' : Γ.DerivedCtxt) × Γ'.ctxt.Var ty)

              Add a new variable to the context, and record it's (absolute) index in the name mapping

              Throws an error if the variable name already exists in the mapping, essentially disallowing shadowing

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                def MLIR.AST.getValFromCtxt {d : Dialect} [DecidableEq d.Ty] (Γ : Ctxt d.Ty) (name : String) (expectedType : d.Ty) :
                MLIR.AST.ReaderM d (Γ.Var expectedType)

                Look up a name from the name mapping, and return the corresponding variable in the given context.

                Throws an error if the name is not present in the mapping (this indicates the name may be free), or if the type of the variable in the context is different from expectedType

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For
                  Equations
                  Instances For
                    Equations
                    Instances For
                      def MLIR.AST.TypedSSAVal.mkVal {d : Dialect} {φ : } [DialectSignature d] [DecidableEq d.Ty] [instTransformTy : MLIR.AST.TransformTy d φ] (Γ : Ctxt d.Ty) :
                      MLIR.AST.TypedSSAVal φMLIR.AST.ReaderM d ((ty : d.Ty) × Γ.Var ty)

                      Translate a TypedSSAVal (a name with an expected type), to a variable in the context. This expects the name to have already been declared before

                      Equations
                      Instances For
                        def MLIR.AST.TypedSSAVal.mkVal' {d : Dialect} {φ : } [DialectSignature d] [DecidableEq d.Ty] [instTransformTy : MLIR.AST.TransformTy d φ] (Γ : Ctxt d.Ty) :
                        MLIR.AST.TypedSSAVal φMLIR.AST.ReaderM d ((ty : d.Ty) × Γ.Var ty)

                        A variant of TypedSSAVal.mkVal that takes the function mkTy as an argument instead of using the typeclass TransformDialect. This is useful when trying to implement an instance of TransformDialect itself, to cut infinite regress.

                        Equations
                        Instances For
                          def MLIR.AST.TypedSSAVal.newVal {d : Dialect} {φ : } [DialectSignature d] [instTransformTy : MLIR.AST.TransformTy d φ] (Γ : Ctxt d.Ty) :
                          MLIR.AST.TypedSSAVal φMLIR.AST.BuilderM d ((Γ' : Γ.DerivedCtxt) × (ty : d.Ty) × Γ'.ctxt.Var ty)

                          Declare a new variable, by adding the passed name to the name mapping stored in the monad state

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            def MLIR.AST.mkCom {d : Dialect} {φ : } [DialectSignature d] [MLIR.AST.TransformTy d φ] [MLIR.AST.TransformExpr d φ] [MLIR.AST.TransformReturn d φ] (reg : MLIR.AST.Region φ) :
                            MLIR.AST.ExceptM d ((Γ : Ctxt d.Ty) × (eff : EffectKind) × (ty : d.Ty) × Com d Γ eff ty)
                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For