• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16include "mlir/Pass/PassBase.td"
17
18def ChloLegalizeToHloPass : FunctionPass<"chlo-legalize-to-hlo"> {
19  let summary = "Legalize CHLO to HLO.";
20  let constructor = "createChloLegalizeToHloPass()";
21  let options = [
22    Option<"legalize_broadcasts_", "legalize-broadcasts", "bool",
23           /*default=*/"true", "Legalize implicit broadcasts to explicit HLO broadcasting forms">,
24    Option<"expand_compositions_", "expand-compositions", "bool",
25           /*default=*/"true", "Expands client-centric compositions to HLO primitives">,
26  ];
27}
28
29def HloCanonicalizeReductionPass : FunctionPass<"hlo-canonicalize-reduction"> {
30  let summary = "canonicalize reduction ops to be suitable for codegen.";
31  let constructor = "createHloCanonicalizeReductionPass()";
32}
33
34def HloLegalizeToLhloPass : Pass<"hlo-legalize-to-lhlo", "ModuleOp"> {
35  let summary = "Legalize from HLO dialect to LHLO dialect.";
36  let constructor = "createLegalizeToLhloPass()";
37}
38
39def HloLegalizeToMemrefPass : FunctionPass<"hlo-legalize-to-memref"> {
40  let summary = "Legalize from HLO dialect to memref dialect.";
41  let constructor = "createLegalizeToMemrefPass()";
42}
43
44def LegalizeControlFlowPass : FunctionPass<"mhlo-legalize-control-flow"> {
45  let summary = "Legalize from MHLO control flow to CFG control flow.";
46  let constructor = "createLegalizeControlFlowPass()";
47}
48
49def LegalizeControlFlowToScfPass : FunctionPass<"mhlo-control-flow-to-scf"> {
50  let summary = "Legalize from MHLO control flow to SCF control flow.";
51  let constructor = "createControlFlowToScfPass()";
52}
53
54def LegalizeEinsumToDotGeneralPass : FunctionPass<"mhlo-legalize-einsum-to-dot-general"> {
55  let summary = "Legalizes einsum ops to dot_general ops.";
56  let constructor = "createLegalizeEinsumToDotGeneralPass()";
57}
58
59def LegalizeGatherToTorchIndexSelectPass : FunctionPass<"mhlo-legalize-gather-to-torch-index-select"> {
60  let summary = "Legalizes gathers to a torch index select.";
61  let constructor = "createLegalizeGatherToTorchIndexSelectPass()";
62}
63
64
65def LegalizeTanhToApproximationPass : FunctionPass<"mhlo-legalize-trigonometric-to-approximation"> {
66  let summary = "Legalize trigonometric operations from standard dialect to an approximation.";
67  let constructor = "createLegalizeTrigonometricToApproximationPass()";
68}
69
70def HloLegalizeToLinalgPass : FunctionPass<"hlo-legalize-to-linalg"> {
71  let summary = "Legalize from HLO dialect to Linalg dialect.";
72  let constructor = "createLegalizeHloToLinalgPass()";
73}
74
75def LegalizeToStandardPass : FunctionPass<"mhlo-legalize-to-std"> {
76  let summary = "Legalize from MHLO dialect to standard dialect.";
77  let constructor = "createLegalizeToStdPass()";
78}
79
80def MarkShapeCalculationPass : Pass<"mhlo-mark-shape-calc", "ModuleOp"> {
81  let summary = "Identify and mark with an attribute operations performing shape calculation";
82  let constructor = "createMarkShapeCalcOpPass()";
83}
84
85def LowerComplexPass : FunctionPass<"mhlo-test-lower-complex"> {
86  let summary = "Lower complex operations into non-complex operations.";
87  let constructor = "createLowerComplexPass()";
88}
89
90
91def LegalizeGeneralDotPass : FunctionPass<"mhlo-test-lower-general-dot"> {
92  let summary = "Tests lowering general dot to a non-batched dot when possible.";
93  let constructor = "createLegalizeGeneralDotPass()";
94}
95
96
97def TestMaterializeBroadcastsPass : FunctionPass<"mhlo-test-materialize-broadcasts"> {
98  let summary = "Test pass for materializing 'broadcast_dimensions' attributes.";
99  let constructor = "createTestMaterializeBroadcastsPass()";
100}
101
102
103def MhloFusionPass : FunctionPass<"mhlo-fusion"> {
104  let summary = "Fuse mhlo ops to kLoop/kInput fusion patterns.";
105  let constructor = "createMhloFusionPass()";
106}
107
108
109def OptimizeMhloPass : FunctionPass<"mhlo-test-optimize"> {
110  let summary = "Run optional HLO optimizations.";
111  let constructor = "createOptimizeMhloPass()";
112}
113
114
115def SinkConstantsToControlFlowPass : FunctionPass<"mhlo-sink-constants-to-control-flow"> {
116  let summary = "Sink constants implicitly captured in control flow regions. This "
117    "is necessary to export to XLA.";
118  let constructor = "createSinkConstantsToControlFlowPass()";
119}
120
121
122def TestInferShapedTypeMethodsPass : FunctionPass<"mhlo-test-infer-shaped-type-methods"> {
123  let summary = "Uses test ops to invoke InferShapedTypeOpInterface methods.";
124  let constructor = "createTestInferShapedTypeMethodsPass()";
125}
126
127def BroadcastPropagationPass : FunctionPass<"mhlo-broadcast-propagation"> {
128  let summary = "Move dynamic broadcasts up over element-wise operations and "
129    "broadcast the operands rather than the result. This will eventually allow "
130    "for larger fusions.";
131  let constructor = "createBroadcastPropagationPass()";
132}
133
134def TestUnfuseBatchNormPass : Pass<"mhlo-test-unfuse-batch-norm", "FuncOp"> {
135  let summary = "Test pass for materializing 'broadcast_dimensions' attributes.";
136  let constructor = "createTestUnfuseBatchNormPass()";
137}
138
139def ExpandHloTuplesPass : Pass<"expand-hlo-tuples", "ModuleOp"> {
140  let summary = "Expand HLO tuple for the entry function of the module.";
141  let constructor = "CreateExpandHloTuplesPass()";
142  let options = [
143    Option<"entry_function_name_", "entry-function", "std::string",
144           /*default=*/"", "the name of entry function of the module">,
145  ];
146
147  let dependentDialects = ["mhlo::MhloDialect"];
148}
149
150def FlattenTuplePass : FunctionPass<"mhlo-flatten-tuple"> {
151  let summary = "Flatten tuples in operands and results of operators that "
152    "support both tuple and variadic type.";
153  let constructor = "createFlattenTuplePass()";
154}
155
156/// Rank specialization passes.
157
158def RankSpecializationClusterPass
159    : FunctionPass<"mhlo-rank-specialization-cluster"> {
160  let constructor = "createRankSpecializationClusterPass()";
161}
162
163def RankSpecializationToSCFPass
164    : FunctionPass<"mhlo-rank-specialization-to-scf"> {
165  let constructor = "createRankSpecializationToSCFPass()";
166  let options = [
167    Option<"max_target_rank_", "max-target-rank", "int", /*default=*/"8",
168           "The maximum supported rank after rank specialization. Any argument "
169           "of greater rank may result in a runtime failure.">,
170  ];
171}
172