[llvm] r252644 - [OperandBundles] Identify operand bundles with both their names and IDs
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 10 12:13:15 PST 2015
Author: sanjoy
Date: Tue Nov 10 14:13:15 2015
New Revision: 252644
URL: http://llvm.org/viewvc/llvm-project?rev=252644&view=rev
Log:
[OperandBundles] Identify operand bundles with both their names and IDs
No code uses this functionality yet. This change just exposes
information / structure that was already present.
Modified:
llvm/trunk/include/llvm/IR/CallSite.h
llvm/trunk/include/llvm/IR/InstrTypes.h
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/trunk/lib/IR/AsmWriter.cpp
Modified: llvm/trunk/include/llvm/IR/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/CallSite.h?rev=252644&r1=252643&r2=252644&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/CallSite.h (original)
+++ llvm/trunk/include/llvm/IR/CallSite.h Tue Nov 10 14:13:15 2015
@@ -383,6 +383,10 @@ public:
CALLSITE_DELEGATE_GETTER(getOperandBundle(Name));
}
+ Optional<OperandBundleUse> getOperandBundle(uint32_t ID) const {
+ CALLSITE_DELEGATE_GETTER(getOperandBundle(ID));
+ }
+
#undef CALLSITE_DELEGATE_GETTER
#undef CALLSITE_DELEGATE_SETTER
Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=252644&r1=252643&r2=252644&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Tue Nov 10 14:13:15 2015
@@ -1114,12 +1114,11 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(Cmp
/// \brief A lightweight accessor for an operand bundle meant to be passed
/// around by value.
struct OperandBundleUse {
- StringRef Tag;
ArrayRef<Use> Inputs;
OperandBundleUse() {}
- explicit OperandBundleUse(StringRef Tag, ArrayRef<Use> Inputs)
- : Tag(Tag), Inputs(Inputs) {}
+ explicit OperandBundleUse(StringMapEntry<uint32_t> *Tag, ArrayRef<Use> Inputs)
+ : Inputs(Inputs), Tag(Tag) {}
/// \brief Return true if all the operands in this operand bundle have the
/// attribute A.
@@ -1130,6 +1129,24 @@ struct OperandBundleUse {
// Conservative answer: no operands have any attributes.
return false;
};
+
+ /// \brief Return the tag of this operand bundle as a string.
+ StringRef getTagName() const {
+ return Tag->getKey();
+ }
+
+ /// \brief Return the tag of this operand bundle as an integer.
+ ///
+ /// Operand bundle tags are interned by LLVMContextImpl::getOrInsertBundleTag,
+ /// and this function returns the unique integer getOrInsertBundleTag
+ /// associated the tag of this operand bundle to.
+ uint32_t getTagID() const {
+ return Tag->getValue();
+ }
+
+private:
+ /// \brief Pointer to an entry in LLVMContextImpl::getOrInsertBundleTag.
+ StringMapEntry<uint32_t> *Tag;
};
/// \brief A container for an operand bundle being viewed as a set of values
@@ -1242,7 +1259,18 @@ public:
unsigned countOperandBundlesOfType(StringRef Name) const {
unsigned Count = 0;
for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
- if (getOperandBundleAt(i).Tag == Name)
+ if (getOperandBundleAt(i).getTagName() == Name)
+ Count++;
+
+ return Count;
+ }
+
+ /// \brief Return the number of operand bundles with the tag ID attached to
+ /// this instruction.
+ unsigned countOperandBundlesOfType(uint32_t ID) const {
+ unsigned Count = 0;
+ for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
+ if (getOperandBundleAt(i).getTagID() == ID)
Count++;
return Count;
@@ -1257,7 +1285,23 @@ public:
for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
OperandBundleUse U = getOperandBundleAt(i);
- if (U.Tag == Name)
+ if (U.getTagName() == Name)
+ return U;
+ }
+
+ return None;
+ }
+
+ /// \brief Return an operand bundle by tag ID, 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(uint32_t ID) const {
+ assert(countOperandBundlesOfType(ID) < 2 && "Precondition violated!");
+
+ for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) {
+ OperandBundleUse U = getOperandBundleAt(i);
+ if (U.getTagID() == ID)
return U;
}
@@ -1345,7 +1389,7 @@ protected:
operandBundleFromBundleOpInfo(const BundleOpInfo &BOI) const {
auto op_begin = static_cast<const InstrTy *>(this)->op_begin();
ArrayRef<Use> Inputs(op_begin + BOI.Begin, op_begin + BOI.End);
- return OperandBundleUse(BOI.Tag->getKey(), Inputs);
+ return OperandBundleUse(BOI.Tag, Inputs);
}
typedef BundleOpInfo *bundle_op_iterator;
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=252644&r1=252643&r2=252644&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Tue Nov 10 14:13:15 2015
@@ -1739,7 +1739,7 @@ static void WriteOperandBundles(Bitstrea
for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) {
const auto &Bundle = CS.getOperandBundleAt(i);
- Record.push_back(C.getOperandBundleTagID(Bundle.Tag));
+ Record.push_back(C.getOperandBundleTagID(Bundle.getTagName()));
for (auto &Input : Bundle.Inputs)
PushValueAndType(Input, InstID, Record, VE);
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=252644&r1=252643&r2=252644&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Tue Nov 10 14:13:15 2015
@@ -2176,7 +2176,7 @@ void AssemblyWriter::writeOperandBundles
FirstBundle = false;
Out << '"';
- PrintEscapedString(BU.Tag, Out);
+ PrintEscapedString(BU.getTagName(), Out);
Out << '"';
Out << '(';
More information about the llvm-commits
mailing list