-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into broken_alive_autogene…
…rated
- Loading branch information
Showing
18 changed files
with
490 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
SSA/Projects/MLIRSyntax/AST.lean → SSA/Core/MLIRSyntax/AST.lean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import SSA.Core.MLIRSyntax.GenericParser | ||
import SSA.Core.MLIRSyntax.Transform | ||
|
||
/-! | ||
# MLIR Dialect Domain Specific Language | ||
This file sets up generic glue meta-code to tie together the generic MLIR parser with the | ||
`Transform` mechanism, to obtain an easy way to specify a DSL that elaborates into `Com`/`Expr` | ||
instances for a specific dialect. | ||
-/ | ||
|
||
namespace SSA | ||
|
||
open Qq Lean Meta Elab Term | ||
open MLIR.AST | ||
|
||
/-- | ||
`elabIntoCom` is a building block for defining a dialect-specific DSL based on the geneeric MLIR | ||
syntax parser. | ||
For example, if `FooOp` is the type of operations of a "Foo" dialect, we can build a term elaborator | ||
for this dialect as follows: | ||
``` | ||
elab "[foo_com| " reg:mlir_region "]" : term => SSA.elabIntoCom reg q(FooOp) | ||
-- ^^^^^^^ ^^^^^ | ||
``` | ||
-/ | ||
def elabIntoCom (region : TSyntax `mlir_region) (Op : Q(Type)) {Ty : Q(Type)} | ||
(_opSignature : Q(OpSignature $Op $Ty) := by exact q(by infer_instance)) | ||
(φ : Q(Nat) := q(0)) | ||
(_transformTy : Q(TransformTy $Op $Ty $φ) := by exact q(by infer_instance)) | ||
(_transformExpr : Q(TransformExpr $Op $Ty $φ) := by exact q(by infer_instance)) | ||
(_transformReturn : Q(TransformReturn $Op $Ty $φ) := by exact q(by infer_instance)) | ||
: | ||
TermElabM Expr := do | ||
let ast_stx ← `([mlir_region| $region]) | ||
let ast ← elabTermEnsuringTypeQ ast_stx q(Region $φ) | ||
let com : Q(MLIR.AST.ExceptM $Op (Σ (Γ' : Ctxt $Ty) (ty : $Ty), Com $Op Γ' ty)) := | ||
q(MLIR.AST.mkCom $ast) | ||
synthesizeSyntheticMVarsNoPostponing | ||
/- Now reduce the term. We do this so that the resulting term will be of the form | ||
`Com.lete _ <| Com.lete _ <| ... <| Com.ret _`, | ||
rather than still containing the `Transform` machinery applied to a raw AST. | ||
This has the side-effect of also fully reducing the expressions involved. | ||
We reduce with mode `.default` so that a dialect can prevent reduction of specific parts | ||
by marking those `irreducible` -/ | ||
let com : Q(MLIR.AST.ExceptM $Op (Σ (Γ' : Ctxt $Ty) (ty : $Ty), Com $Op Γ' ty)) ← | ||
withTheReader Core.Context (fun ctx => { ctx with options := ctx.options.setBool `smartUnfolding false }) do | ||
withTransparency (mode := .default) <| | ||
return ←reduce com | ||
let comExpr : Expr := com | ||
trace[Meta] com | ||
trace[Meta] comExpr | ||
|
||
match comExpr.app3? ``Except.ok with | ||
| .some (_εexpr, _αexpr, aexpr) => | ||
match aexpr.app4? ``Sigma.mk with | ||
| .some (_αexpr, _βexpr, _fstexpr, sndexpr) => | ||
match sndexpr.app4? ``Sigma.mk with | ||
| .some (_αexpr, _βexpr, _fstexpr, sndexpr) => | ||
return sndexpr | ||
| .none => throwError "Found `Except.ok (Sigma.mk _ WRONG)`, Expected (Except.ok (Sigma.mk _ (Sigma.mk _ _))" | ||
| .none => throwError "Found `Except.ok WRONG`, Expected (Except.ok (Sigma.mk _ _))" | ||
| .none => throwError "Expected `Except.ok`, found {comExpr}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
SSA/Projects/InstCombine/LLVM/Transform.lean → SSA/Core/MLIRSyntax/Transform.lean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ombine/LLVM/Transform/TransformError.lean → .../MLIRSyntax/Transform/TransformError.lean
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import SSA.Projects.MLIRSyntax.AST | ||
import SSA.Core.MLIRSyntax.AST | ||
|
||
namespace MLIR.AST | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import SSA.Projects.FullyHomomorphicEncryption.Basic | ||
import SSA.Projects.FullyHomomorphicEncryption.Statements | ||
import SSA.Projects.FullyHomomorphicEncryption.Rewrites | ||
import SSA.Projects.FullyHomomorphicEncryption.Statements | ||
import SSA.Projects.FullyHomomorphicEncryption.Syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.