[llvm] r267190 - [LoopUtils] Extend findStringMetadataForLoop to return the value for metadata

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 12:10:06 PDT 2016


Author: anemet
Date: Fri Apr 22 14:10:05 2016
New Revision: 267190

URL: http://llvm.org/viewvc/llvm-project?rev=267190&view=rev
Log:
[LoopUtils] Extend findStringMetadataForLoop to return the value for metadata

E.g. for:

  !1 = {"llvm.distribute", i32 1}

it now returns the MDOperand for 1.

I will use this in LoopDistribution to check the value of the metadata.

Note that the change is backward-compatible with its current use in
LoopVersioningLICM.  An Optional implicitly converts to a bool depending
whether it contains a value or not.

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h
    llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp

Modified: llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h?rev=267190&r1=267189&r2=267190&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/LoopUtils.h Fri Apr 22 14:10:05 2016
@@ -385,9 +385,13 @@ void computeLICMSafetyInfo(LICMSafetyInf
 /// \brief Returns the instructions that use values defined in the loop.
 SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
 
-/// \brief Find string metadata for loop, if it exists return true, else return
-/// false.
-bool findStringMetadataForLoop(Loop *TheLoop, StringRef Name);
+/// \brief Find string metadata for loop
+///
+/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
+/// operand or null otherwise.  If the string metadata is not found return
+/// Optional's not-a-value.
+Optional<const MDOperand *> findStringMetadataForLoop(Loop *TheLoop,
+                                                      StringRef Name);
 
 /// \brief Set input string into loop metadata by keeping other values intact.
 void addStringMetadataToLoop(Loop *TheLoop, const char *MDString, 

Modified: llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp?rev=267190&r1=267189&r2=267190&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUtils.cpp Fri Apr 22 14:10:05 2016
@@ -823,13 +823,17 @@ void llvm::initializeLoopPassPass(PassRe
   INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
 }
 
-/// \brief Find string metadata for loop, if it exists return true, else return
-/// false.
-bool llvm::findStringMetadataForLoop(Loop *TheLoop, StringRef Name) {
+/// \brief Find string metadata for loop
+///
+/// If it has a value (e.g. {"llvm.distribute", 1} return the value as an
+/// operand or null otherwise.  If the string metadata is not found return
+/// Optional's not-a-value.
+Optional<const MDOperand *> llvm::findStringMetadataForLoop(Loop *TheLoop,
+                                                            StringRef Name) {
   MDNode *LoopID = TheLoop->getLoopID();
-  // Return false if LoopID is false.
+  // Return none if LoopID is false.
   if (!LoopID)
-    return false;
+    return None;
 
   // First operand should refer to the loop id itself.
   assert(LoopID->getNumOperands() > 0 && "requires at least one operand");
@@ -845,7 +849,14 @@ bool llvm::findStringMetadataForLoop(Loo
       continue;
     // Return true if MDString holds expected MetaData.
     if (Name.equals(S->getString()))
-      return true;
+      switch (MD->getNumOperands()) {
+      case 1:
+        return nullptr;
+      case 2:
+        return &MD->getOperand(1);
+      default:
+        llvm_unreachable("loop metadata has 0 or 1 operand");
+      }
   }
-  return false;
+  return None;
 }




More information about the llvm-commits mailing list