Skip to content

Commit 8a49ed2

Browse files
committed
[mlir][Transforms][docs] Add a description blurb for various passes
Summary: This revision adds blurbs of documentation to various different passes, namely: Canonicalizer, CSE, LocationSnapshot, StripDebugInfo, and SymbolDCE. Differential Revision: https://reviews.llvm.org/D78007
1 parent ed6c452 commit 8a49ed2

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

mlir/include/mlir/Transforms/Passes.td

+87
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,23 @@ def AffinePipelineDataTransfer
104104

105105
def Canonicalizer : Pass<"canonicalize"> {
106106
let summary = "Canonicalize operations";
107+
let description = [{
108+
This pass performs various types of canonicalizations over a set of
109+
operations. See [Operation Canonicalization](Canonicalization.md) for more
110+
details.
111+
}];
107112
let constructor = "mlir::createCanonicalizerPass()";
108113
}
109114

110115
def CSE : Pass<"cse"> {
111116
let summary = "Eliminate common sub-expressions";
117+
let description = [{
118+
This pass implements a generalized algorithm for common sub-expression
119+
elimination. This pass relies on information provided by the
120+
`Memory SideEffect` interface to identify when it is safe to eliminate
121+
operations. See [Common subexpression elimination](https://en.wikipedia.org/wiki/Common_subexpression_elimination)
122+
for more general details on this optimization.
123+
}];
112124
let constructor = "mlir::createCSEPass()";
113125
let statistics = [
114126
Statistic<"numCSE", "num-cse'd", "Number of operations CSE'd">,
@@ -131,6 +143,39 @@ def Inliner : Pass<"inline"> {
131143

132144
def LocationSnapshot : Pass<"snapshot-op-locations"> {
133145
let summary = "Generate new locations from the current IR";
146+
let description = [{
147+
This pass allows for generating new locations from the IR during any stage
148+
of compilation, by snapshotting the IR to a file and using that file to
149+
generate new locations for the operations.
150+
151+
Depending on the value of the `tag` option, different resulting locations
152+
may be generated:
153+
154+
* If unset, the original location of the operation is replaced.
155+
156+
Example:
157+
158+
```mlir
159+
// old:
160+
... loc("original_source.cpp":1:1)
161+
162+
// new:
163+
... loc("snapshot_source.mlir":10:10)
164+
```
165+
166+
* If set, the new location is fused with the original location in the form
167+
of a [`Name Location`](Diagnostics.md#name-location) with the specified tag.
168+
169+
Example:
170+
171+
```mlir
172+
// old:
173+
... loc("original_source.cpp":1:1)
174+
175+
// new:
176+
... loc(fused["original_source.cpp":1:1, "snapshot"("snapshot_source.mlir":10:10)])
177+
```
178+
}];
134179
let constructor = "mlir::createLocationSnapshotPass()";
135180
let options = [
136181
Option<"fileName", "filename", "std::string", /*default=*/"",
@@ -230,11 +275,53 @@ def PrintOp : Pass<"print-op-graph", "ModuleOp"> {
230275

231276
def StripDebugInfo : Pass<"strip-debuginfo"> {
232277
let summary = "Strip debug info from all operations";
278+
let description = [{
279+
This pass strips the IR of any location information, by replacing all
280+
operation locations with [`unknown`](Diagnostics.md#unknown-location).
281+
}];
233282
let constructor = "mlir::createStripDebugInfoPass()";
234283
}
235284

236285
def SymbolDCE : Pass<"symbol-dce"> {
237286
let summary = "Eliminate dead symbols";
287+
let description = [{
288+
This pass deletes all symbols that are found to be unreachable. This is done
289+
by computing the set of operations that are known to be live, propagating
290+
that liveness to other symbols, and then deleting all symbols that are not
291+
within this live set. Live symbols are those that have a
292+
[visibility](SymbolsAndSymbolTables.md#symbol-visibility) that extends
293+
beyond the IR, e.g. `public`, or those that are referenced by live symbols
294+
or other non-Symbol operations.
295+
296+
For example, consider the following input:
297+
298+
```mlir
299+
func @dead_private_function() attributes { sym_visibility = "private" }
300+
func @live_private_function() attributes { sym_visibility = "private" }
301+
302+
// Note: The `public` isn't necessary here, as this is the default.
303+
func @public_function() attributes { sym_visibility = "public" } {
304+
"foo.return"() {uses = [@live_private_function]} : () -> ()
305+
}
306+
```
307+
308+
A known live function, `public_function`, contains a reference to an
309+
otherwise non-live function `live_private_function`. After running
310+
`symbol-dce`, only these two symbols should remain, as the final symbol
311+
`dead_private_function` is not visible outside of the current IR and there
312+
are no links to known-live operations. After running, we get the expected:
313+
314+
```mlir
315+
func @live_private_function() attributes { sym_visibility = "private" }
316+
317+
func @public_function() attributes { sym_visibility = "public" } {
318+
"foo.return"() {uses = [@live_private_function]} : () -> ()
319+
}
320+
```
321+
322+
See [Symbols and SymbolTables](SymbolsAndSymbolTables.md) for more
323+
information on `Symbols`.
324+
}];
238325
let constructor = "mlir::createSymbolDCEPass()";
239326
}
240327

0 commit comments

Comments
 (0)