[Mlir-commits] [mlir] [mlir] Add FileRange location type. (PR #80213)
Jacques Pienaar
llvmlistbot at llvm.org
Sun Nov 3 22:36:52 PST 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), [{
+ return $_get(filename.getContext(), filename, ArrayRef<unsigned>{});
+ }]>,
+ AttrBuilderWithInferredContext<(ins "StringAttr":$filename,
+ "unsigned":$line), [{
+ return $_get(filename.getContext(), filename,
+ ArrayRef<unsigned>{line});
+ }]>,
AttrBuilderWithInferredContext<(ins "StringAttr":$filename,
"unsigned":$line,
"unsigned":$column), [{
- return $_get(filename.getContext(), filename, line, column);
+ return $_get(filename.getContext(), filename,
+ ArrayRef<unsigned>{line, column});
}]>,
- AttrBuilder<(ins "StringRef":$filename, "unsigned":$line,
- "unsigned":$column), [{
+ AttrBuilder<(ins "::llvm::StringRef":$filename,
+ "unsigned":$start_line,
+ "unsigned":$start_column), [{
return $_get($_ctxt,
- StringAttr::get($_ctxt, filename.empty() ? "-" : filename),
- line, column);
- }]>
+ StringAttr::get($_ctxt, filename.empty() ? "-" : filename),
+ ArrayRef<unsigned>{start_line, start_column});
+ }]>,
+ AttrBuilderWithInferredContext<(ins "::mlir::StringAttr":$filename,
+ "unsigned":$line,
+ "unsigned":$start_column,
+ "unsigned":$end_column), [{
+ return $_get(filename.getContext(), filename,
+ ArrayRef<unsigned>{line, start_column, end_column});
+ }]>,
+ AttrBuilderWithInferredContext<(ins "::mlir::StringAttr":$filename,
+ "unsigned":$start_line,
+ "unsigned":$start_column,
+ "unsigned":$end_line,
+ "unsigned":$end_column), [{
+ return $_get(filename.getContext(), filename,
+ ArrayRef<unsigned>{start_line, start_column, end_column, end_line});
+ }]>,
+ AttrBuilder<(ins "::llvm::StringRef":$filename,
+ "unsigned":$start_line,
+ "unsigned":$start_column,
+ "unsigned":$end_line,
+ "unsigned":$end_column), [{
+ return $_get($_ctxt,
+ StringAttr::get($_ctxt, filename.empty() ? "-" : filename),
+ ArrayRef<unsigned>{start_line, start_column, end_column, end_line});
+ }]>,
];
+
+ let extraClassDeclaration = [{
+ std::optional<unsigned> getStartLine() const;
+ std::optional<unsigned> getStartColumn() const;
+ std::optional<unsigned> getEndColumn() const;
+ std::optional<unsigned> getEndLine() const;
----------------
jpienaar wrote:
Mmm, on second thought. I'm not sure if not using optional doesn't result in requiring more folks to be aware of the convention or encoding. Now if I have question "is this actually a range", a consumer would have to know the above. Which might not be an issue if all consumers treat empty ranges as locations.
https://github.com/llvm/llvm-project/pull/80213
More information about the Mlir-commits
mailing list