From 00fb64dd3b56e1db7586f59cff82dd9f5b52205d Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Wed, 25 Nov 2015 00:42:24 +0000 Subject: [PATCH] [OperandBundles] Extract duplicated code into a helper function, NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254047 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/CallSite.h | 10 ++++++++++ include/llvm/IR/InstrTypes.h | 12 ++++++++++++ lib/Transforms/InstCombine/InstCombineCalls.cpp | 6 +----- lib/Transforms/Utils/InlineFunction.cpp | 6 +----- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/llvm/IR/CallSite.h b/include/llvm/IR/CallSite.h index 820f96356c6..c87f1293330 100644 --- a/include/llvm/IR/CallSite.h +++ b/include/llvm/IR/CallSite.h @@ -390,6 +390,16 @@ public: #undef CALLSITE_DELEGATE_GETTER #undef CALLSITE_DELEGATE_SETTER + void getOperandBundlesAsDefs(SmallVectorImpl &Defs) const { + const Instruction *II = getInstruction(); + // Since this is actually a getter that "looks like" a setter, don't use the + // above macros to avoid confusion. + if (isCall()) + cast(II)->getOperandBundlesAsDefs(Defs); + else + cast(II)->getOperandBundlesAsDefs(Defs); + } + /// @brief Determine whether this data operand is not captured. bool doesNotCapture(unsigned OpNo) const { return dataOperandHasImpliedAttr(OpNo + 1, Attribute::NoCapture); diff --git a/include/llvm/IR/InstrTypes.h b/include/llvm/IR/InstrTypes.h index 737b46fbe33..32dceeac3fc 100644 --- a/include/llvm/IR/InstrTypes.h +++ b/include/llvm/IR/InstrTypes.h @@ -1325,6 +1325,18 @@ public: return None; } + /// \brief Return the list of operand bundles attached to this instruction as + /// a vector of OperandBundleDefs. + /// + /// This function copies the OperandBundeUse instances associated with this + /// OperandBundleUser to a vector of OperandBundleDefs. Note: + /// OperandBundeUses and OperandBundleDefs are non-trivially *different* + /// representations of operand bundles (see documentation above). + void getOperandBundlesAsDefs(SmallVectorImpl &Defs) const { + for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i) + Defs.emplace_back(getOperandBundleAt(i)); + } + /// \brief Return the operand bundle for the operand at index OpIdx. /// /// It is an error to call this with an OpIdx that does not correspond to an diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index c3fbaf2adfc..26088bbe018 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2268,11 +2268,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { attrVec); SmallVector OpBundles; - - // Convert the operand bundle uses to operand bundle defs. See InstrTypes.h - // for details on how these differ. - for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) - OpBundles.emplace_back(CS.getOperandBundleAt(i)); + CS.getOperandBundlesAsDefs(OpBundles); Instruction *NC; if (InvokeInst *II = dyn_cast(Caller)) { diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index dd8e5b3b044..aee84c07d59 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -210,11 +210,7 @@ HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB, BasicBlock *UnwindEdge) { SmallVector InvokeArgs(CS.arg_begin(), CS.arg_end()); SmallVector OpBundles; - // Copy the OperandBundeUse instances to OperandBundleDefs. These two are - // *different* representations of operand bundles: see the documentation in - // InstrTypes.h for more details. - for (unsigned i = 0, e = CS.getNumOperandBundles(); i != e; ++i) - OpBundles.emplace_back(CS.getOperandBundleAt(i)); + CS.getOperandBundlesAsDefs(OpBundles); // Note: we're round tripping operand bundles through memory here, and that // can potentially be avoided with a cleverer API design that we do not have -- 2.34.1