[PATCH] D73866: [RDA] getInstFromId: find instructions. NFC.

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 03:14:15 PST 2020


SjoerdMeijer updated this revision to Diff 242008.
SjoerdMeijer added a comment.

Ah, yes, thanks for catching. We can just use `find` instead.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73866/new/

https://reviews.llvm.org/D73866

Files:
  llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
  llvm/lib/CodeGen/ReachingDefAnalysis.cpp


Index: llvm/lib/CodeGen/ReachingDefAnalysis.cpp
===================================================================
--- llvm/lib/CodeGen/ReachingDefAnalysis.cpp
+++ llvm/lib/CodeGen/ReachingDefAnalysis.cpp
@@ -214,10 +214,17 @@
   if (InstId < 0)
     return nullptr;
 
-  for (auto &MI : *MBB) {
-    if (InstIds.count(&MI) && InstIds.lookup(&MI) == InstId)
-      return &MI;
-  }
+  auto It = std::find_if(MBB->begin(), MBB->end(), [&](const MachineInstr &MI) {
+    auto F = InstIds.find(&MI);
+    if (F->first != MBB->end() && F->second == InstId)
+      return true;
+    else
+      return false;
+  });
+
+  if (It != MBB->end())
+    return &*It;
+
   return nullptr;
 }
 
Index: llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
===================================================================
--- llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
+++ llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
@@ -55,7 +55,7 @@
   /// The first instruction in each basic block is 0.
   int CurInstr;
 
-  /// Maps instructions to their instruction Ids, relative to the begining of
+  /// Maps instructions to their instruction Ids, relative to the beginning of
   /// their basic blocks.
   DenseMap<MachineInstr *, int> InstIds;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73866.242008.patch
Type: text/x-patch
Size: 1232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200203/8dbe041e/attachment.bin>


More information about the llvm-commits mailing list