[Mlir-commits] [mlir] 47f76bb - [mlir][lsp] Use ResultGroupDefinition struct

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 16 16:41:01 PST 2021


Author: Mogball
Date: 2021-11-17T00:40:57Z
New Revision: 47f76bb0f478f8c5c1c0d8e8ba374b995b1dccde

URL: https://github.com/llvm/llvm-project/commit/47f76bb0f478f8c5c1c0d8e8ba374b995b1dccde
DIFF: https://github.com/llvm/llvm-project/commit/47f76bb0f478f8c5c1c0d8e8ba374b995b1dccde.diff

LOG: [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

Added: 
    

Modified: 
    mlir/include/mlir/Parser/AsmParserState.h
    mlir/lib/Parser/AsmParserState.cpp
    mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Parser/AsmParserState.h b/mlir/include/mlir/Parser/AsmParserState.h
index cc010b81e1344..cf955bb564227 100644
--- a/mlir/include/mlir/Parser/AsmParserState.h
+++ b/mlir/include/mlir/Parser/AsmParserState.h
@@ -47,6 +47,9 @@ class AsmParserState {
   /// an input file.
   struct OperationDefinition {
     struct ResultGroupDefinition {
+      ResultGroupDefinition(unsigned index, llvm::SMRange loc)
+          : startIndex(index), definition(loc) {}
+
       /// The result number that starts this group.
       unsigned startIndex;
       /// The source definition of the result group.
@@ -67,7 +70,7 @@ class AsmParserState {
     llvm::SMRange scopeLoc;
 
     /// Source definitions for any result groups of this operation.
-    SmallVector<std::pair<unsigned, SMDefinition>> resultGroups;
+    SmallVector<ResultGroupDefinition> resultGroups;
 
     /// If this operation is a symbol operation, this vector contains symbol
     /// uses of this operation.

diff  --git a/mlir/lib/Parser/AsmParserState.cpp b/mlir/lib/Parser/AsmParserState.cpp
index e8e0479596377..5d40f50a3a36a 100644
--- a/mlir/lib/Parser/AsmParserState.cpp
+++ b/mlir/lib/Parser/AsmParserState.cpp
@@ -258,9 +258,9 @@ void AsmParserState::addUses(Value value, ArrayRef<llvm::SMLoc> locations) {
     unsigned resultNo = result.getResultNumber();
     OperationDefinition &def = *impl->operations[existingIt->second];
     for (auto &resultGroup : llvm::reverse(def.resultGroups)) {
-      if (resultNo >= resultGroup.first) {
+      if (resultNo >= resultGroup.startIndex) {
         for (llvm::SMLoc loc : locations)
-          resultGroup.second.uses.push_back(convertIdLocToRange(loc));
+          resultGroup.definition.uses.push_back(convertIdLocToRange(loc));
         return;
       }
     }

diff  --git a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
index 9f5a5d3d07449..83c00f05c45dd 100644
--- a/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
+++ b/mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp
@@ -367,7 +367,7 @@ void MLIRDocument::getLocationsOf(const lsp::URIForFile &uri,
     if (contains(op.loc, posLoc))
       return collectLocationsFromLoc(op.op->getLoc(), locations, uri);
     for (const auto &result : op.resultGroups)
-      if (containsPosition(result.second))
+      if (containsPosition(result.definition))
         return collectLocationsFromLoc(op.op->getLoc(), locations, uri);
     for (const auto &symUse : op.symbolUses) {
       if (contains(symUse, posLoc)) {
@@ -404,15 +404,15 @@ void MLIRDocument::findReferencesOf(const lsp::URIForFile &uri,
   for (const AsmParserState::OperationDefinition &op : asmState.getOpDefs()) {
     if (contains(op.loc, posLoc)) {
       for (const auto &result : op.resultGroups)
-        appendSMDef(result.second);
+        appendSMDef(result.definition);
       for (const auto &symUse : op.symbolUses)
         if (contains(symUse, posLoc))
           references.push_back(getLocationFromLoc(sourceMgr, symUse, uri));
       return;
     }
     for (const auto &result : op.resultGroups)
-      if (isDefOrUse(result.second, posLoc))
-        return appendSMDef(result.second);
+      if (isDefOrUse(result.definition, posLoc))
+        return appendSMDef(result.definition);
     for (const auto &symUse : op.symbolUses) {
       if (!contains(symUse, posLoc))
         continue;
@@ -456,13 +456,13 @@ Optional<lsp::Hover> MLIRDocument::findHover(const lsp::URIForFile &uri,
     // Check if the position points at a result group.
     for (unsigned i = 0, e = op.resultGroups.size(); i < e; ++i) {
       const auto &result = op.resultGroups[i];
-      if (!isDefOrUse(result.second, posLoc, &hoverRange))
+      if (!isDefOrUse(result.definition, posLoc, &hoverRange))
         continue;
 
       // Get the range of results covered by the over position.
-      unsigned resultStart = result.first;
-      unsigned resultEnd =
-          (i == e - 1) ? op.op->getNumResults() : op.resultGroups[i + 1].first;
+      unsigned resultStart = result.startIndex;
+      unsigned resultEnd = (i == e - 1) ? op.op->getNumResults()
+                                        : op.resultGroups[i + 1].startIndex;
       return buildHoverForOperationResult(hoverRange, op.op, resultStart,
                                           resultEnd, posLoc);
     }


        


More information about the Mlir-commits mailing list