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.
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.
Equations
- MLIR.AST.ExceptM d = Except (MLIR.AST.TransformError d.Ty)
Instances For
Equations
Instances For
Equations
Instances For
Equations
- MLIR.AST.instMonadLiftReaderMBuilderM = { monadLift := fun {α : Type} (x : MLIR.AST.ReaderM d α) => do let __do_lift ← get liftM (ReaderT.run x __do_lift) }
Equations
- MLIR.AST.instMonadLiftExceptMReaderM = { monadLift := fun {α : Type} (x : MLIR.AST.ExceptM d α) => do let __do_lift ← liftM x pure __do_lift }
Equations
- k.runWithEmptyMapping = Prod.fst <$> StateT.run k []
Instances For
These typeclasses provide a natural flow to how users should implement TransformDialect
.
- First declare how to transform types with
TransformTy
. - Second, using
TransformTy
, declare how to transform expressions withTransformExpr
. - Third, using both type and expression conversion, declare how to transform
returns with
TransformReturn
. - These three automatically give an instance of
TransformDialect
.
- mkTy : MLIR.AST.MLIRType φ → MLIR.AST.ExceptM d d.Ty
Instances
- mkExpr : (Γ : List d.Ty) → MLIR.AST.Op φ → MLIR.AST.ReaderM d ((eff : EffectKind) × (ty : d.Ty) × Expr d Γ eff ty)
Instances
- mkReturn : (Γ : List d.Ty) → MLIR.AST.Op φ → MLIR.AST.ReaderM d ((eff : EffectKind) × (ty : d.Ty) × Com d Γ eff ty)
Instances
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
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
- x.isOk = match StateT.run x [] with | Except.ok a => true | Except.error a => false
Instances For
Equations
- x.isErr = match StateT.run x [] with | Except.ok a => true | Except.error a => false
Instances For
Equations
Instances For
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
- MLIR.AST.TypedSSAVal.mkVal Γ (MLIR.AST.SSAVal.SSAVal a, ty) = do let ty ← liftM (MLIR.AST.TransformTy.mkTy ty) let var ← MLIR.AST.getValFromCtxt Γ a ty pure ⟨ty, var⟩
Instances For
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
- MLIR.AST.TypedSSAVal.mkVal' Γ (MLIR.AST.SSAVal.SSAVal a, ty) = do let ty ← liftM (MLIR.AST.TransformTy.mkTy ty) let var ← MLIR.AST.getValFromCtxt Γ a ty pure ⟨ty, var⟩
Instances For
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
Equations
- One or more equations did not get rendered due to their size.