[Mlir-commits] [mlir] [mlir] Add FileRange location type. (PR #80213)

River Riddle llvmlistbot at llvm.org
Fri Nov 1 10:01:36 PDT 2024


================
@@ -60,46 +60,97 @@ def CallSiteLoc : Builtin_LocationAttr<"CallSiteLoc"> {
 }
 
 //===----------------------------------------------------------------------===//
-// FileLineColLoc
+// FileLineColRange
 //===----------------------------------------------------------------------===//
 
-def FileLineColLoc : Builtin_LocationAttr<"FileLineColLoc"> {
-  let summary = "A file:line:column source location";
+def FileLineColRange : Builtin_LocationAttr<"FileLineColRange"> {
+  let summary = "A file:line:column source location range";
   let description = [{
     Syntax:
 
     ```
     filelinecol-location ::= string-literal `:` integer-literal `:`
                              integer-literal
+                             (`to` (integer-literal ?) `:` integer-literal ?)
     ```
 
-    An instance of this location represents a tuple of file, line number, and
-    column number. This is similar to the type of location that you get from
-    most source languages.
+    An instance of this location represents a tuple of file, start and end line
+    number, and start and end column number. It allows for the following
+    configurations:
+
+    *   A single file line location: `file:line`;
+    *   A single file line col location: `file:line:column`;
+    *   A single line range: `file:line:column to :column`;
+    *   A single file range: `file:line:column to line:column`;
 
     Example:
 
     ```mlir
-    loc("mysource.cc":10:8)
+    loc("mysource.cc":10:8 to 12:18)
     ```
   }];
-  let parameters = (ins "StringAttr":$filename, "unsigned":$line,
-                        "unsigned":$column);
+
+  // Note: this only shows the parameters for which accessors are generated. The
+  // locations are only set in storage.
+  let parameters = (ins "StringAttr":$filename);
   let builders = [
+
+    AttrBuilderWithInferredContext<(ins "StringAttr":$filename), [{
----------------
River707 wrote:

```suggestion
  let builders = [
    AttrBuilderWithInferredContext<(ins "StringAttr":$filename), [{
```

https://github.com/llvm/llvm-project/pull/80213


More information about the Mlir-commits mailing list