[PATCH] D24872: Get the instruction having loop id.

Aditya Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 09:23:59 PDT 2016


hiraditya created this revision.
hiraditya added reviewers: majnemer, spatel.
hiraditya added subscribers: sebpop, llvm-commits.
Herald added a subscriber: mzolotukhin.

This is useful in moving the loop id from the instruction to another when a loop is rotated. See: D22630

https://reviews.llvm.org/D24872

Files:
  llvm/include/llvm/Analysis/LoopInfo.h
  llvm/lib/Analysis/LoopInfo.cpp

Index: llvm/lib/Analysis/LoopInfo.cpp
===================================================================
--- llvm/lib/Analysis/LoopInfo.cpp
+++ llvm/lib/Analysis/LoopInfo.cpp
@@ -203,8 +203,9 @@
   return true;
 }
 
-MDNode *Loop::getLoopID() const {
+std::pair<MDNode *, Instruction *> Loop::getLoopIDWithInstr() const {
   MDNode *LoopID = nullptr;
+  Instruction *I = nullptr;
   if (isLoopSimplifyForm()) {
     LoopID = getLoopLatch()->getTerminator()->getMetadata(LLVMContext::MD_loop);
   } else {
@@ -218,17 +219,19 @@
 
       TerminatorInst *TI = BB->getTerminator();
       if (MDNode *MD = TI->getMetadata(LLVMContext::MD_loop)) {
-        if (!LoopID)
+        if (!LoopID) {
           LoopID = MD;
+          I = TI;
+        }
         else if (MD != LoopID) // Multiple MD_loop found => corrupt metadata.
-          return nullptr;
+          return { nullptr, nullptr };
       }
     }
   }
   if (!LoopID || LoopID->getNumOperands() == 0 ||
       LoopID->getOperand(0) != LoopID)
-    return nullptr;
-  return LoopID;
+    return { nullptr, nullptr };
+  return { LoopID, I };
 }
 
 void Loop::setLoopID(MDNode *LoopID) const {
Index: llvm/include/llvm/Analysis/LoopInfo.h
===================================================================
--- llvm/include/llvm/Analysis/LoopInfo.h
+++ llvm/include/llvm/Analysis/LoopInfo.h
@@ -441,7 +441,9 @@
   /// header then the node is returned. If any latch instruction does not
   /// contain llvm.loop or or if multiple latches contain different nodes then
   /// 0 is returned.
-  MDNode *getLoopID() const;
+  std::pair<MDNode *, Instruction *> getLoopIDWithInstr() const;
+  MDNode *getLoopID() const { return getLoopIDWithInstr().first; }
+
   /// Set the llvm.loop loop id metadata for this loop.
   ///
   /// The LoopID metadata node will be added to each terminator instruction in


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24872.72298.patch
Type: text/x-patch
Size: 1855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160923/10f80d87/attachment-0001.bin>


More information about the llvm-commits mailing list