[llvm] r254047 - [OperandBundles] Extract duplicated code into a helper function, NFC

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 24 16:42:24 PST 2015


Author: sanjoy
Date: Tue Nov 24 18:42:24 2015
New Revision: 254047

URL: http://llvm.org/viewvc/llvm-project?rev=254047&view=rev
Log:
[OperandBundles] Extract duplicated code into a helper function, NFC

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

Modified: llvm/trunk/include/llvm/IR/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/CallSite.h?rev=254047&r1=254046&r2=254047&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/CallSite.h (original)
+++ llvm/trunk/include/llvm/IR/CallSite.h Tue Nov 24 18:42:24 2015
@@ -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);

Modified: llvm/trunk/include/llvm/IR/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/InstrTypes.h?rev=254047&r1=254046&r2=254047&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/IR/InstrTypes.h Tue Nov 24 18:42:24 2015
@@ -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

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=254047&r1=254046&r2=254047&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Tue Nov 24 18:42:24 2015
@@ -2268,11 +2268,7 @@ bool InstCombiner::transformConstExprCas
                                                        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)) {

Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=254047&r1=254046&r2=254047&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Tue Nov 24 18:42:24 2015
@@ -210,11 +210,7 @@ HandleCallsInBlockInlinedThroughInvoke(B
     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




More information about the llvm-commits mailing list