[OperandBundles] Add an accessor to get an operand bundle by tag
authorSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 7 Oct 2015 02:39:24 +0000 (02:39 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 7 Oct 2015 02:39:24 +0000 (02:39 +0000)
Not used at the moment, but will be used in a later change to
RewriteStatepointsForGC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249510 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/CallSite.h
include/llvm/IR/InstrTypes.h

index d1f1847581c00df5f17b806b76aa57f58b48e5fc..d8fd9fa30a6f92fe69b9bc9713cb7adcd05e6cad 100644 (file)
@@ -333,6 +333,10 @@ public:
     CALLSITE_DELEGATE_GETTER(getOperandBundle(Index));
   }
 
+  Optional<OperandBundleUse> getOperandBundle(StringRef Name) const {
+    CALLSITE_DELEGATE_GETTER(getOperandBundle(Name));
+  }
+
 #undef CALLSITE_DELEGATE_GETTER
 #undef CALLSITE_DELEGATE_SETTER
 
index b4d0fec21b1ed4cfc3f16639cfb0d5c625b2d5fb..c3bbe22069c80971ae2b009127380f7cac8c68e0 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef LLVM_IR_INSTRTYPES_H
 #define LLVM_IR_INSTRTYPES_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instruction.h"
@@ -1204,6 +1205,34 @@ public:
     return OperandBundleUse(BOI->Tag->getKey(), Inputs);
   }
 
+  /// \brief Return the number of operand bundles with the tag Name attached to
+  /// this instruction.
+  unsigned countOperandBundlesOfType(StringRef Name) const {
+    unsigned Count = 0;
+    for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
+      if (getOperandBundle(i).Tag == Name)
+        Count++;
+
+    return Count;
+  }
+
+  /// \brief Return an operand bundle by name, if present.
+  ///
+  /// It is an error to call this for operand bundle types that may have
+  /// multiple instances of them on the same instruction.
+  Optional<OperandBundleUse> getOperandBundle(StringRef Name) const {
+    assert(countOperandBundlesOfType(Name) < 2 && "Precondition violated!");
+
+    for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
+      OperandBundleUse U = getOperandBundle(i);
+      if (U.Tag == Name)
+        return U;
+    }
+
+    return None;
+  }
+
+
 protected:
   /// \brief Used to keep track of an operand bundle.  See the main comment on
   /// OperandBundleUser above.