[llvm] c250ebf - getArgOperandNo helper function.

Stefan Stipanovic via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 10 13:01:26 PST 2019


Author: Stefan Stipanovic
Date: 2019-11-10T21:45:11+01:00
New Revision: c250ebf7bcaa85f5366c651c2efdda828258cb27

URL: https://github.com/llvm/llvm-project/commit/c250ebf7bcaa85f5366c651c2efdda828258cb27
DIFF: https://github.com/llvm/llvm-project/commit/c250ebf7bcaa85f5366c651c2efdda828258cb27.diff

LOG: getArgOperandNo helper function.

Summary: A helper function to get argument number of a arg operand Use.

Reviewers: jdoerfert, uenoku

Subscribers: hiraditya, lebedev.ri, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D66844

Added: 
    

Modified: 
    llvm/include/llvm/IR/InstrTypes.h
    llvm/lib/Transforms/IPO/Attributor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index faf58cf19014..a85e0f293469 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1272,6 +1272,19 @@ class CallBase : public Instruction {
     return isArgOperand(&UI.getUse());
   }
 
+  /// Given a use for a arg operand, get the arg operand number that
+  /// corresponds to it.
+  unsigned getArgOperandNo(const Use *U) const {
+    assert(isArgOperand(U) && "Arg operand # out of range!");
+    return U - arg_begin();
+  }
+
+  /// Given a value use iterator, return the arg operand number corresponding to
+  /// it. Iterator must actually correspond to a data operand.
+  unsigned getArgOperandNo(Value::const_user_iterator UI) const {
+    return getArgOperandNo(&UI.getUse());
+  }
+
   /// Returns true if this CallSite passes the given Value* as an argument to
   /// the called function.
   bool hasArgument(const Value *V) const {

diff  --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index b7471a32faf4..b959dc0e6070 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1572,7 +1572,7 @@ struct AANoFreeFloating : AANoFreeImpl {
         if (!CB->isArgOperand(U))
           continue;
 
-        unsigned ArgNo = U - CB->arg_begin();
+        unsigned ArgNo = CB->getArgOperandNo(U);
 
         const auto &NoFreeArg = A.getAAFor<AANoFree>(
             *this, IRPosition::callsite_argument(*CB, ArgNo));
@@ -4144,7 +4144,7 @@ ChangeStatus AAHeapToStackImpl::updateImpl(Attributor &A) {
         const auto &NoFreeAA =
             A.getAAFor<AANoFree>(*this, IRPosition::callsite_function(*CB));
 
-        unsigned ArgNo = U - CB->arg_begin();
+        unsigned ArgNo = CB->getArgOperandNo(U);
         const auto &NoCaptureAA = A.getAAFor<AANoCapture>(
             *this, IRPosition::callsite_argument(*CB, ArgNo));
 


        


More information about the llvm-commits mailing list