From 76cac2771911e8448135fdd97960c7baf953f3f7 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Wed, 7 Oct 2015 02:39:24 +0000 Subject: [PATCH] [OperandBundles] Add an accessor to get an operand bundle by tag 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 | 4 ++++ include/llvm/IR/InstrTypes.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/llvm/IR/CallSite.h b/include/llvm/IR/CallSite.h index d1f1847581c..d8fd9fa30a6 100644 --- a/include/llvm/IR/CallSite.h +++ b/include/llvm/IR/CallSite.h @@ -333,6 +333,10 @@ public: CALLSITE_DELEGATE_GETTER(getOperandBundle(Index)); } + Optional getOperandBundle(StringRef Name) const { + CALLSITE_DELEGATE_GETTER(getOperandBundle(Name)); + } + #undef CALLSITE_DELEGATE_GETTER #undef CALLSITE_DELEGATE_SETTER diff --git a/include/llvm/IR/InstrTypes.h b/include/llvm/IR/InstrTypes.h index b4d0fec21b1..c3bbe22069c 100644 --- a/include/llvm/IR/InstrTypes.h +++ b/include/llvm/IR/InstrTypes.h @@ -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 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. -- 2.34.1