[Feat] Add the complete location feature support#5681
[Feat] Add the complete location feature support#5681ice-tong wants to merge 2 commits intoxdslproject:mainfrom
Conversation
|
Related #815 Gently ping @superlopuh to take a look at this PR and let me know if this implementation is worth pursuing further for merging into the xdsl main branch? |
|
Hi, thanks for opening this. It's kind of funny that you're the third person in the last few days to open a PR adding location support. This one has a few issues:
I would invite you to look at the other open PRs to add location, which are split up in smaller chunks so that we can merge and discuss each aspect individually, and to join us on the Zulip for discussions on how to merge all the missing features in a coordinated way. There are a few things in flight already that will conflict with this, but there are some things that this PR does that the others don't. It will be great to merge all of it eventually, but it'll be much easier if we do it in a coordinated way. |
|
Hi @superlopuh, I just found out that a better implementation MR for location has already been submitted from @aniragil #5680! I will wait for that PR to be merged, and then see if there are any other new location-related features that need to be added~ |
|
Close since duplicate with #5680 |
Complete MLIR-Compatible Location Mechanism Implementation
!!!Note: This implementation was developed with the assistance of an AI coding assistant (Qwen3-Coder).
Background and Motivation
Location information is an extremely integral part of the MLIR infrastructure. Every operation in MLIR carries source location information for debugging, error diagnostics, and source mapping purposes. However, xDSL's location support was limited to only
UnknownLocandFileLineColLoc, missing 5 important location types from MLIR C++:This PR implements complete MLIR-compatible location mechanism in xDSL, enabling:
LocationAttr Design
Type Hierarchy
All location types inherit from
LocationAttr(which extendsAttribute):Key Design Decisions
Location is never None:
_locationfields useLocationAttrtype (notLocationAttr | None), defaulting toUnknownLoc()when not specified. This matches MLIR C++ design where location is always present.Backward Compatibility: All location parameters are optional. The parser only passes location to
create()when non-None, ensuring existing customcreate()methods continue to work.Fusion Logic:
FusedLoc.create()implements MLIR-compatible fusion:FusedLocwith same metadataUnknownLocfrom the setUnknownLoc()for empty listsModular Parser: Location parsing is refactored into helper methods (
_parse_location_content(),_parse_callsite_location(), etc.) for better maintainability.Code Changes
Core Infrastructure (
xdsl/ir/)core.py:_locationfield toOperationwithget_loc()/set_loc()methods_locationfield toBlockArgumentwithget_loc()/set_loc()methodsget_loc()toRegion(inherits from parent operation)Operation.__init__()andcreate()to acceptlocationparameterBlock.add_arg()/insert_arg()/add_args()to accept location parameterslocation.py(NEW): Location utility functionswalk_locations(): Recursively walk nested locationsfind_location_of_type(): Find first location of specified typefuse_locations(): Fuse multiple locationsstrip_locations(): Replace with UnknownLoclocations_equal(): Structural comparisoncollect_locations(): Collect all nested locationshas_location_type(): Check if contains typeParser (
xdsl/parser/)attribute_parser.py:parse_optional_location()to parse all 7 location typesparse_location()for required location parsingcore.py:_parse_generic_operation()to attach location to operationsparse_func_op_like()to parse operation locationPrinter (
xdsl/printer.py)print_location()methodprint_block_argument()to print locationprint_operation_type()to print operation locationprint_func_op_like()to print function locationDialect Updates (
xdsl/dialects/)builtin.py: Add 5 new location type definitionsfunc.py,pdl_interp.py,transform.py,csl/csl.py,arm_func.py,riscv_func.py,llvm.py: Update to support location in parse/printutils/format.py: Updateprint_func_op_like()signatureIRDL (
xdsl/irdl/)operations.py: UpdateIRDLOperation.__init__()andirdl_op_init()to accept location parameterTest Coverage
Unit Tests
tests/dialects/test_location.py(20 tests)FusedLoc.create()simplification logictests/ir/test_location.py(16 tests)tests/ir/test_location_utils.py(21 tests)tests/test_parser.py(enhanced)test_parse_location()to cover all location typestests/test_printer.py(enhanced)test_print_op_location()for operation location printingtest_print_location_types()for all location type printingFileCheck Tests
tests/filecheck/location/test-location.mlir--print-debuginfoTest Results
Example Usage
MLIR Syntax Compatibility
All MLIR location syntax is supported:
Breaking Changes
None. All changes are backward compatible:
UnknownLoc()defaultcreate()methods continue to workRelated Issues
This implementation addresses the need for complete location support in xDSL, enabling: