-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from j2kun:dialect-transform-template
PiperOrigin-RevId: 586062227
- Loading branch information
Showing
12 changed files
with
530 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# {{ pass_name }} tablegen and headers. | ||
|
||
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library") | ||
|
||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
gentbl_cc_library( | ||
name = "pass_inc_gen", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-pass-decls", | ||
"-name={{ dialect_name }}", | ||
], | ||
"Passes.h.inc", | ||
), | ||
( | ||
["-gen-pass-doc"], | ||
"{{ dialect_name }}Passes.md", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "Passes.td", | ||
deps = [ | ||
"@llvm-project//mlir:OpBaseTdFiles", | ||
"@llvm-project//mlir:PassBaseTdFiles", | ||
], | ||
) | ||
|
||
exports_files([ | ||
"Passes.h", | ||
"{{ pass_name }}.h", | ||
]) |
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,17 @@ | ||
#ifndef INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_{{ pass_name | upper }}_H_ | ||
#define INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_{{ pass_name | upper }}_H_ | ||
|
||
#include "mlir/include/mlir/Pass/Pass.h" // from @llvm-project | ||
|
||
namespace mlir { | ||
namespace heir { | ||
namespace {{ dialect_namespace }} { | ||
|
||
#define GEN_PASS_DECL_{{ pass_name | upper }} | ||
#include "include/Dialect/{{ dialect_name }}/Transforms/Passes.h.inc" | ||
|
||
} // namespace {{ dialect_namespace }} | ||
} // namespace heir | ||
} // namespace mlir | ||
|
||
#endif // INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_{{ pass_name | upper }}_H_ |
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,18 @@ | ||
#ifndef INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_PASSES_H_ | ||
#define INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_PASSES_H_ | ||
|
||
#include "include/Dialect/{{ dialect_name }}/IR/{{ dialect_name }}Dialect.h" | ||
#include "include/Dialect/{{ dialect_name }}/Transforms/{{ pass_name }}.h" | ||
|
||
namespace mlir { | ||
namespace heir { | ||
namespace {{ dialect_namespace }} { | ||
|
||
#define GEN_PASS_REGISTRATION | ||
#include "include/Dialect/{{ dialect_name }}/Transforms/Passes.h.inc" | ||
|
||
} // namespace {{ dialect_namespace }} | ||
} // namespace heir | ||
} // namespace mlir | ||
|
||
#endif // INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_PASSES_H_ |
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,14 @@ | ||
#ifndef INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_PASSES_TD_ | ||
#define INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_PASSES_TD_ | ||
|
||
include "mlir/Pass/PassBase.td" | ||
|
||
def {{ pass_name }} : Pass<"{{ pass_flag }}"> { | ||
// FIXME: add add summary/description | ||
let summary = ""; | ||
let description = [{ | ||
}]; | ||
let dependentDialects = ["mlir::heir::{{ dialect_namespace }}::{{ dialect_name}}Dialect"]; | ||
} | ||
|
||
#endif // INCLUDE_DIALECT_{{ dialect_name | upper }}_TRANSFORMS_PASSES_TD_ |
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,32 @@ | ||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "Transforms", | ||
hdrs = [ | ||
"@heir//include/Dialect/{{ dialect_name }}/Transforms:Passes.h", | ||
], | ||
deps = [ | ||
":{{ pass_name }}", | ||
"@heir//include/Dialect/{{ dialect_name }}/Transforms:pass_inc_gen", | ||
"@heir//lib/Dialect/{{ dialect_name }}/IR:Dialect", | ||
"@llvm-project//mlir:IR", | ||
], | ||
) | ||
|
||
cc_library( | ||
name = "{{ pass_name }}", | ||
srcs = ["{{ pass_name }}.cpp"], | ||
hdrs = [ | ||
"@heir//include/Dialect/{{ dialect_name }}/Transforms:{{ pass_name }}.h", | ||
], | ||
deps = [ | ||
"@heir//include/Dialect/{{ dialect_name }}/Transforms:pass_inc_gen", | ||
"@heir//lib/Dialect/{{ dialect_name }}/IR:Dialect", | ||
"@llvm-project//mlir:IR", | ||
"@llvm-project//mlir:Pass", | ||
"@llvm-project//mlir:Transforms", | ||
], | ||
) |
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,29 @@ | ||
#include "include/Dialect/{{ dialect_name }}/Transforms/{{ pass_name }}.h" | ||
|
||
#include "include/Dialect/{{ dialect_name }}/IR/{{ dialect_name }}Ops.h" | ||
#include "mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h" // from @llvm-project | ||
|
||
namespace mlir { | ||
namespace heir { | ||
namespace {{ dialect_namespace }} { | ||
|
||
#define GEN_PASS_DEF_{{ pass_name | upper }} | ||
#include "include/Dialect/{{ dialect_name }}/Transforms/Passes.h.inc" | ||
|
||
struct {{ pass_name }} : impl::{{ pass_name }}Base<{{ pass_name }}> { | ||
using {{ pass_name }}Base::{{ pass_name }}Base; | ||
|
||
void runOnOperation() override { | ||
MLIRContext *context = &getContext(); | ||
RewritePatternSet patterns(context); | ||
|
||
// FIXME: implement pass | ||
patterns.add<>(context); | ||
|
||
(void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); | ||
} | ||
}; | ||
|
||
} // namespace {{ dialect_namespace }} | ||
} // namespace heir | ||
} // namespace mlir |
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,35 @@ | ||
# {{ pass_name }} tablegen and headers. | ||
|
||
load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library") | ||
|
||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
exports_files([ | ||
"{{ pass_name }}.h", | ||
]) | ||
|
||
gentbl_cc_library( | ||
name = "pass_inc_gen", | ||
tbl_outs = [ | ||
( | ||
[ | ||
"-gen-pass-decls", | ||
"-name={{ pass_name }}", | ||
], | ||
"{{ pass_name }}.h.inc", | ||
), | ||
( | ||
["-gen-pass-doc"], | ||
"{{ pass_name }}.md", | ||
), | ||
], | ||
tblgen = "@llvm-project//mlir:mlir-tblgen", | ||
td_file = "{{ pass_name }}.td", | ||
deps = [ | ||
"@llvm-project//mlir:OpBaseTdFiles", | ||
"@llvm-project//mlir:PassBaseTdFiles", | ||
], | ||
) |
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,18 @@ | ||
#ifndef INCLUDE_TRANSFORMS_{{ pass_name | upper }}_{{ pass_name | upper }}_H_ | ||
#define INCLUDE_TRANSFORMS_{{ pass_name | upper }}_{{ pass_name | upper }}_H_ | ||
|
||
#include "mlir/include/mlir/Pass/Pass.h" // from @llvm-project | ||
|
||
namespace mlir { | ||
namespace heir { | ||
|
||
#define GEN_PASS_DECL | ||
#include "include/Transforms/{{ pass_name }}/{{ pass_name }}.h.inc" | ||
|
||
#define GEN_PASS_REGISTRATION | ||
#include "include/Transforms/{{ pass_name }}/{{ pass_name }}.h.inc" | ||
|
||
} // namespace heir | ||
} // namespace mlir | ||
|
||
#endif // INCLUDE_TRANSFORMS_{{ pass_name | upper }}_{{ pass_name | upper }}_H_ |
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,16 @@ | ||
#ifndef INCLUDE_TRANSFORMS_{{ pass_name | upper }}_{{ pass_name | upper }}_TD_ | ||
#define INCLUDE_TRANSFORMS_{{ pass_name | upper }}_{{ pass_name | upper }}_TD_ | ||
|
||
include "mlir/Pass/PassBase.td" | ||
|
||
def {{ pass_name }} : Pass<"{{ pass_flag }}"> { | ||
// FIXME: add add summary/description | ||
let summary = ""; | ||
let description = [{ | ||
}]; | ||
let dependentDialects = [ | ||
|
||
]; | ||
} | ||
|
||
#endif // INCLUDE_TRANSFORMS_{{ pass_name | upper }}_{{ pass_name | upper }}_TD_ |
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,19 @@ | ||
package( | ||
default_applicable_licenses = ["@heir//:license"], | ||
default_visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "{{ pass_name }}", | ||
srcs = ["{{ pass_name }}.cpp"], | ||
hdrs = [ | ||
"@heir//include/Transforms/{{ pass_name }}:{{ pass_name }}.h", | ||
], | ||
deps = [ | ||
"@heir//include/Transforms/{{ pass_name }}:pass_inc_gen", | ||
"@llvm-project//mlir:IR", | ||
"@llvm-project//mlir:Pass", | ||
"@llvm-project//mlir:Support", | ||
"@llvm-project//mlir:Transforms", | ||
], | ||
) |
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,27 @@ | ||
#include "include/Transforms/{{ pass_name }}/{{ pass_name }}.h" | ||
|
||
#include "mlir/include/mlir/Transforms/Passes.h" // from @llvm-project | ||
#include "mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h" // from @llvm-project | ||
|
||
namespace mlir { | ||
namespace heir { | ||
|
||
#define GEN_PASS_DEF_{{ pass_name | upper }} | ||
#include "include/Transforms/{{ pass_name }}/{{ pass_name }}.h.inc" | ||
|
||
struct {{ pass_name }} : impl::{{ pass_name }}Base<{{ pass_name }}> { | ||
using {{ pass_name }}Base::{{ pass_name }}Base; | ||
|
||
void runOnOperation() override { | ||
MLIRContext *context = &getContext(); | ||
RewritePatternSet patterns(context); | ||
|
||
// FIXME: implement pass | ||
patterns.add<>(context); | ||
|
||
(void)applyPatternsAndFoldGreedily(getOperation(), std::move(patterns)); | ||
} | ||
}; | ||
|
||
} // namespace heir | ||
} // namespace mlir |
Oops, something went wrong.