-
Notifications
You must be signed in to change notification settings - Fork 142
Add cheddar emitter #2994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexanderViand
wants to merge
13
commits into
google:main
Choose a base branch
from
AlexanderViand:cheddar-emitter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add cheddar emitter #2994
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
77e6bf8
cheddar: dialect support for emitc lowering (DPS decode, TensorOrMemR…
AlexanderViand 3e77023
cheddar: accept tensor-or-memref diagonals on linear_transform
AlexanderViand 34677e9
cheddar: split Context into Context + BootContext; type eval_poly coe…
AlexanderViand 5322536
cheddar: allow cheddar types as memref/tensor element types
AlexanderViand 734ddad
cheddar-to-emitc: emitc-based CHEDDAR backend emitter + bufferization
AlexanderViand c62b4ed
cheddar-to-emitc: emit encode scale verbatim (drop GetScale/exact_sca…
AlexanderViand d0d0a30
cheddar-to-emitc: fix array-attr literal emission (braces + float pre…
AlexanderViand 99cfa47
cheddar-to-emitc: emit LinearTransform/EvalPoly via prelude shims
AlexanderViand 7f96779
cheddar-to-emitc: lower boot directly on a BootContext (drop static_c…
AlexanderViand 179da31
cheddar-to-emitc: add doctest; simplify written-array walk; note tens…
AlexanderViand 767106c
cheddar-to-emitc: simplify inout-arg detection with llvm::all_of
AlexanderViand 8dd409d
cheddar-to-emitc: extract in-place result detection into a named func…
AlexanderViand 3587e8e
tools/heir-translate: register --mlir-to-cpp (EmitC -> C++)
AlexanderViand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| load("@heir//lib/Transforms:transforms.bzl", "add_heir_transforms") | ||
| load("@rules_cc//cc:cc_library.bzl", "cc_library") | ||
|
|
||
| package( | ||
| default_applicable_licenses = ["@heir//:license"], | ||
| default_visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| cc_library( | ||
| name = "CheddarToEmitC", | ||
| srcs = ["CheddarToEmitC.cpp"], | ||
| hdrs = ["CheddarToEmitC.h"], | ||
| deps = [ | ||
| ":pass_inc_gen", | ||
| "@heir//lib/Dialect/Cheddar/IR:Dialect", | ||
| "@heir//lib/Utils:ConversionUtils", | ||
| "@llvm-project//llvm:Support", | ||
| "@llvm-project//mlir:ArithDialect", | ||
| "@llvm-project//mlir:ArithToEmitC", | ||
| "@llvm-project//mlir:EmitCDialect", | ||
| "@llvm-project//mlir:FuncDialect", | ||
| "@llvm-project//mlir:IR", | ||
| "@llvm-project//mlir:MemRefDialect", | ||
| "@llvm-project//mlir:MemRefToEmitC", | ||
| "@llvm-project//mlir:Pass", | ||
| "@llvm-project//mlir:SCFDialect", | ||
| "@llvm-project//mlir:SCFToEmitC", | ||
| "@llvm-project//mlir:Support", | ||
| "@llvm-project//mlir:TransformUtils", | ||
| ], | ||
| ) | ||
|
|
||
| add_heir_transforms( | ||
| header_filename = "CheddarToEmitC.h.inc", | ||
| pass_name = "CheddarToEmitC", | ||
| td_file = "CheddarToEmitC.td", | ||
| ) |
1,440 changes: 1,440 additions & 0 deletions
1,440
lib/Conversions/CheddarToEmitC/CheddarToEmitC.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,23 @@ | ||
| #ifndef LIB_CONVERSIONS_CHEDDARTOEMITC_CHEDDARTOEMITC_H_ | ||
| #define LIB_CONVERSIONS_CHEDDARTOEMITC_CHEDDARTOEMITC_H_ | ||
|
|
||
| #include "mlir/include/mlir/IR/DialectRegistry.h" // from @llvm-project | ||
| #include "mlir/include/mlir/Pass/Pass.h" // from @llvm-project | ||
|
|
||
| namespace mlir::heir { | ||
|
|
||
| // Attaches MemRefElementTypeInterface as an external (marker-only) model to | ||
| // emitc::OpaqueType. Needed so that the cheddar-to-emitc type converter can | ||
| // form `memref<Nx!emitc.opaque<...>>` as the converted form of | ||
| // `memref<Nx!cheddar.*>` after bufferization. Call once at tool startup. | ||
| void registerCheddarToEmitCExternalModels(DialectRegistry& registry); | ||
|
|
||
| #define GEN_PASS_DECL | ||
| #include "lib/Conversions/CheddarToEmitC/CheddarToEmitC.h.inc" | ||
|
|
||
| #define GEN_PASS_REGISTRATION | ||
| #include "lib/Conversions/CheddarToEmitC/CheddarToEmitC.h.inc" | ||
|
|
||
| } // namespace mlir::heir | ||
|
|
||
| #endif // LIB_CONVERSIONS_CHEDDARTOEMITC_CHEDDARTOEMITC_H_ |
This file contains hidden or 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,34 @@ | ||
| #ifndef LIB_CONVERSIONS_CHEDDARTOEMITC_CHEDDARTOEMITC_TD_ | ||
| #define LIB_CONVERSIONS_CHEDDARTOEMITC_CHEDDARTOEMITC_TD_ | ||
|
|
||
| include "mlir/Pass/PassBase.td" | ||
|
|
||
| def CheddarToEmitC : Pass<"cheddar-to-emitc"> { | ||
| let summary = "Lower the cheddar dialect to EmitC."; | ||
|
|
||
| let description = [{ | ||
| Translates each cheddar op into an out-parameter-style `Context`/ | ||
| `UserInterface` method call expressed in the EmitC dialect. | ||
| `mlir-translate --mlir-to-cpp` renders the resulting IR as host-side | ||
| C++ against the CHEDDAR library API. | ||
|
|
||
| Bufferized loop kernels are handled in the same conversion: the SCF and | ||
| Arith EmitC patterns are run alongside the cheddar patterns so that the | ||
| shared type converter sees cheddar types (e.g. an `scf.for` carrying an | ||
| `!cheddar.*` iter_arg lowers to a move-assigned `emitc.variable`, and | ||
| loop-index values feed `memref` subscripts without a stranded | ||
| `index -> emitc.size_t` cast). | ||
|
|
||
| (* example filepath=tests/Conversions/CheddarToEmitC/doctest.mlir *) | ||
| }]; | ||
|
|
||
| let dependentDialects = [ | ||
| "::mlir::arith::ArithDialect", | ||
| "::mlir::emitc::EmitCDialect", | ||
| "::mlir::func::FuncDialect", | ||
| "::mlir::memref::MemRefDialect", | ||
| "::mlir::scf::SCFDialect", | ||
| ]; | ||
| } | ||
|
|
||
| #endif // LIB_CONVERSIONS_CHEDDARTOEMITC_CHEDDARTOEMITC_TD_ | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a doctest