Skip to content

Commit 381b3ce

Browse files
committed
Update printer and parser
1 parent 744b2ec commit 381b3ce

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

mlir/include/mlir/IR/BuiltinDialectBytecode.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def FileLineColRange : DialectAttribute<(attr
100100
StringAttr:$filename,
101101
WithBuilder<"$_args",
102102
WithType<"SmallVector<uint64_t>",
103-
WithParser <"succeeded(readFileLineColRangeLocs($_reader, $_var))",
103+
WithParser<"succeeded(readFileLineColRangeLocs($_reader, $_var))",
104104
WithPrinter<"writeFileLineColRangeLocs($_writer, $_name)">>>>:$rawLocData
105105
)> {
106106
let cBuilder = "getFileLineColRange(context, filename, rawLocData)";
@@ -109,8 +109,8 @@ def FileLineColRange : DialectAttribute<(attr
109109

110110
def FileLineColLoc : DialectAttribute<(attr
111111
StringAttr:$filename,
112-
PresentOptionalVarInt:$start_line,
113-
PresentOptionalVarInt:$start_column
112+
VarInt:$start_line,
113+
VarInt:$start_column
114114
)> {
115115
let printerPredicate = "::llvm::isa<FileLineColLoc>($_val)";
116116
}

mlir/include/mlir/IR/BuiltinLocationAttributes.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ def FileLineColRange : Builtin_LocationAttr<"FileLineColRange"> {
143143

144144
let extraClassDeclaration = [{
145145
::mlir::StringAttr getFilename() const;
146-
std::optional<unsigned> getStartLine() const;
147-
std::optional<unsigned> getStartColumn() const;
148-
std::optional<unsigned> getEndColumn() const;
149-
std::optional<unsigned> getEndLine() const;
146+
unsigned getStartLine() const;
147+
unsigned getStartColumn() const;
148+
unsigned getEndColumn() const;
149+
unsigned getEndLine() const;
150150
}];
151151
let skipDefaultBuilders = 1;
152152
let genAccessors = 0;

mlir/include/mlir/IR/BytecodeBase.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ def VarInt :
8282
WithBuilder<"$_args",
8383
WithPrinter<"$_writer.writeVarInt($_getter)",
8484
WithType <"uint64_t">>>>;
85-
// This is for optional ints which are guaranteed to be present.
86-
def PresentOptionalVarInt :
87-
WithParser <"succeeded($_reader.readVarInt($_var))",
88-
WithBuilder<"$_args",
89-
WithPrinter<"$_writer.writeVarInt(*$_getter)",
90-
WithType <"uint64_t">>>>;
9185
def SignedVarInt :
9286
WithParser <"succeeded($_reader.readSignedVarInt($_var))",
9387
WithBuilder<"$_args",

mlir/lib/IR/AsmPrinter.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,16 +2014,27 @@ void AsmPrinter::Impl::printLocationInternal(LocationAttr loc, bool pretty,
20142014
os << loc.getFilename().getValue();
20152015
else
20162016
printEscapedString(loc.getFilename());
2017-
os << ':' << *loc.getStartLine();
2018-
if (loc.getStartColumn()) {
2019-
os << ':' << *loc.getStartColumn();
2020-
if (loc.getEndColumn().has_value() || loc.getEndLine().has_value())
2021-
os << " to ";
2022-
if (loc.getEndLine().has_value())
2023-
os << *loc.getEndLine();
2024-
if (loc.getEndColumn().has_value())
2025-
os << ':' << *loc.getEndColumn();
2017+
if (loc.getStartLine() == loc.getStartColumn() == loc.getEndLine() ==
2018+
loc.getEndColumn() == 0) {
2019+
return;
2020+
}
2021+
if (loc.getStartColumn() == 0 &&
2022+
loc.getStartLine() == loc.getEndLine()) {
2023+
os << ':' << loc.getStartLine();
2024+
return;
2025+
}
2026+
if (loc.getEndColumn() == loc.getStartColumn() &&
2027+
loc.getStartLine() == loc.getEndLine()) {
2028+
os << ':' << loc.getStartLine() << ':' << loc.getStartColumn();
2029+
return;
2030+
}
2031+
if (loc.getStartLine() == loc.getEndLine()) {
2032+
os << ':' << loc.getStartLine() << ':' << loc.getStartColumn()
2033+
<< " to :" << loc.getEndColumn();
2034+
return;
20262035
}
2036+
os << ':' << loc.getStartLine() << ':' << loc.getStartColumn() << " to "
2037+
<< loc.getEndLine() << ':' << loc.getEndColumn();
20272038
})
20282039
.Case<NameLoc>([&](NameLoc loc) {
20292040
printEscapedString(loc.getName());

mlir/lib/IR/BuiltinDialectBytecode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static void writeFileLineColRangeLocs(DialectBytecodeWriter &writer,
126126
}
127127
// The single file:line:col is handled by other writer, but checked here for
128128
// completeness.
129-
if (range.endColumn() == range.startColumn() &&
129+
if (range.getEndColumn() == range.getStartColumn() &&
130130
range.getStartLine() == range.getEndLine()) {
131131
writer.writeVarInt(2);
132132
writer.writeVarInt(range.getStartLine());

mlir/lib/IR/Location.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ StringAttr FileLineColLoc::getFilename() const {
173173
return FileLineColRange::getFilename();
174174
}
175175

176-
unsigned FileLineColLoc::getLine() const { return *getStartLine(); }
176+
unsigned FileLineColLoc::getLine() const { return getStartLine(); }
177177

178-
unsigned FileLineColLoc::getColumn() const { return *getStartColumn(); }
178+
unsigned FileLineColLoc::getColumn() const { return getStartColumn(); }
179179

180180
bool FileLineColLoc::classof(Attribute attr) {
181181
// This could also have been for <= 2. But given this is matching previous

0 commit comments

Comments
 (0)