[IR] Add a Location to BlockArgument
authorChris Lattner <clattner@nondot.org>
Sun, 23 May 2021 21:08:31 +0000 (14:08 -0700)
committerChris Lattner <clattner@nondot.org>
Sun, 23 May 2021 21:10:00 +0000 (14:10 -0700)
commit81467f500f6ad106a69088bc276024c5e1938571
tree997ea371a5910ed6840a230e755e1e3c15066149
parentfc82507c895a11c2d3acfcc5fb0e547d7f42f88e
[IR] Add a Location to BlockArgument

This adds the ability to specify a location when creating BlockArguments.
Notably Value::getLoc() will return this correctly, which makes diagnostics
more precise (e.g. the example in test-legalize-type-conversion.mlir).

This is currently optional to avoid breaking any existing code - if
absent, the BlockArgument defaults to using the location of its enclosing
operation (preserving existing behavior).

The bulk of this change is plumbing location tracking through the parser
and printer to make sure it can round trip (in -mlir-print-debuginfo
mode).  This is complete for generic operations, but requires manual
adoption for custom ops.

I added support for function-like ops to round trip their argument
locations - they print correctly, but when parsing the locations are
dropped on the floor.  I intend to fix this, but it will require more
invasive plumbing through "function_like_impl" stuff so I think it
best to split it out to its own patch.

This is a reapply of the patch here: https://reviews.llvm.org/D102567
with an additional change: we now never defer block argument locations,
guaranteeing that we can round trip correctly.

This isn't required in all cases, but allows us to hill climb here and
works around unrelated bugs like https://bugs.llvm.org/show_bug.cgi?id=50451

Differential Revision: https://reviews.llvm.org/D102991
13 files changed:
mlir/include/mlir/IR/Block.h
mlir/include/mlir/IR/Builders.h
mlir/include/mlir/IR/OpImplementation.h
mlir/include/mlir/IR/Value.h
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/Block.cpp
mlir/lib/IR/Builders.cpp
mlir/lib/IR/FunctionImplementation.cpp
mlir/lib/IR/Value.cpp
mlir/lib/Parser/Parser.cpp
mlir/test/IR/locations.mlir
mlir/test/Transforms/test-legalize-type-conversion.mlir
mlir/test/mlir-tblgen/pattern.mlir