Skip to content

Commit 47f76bb

Browse files
committed
[mlir][lsp] Use ResultGroupDefinition struct
This struct was added and was intended to be used, but it was missed in the original patch. Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D114041
1 parent b2fbd45 commit 47f76bb

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

mlir/include/mlir/Parser/AsmParserState.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class AsmParserState {
4747
/// an input file.
4848
struct OperationDefinition {
4949
struct ResultGroupDefinition {
50+
ResultGroupDefinition(unsigned index, llvm::SMRange loc)
51+
: startIndex(index), definition(loc) {}
52+
5053
/// The result number that starts this group.
5154
unsigned startIndex;
5255
/// The source definition of the result group.
@@ -67,7 +70,7 @@ class AsmParserState {
6770
llvm::SMRange scopeLoc;
6871

6972
/// Source definitions for any result groups of this operation.
70-
SmallVector<std::pair<unsigned, SMDefinition>> resultGroups;
73+
SmallVector<ResultGroupDefinition> resultGroups;
7174

7275
/// If this operation is a symbol operation, this vector contains symbol
7376
/// uses of this operation.

mlir/lib/Parser/AsmParserState.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ void AsmParserState::addUses(Value value, ArrayRef<llvm::SMLoc> locations) {
258258
unsigned resultNo = result.getResultNumber();
259259
OperationDefinition &def = *impl->operations[existingIt->second];
260260
for (auto &resultGroup : llvm::reverse(def.resultGroups)) {
261-
if (resultNo >= resultGroup.first) {
261+
if (resultNo >= resultGroup.startIndex) {
262262
for (llvm::SMLoc loc : locations)
263-
resultGroup.second.uses.push_back(convertIdLocToRange(loc));
263+
resultGroup.definition.uses.push_back(convertIdLocToRange(loc));
264264
return;
265265
}
266266
}

mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void MLIRDocument::getLocationsOf(const lsp::URIForFile &uri,
367367
if (contains(op.loc, posLoc))
368368
return collectLocationsFromLoc(op.op->getLoc(), locations, uri);
369369
for (const auto &result : op.resultGroups)
370-
if (containsPosition(result.second))
370+
if (containsPosition(result.definition))
371371
return collectLocationsFromLoc(op.op->getLoc(), locations, uri);
372372
for (const auto &symUse : op.symbolUses) {
373373
if (contains(symUse, posLoc)) {
@@ -404,15 +404,15 @@ void MLIRDocument::findReferencesOf(const lsp::URIForFile &uri,
404404
for (const AsmParserState::OperationDefinition &op : asmState.getOpDefs()) {
405405
if (contains(op.loc, posLoc)) {
406406
for (const auto &result : op.resultGroups)
407-
appendSMDef(result.second);
407+
appendSMDef(result.definition);
408408
for (const auto &symUse : op.symbolUses)
409409
if (contains(symUse, posLoc))
410410
references.push_back(getLocationFromLoc(sourceMgr, symUse, uri));
411411
return;
412412
}
413413
for (const auto &result : op.resultGroups)
414-
if (isDefOrUse(result.second, posLoc))
415-
return appendSMDef(result.second);
414+
if (isDefOrUse(result.definition, posLoc))
415+
return appendSMDef(result.definition);
416416
for (const auto &symUse : op.symbolUses) {
417417
if (!contains(symUse, posLoc))
418418
continue;
@@ -456,13 +456,13 @@ Optional<lsp::Hover> MLIRDocument::findHover(const lsp::URIForFile &uri,
456456
// Check if the position points at a result group.
457457
for (unsigned i = 0, e = op.resultGroups.size(); i < e; ++i) {
458458
const auto &result = op.resultGroups[i];
459-
if (!isDefOrUse(result.second, posLoc, &hoverRange))
459+
if (!isDefOrUse(result.definition, posLoc, &hoverRange))
460460
continue;
461461

462462
// Get the range of results covered by the over position.
463-
unsigned resultStart = result.first;
464-
unsigned resultEnd =
465-
(i == e - 1) ? op.op->getNumResults() : op.resultGroups[i + 1].first;
463+
unsigned resultStart = result.startIndex;
464+
unsigned resultEnd = (i == e - 1) ? op.op->getNumResults()
465+
: op.resultGroups[i + 1].startIndex;
466466
return buildHoverForOperationResult(hoverRange, op.op, resultStart,
467467
resultEnd, posLoc);
468468
}

0 commit comments

Comments
 (0)