[OperandBundles] Extract duplicated code into a helper function, NFC
authorSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 25 Nov 2015 00:42:24 +0000 (00:42 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 25 Nov 2015 00:42:24 +0000 (00:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254047 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/CallSite.h
include/llvm/IR/InstrTypes.h
lib/Transforms/InstCombine/InstCombineCalls.cpp
lib/Transforms/Utils/InlineFunction.cpp

index 820f96356c6791f0bb7bf7127d6ba7adb5ef1acb..c87f1293330bc374e6632457357d1236219f484a 100644 (file)
@@ -390,6 +390,16 @@ public:
 #undef CALLSITE_DELEGATE_GETTER
 #undef CALLSITE_DELEGATE_SETTER
 
+  void getOperandBundlesAsDefs(SmallVectorImpl<OperandBundleDef> &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<CallInst>(II)->getOperandBundlesAsDefs(Defs);
+    else
+      cast<InvokeInst>(II)->getOperandBundlesAsDefs(Defs);
+  }
+
   /// @brief Determine whether this data operand is not captured.
   bool doesNotCapture(unsigned OpNo) const {
     return dataOperandHasImpliedAttr(OpNo + 1, Attribute::NoCapture);
index 737b46fbe337c00b57452edb2d0e962ae767e14d..32dceeac3fc23b32a31e8188d10312789f431797 100644 (file)
@@ -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<OperandBundleDef> &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
index c3fbaf2adfc04bcd950e64841fdcdcf74325e800..26088bbe018a7bd048c42ccdee184ff220bb5f5b 100644 (file)
@@ -2268,11 +2268,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
                                                        attrVec);
 
   SmallVector<OperandBundleDef, 1> 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<InvokeInst>(Caller)) {
index dd8e5b3b044932dc93942a6cdd454dfca02a89bb..aee84c07d5934b01543c7089141482c52dc1d167 100644 (file)
@@ -210,11 +210,7 @@ HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB, BasicBlock *UnwindEdge) {
     SmallVector<Value*, 8> InvokeArgs(CS.arg_begin(), CS.arg_end());
     SmallVector<OperandBundleDef, 1> 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