38 Source Location And Source Maps
Locations connect MLIR operations to source code, generated code, or compiler provenance. They are crucial for diagnostics and debugging, but they do not change an operation’s runtime semantics.
38.1 Locations Travel With Transformations
An operation may carry a file/line/column location, an unknown location, a fused location representing several sources, a call-site location, or dialect-specific provenance. When a transformation combines operations, it should choose a location policy that makes a later diagnostic understandable: preserve the most relevant source, fuse contributors, or record a transformation call site.
Dropping locations wholesale makes a compiler difficult to use. Inventing a precise location when none exists is also harmful because it points users to the wrong source. Use unknown locations honestly and retain provenance where the IR API allows it.
38.2 Source Maps Are A Later Lowering Concern
A source map associates generated output positions with original source locations. MLIR locations provide the upstream provenance needed to build such maps, but target emission, instruction selection, and linker behavior determine the final mapping format. Keep the distinction clear: locations annotate IR; a source-map artifact belongs to an output format and debug-information pipeline.