diff options
author | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-11-05 03:04:40 +0000 |
---|---|---|
committer | Sanjoy Das <sanjoy@playingwithpointers.com> | 2015-11-05 03:04:40 +0000 |
commit | 98bfe26bf8cbb088d13a3aee2d5c29070ffbbd55 (patch) | |
tree | fdbb856ab913328f9d164cce0ae449ee8485dbb1 | |
parent | a40450cba2d40c33a58f2da075e807e1953c2c6a (diff) | |
download | bcm5719-llvm-98bfe26bf8cbb088d13a3aee2d5c29070ffbbd55.tar.gz bcm5719-llvm-98bfe26bf8cbb088d13a3aee2d5c29070ffbbd55.zip |
[FunctionAttrs] Remove a loop, NFC refactor
Summary:
Remove the loop over the uses of the CallSite in ArgumentUsesTracker.
Since we have the `Use *` for actual argument operand, we can just use
pointer subtraction.
The time complexity remains the same though (except for a vararg
argument) -- `std::advance` is O(UseIndex) for the ArgumentList
iterator.
The real motivation is to make a later change adding support for operand
bundles simpler.
Reviewers: reames, chandlerc, nlewycky
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D14363
llvm-svn: 252141
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 80050220c8b..bc7c98e2890 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -321,23 +321,21 @@ struct ArgumentUsesTracker : public CaptureTracker { return true; } - bool Found = false; - Function::arg_iterator AI = F->arg_begin(), AE = F->arg_end(); - for (CallSite::arg_iterator PI = CS.arg_begin(), PE = CS.arg_end(); - PI != PE; ++PI, ++AI) { - if (AI == AE) { - assert(F->isVarArg() && "More params than args in non-varargs call"); - Captured = true; - return true; - } - if (PI == U) { - Uses.push_back(&*AI); - Found = true; - break; - } + // Note: the callee and the two successor blocks *follow* the argument + // operands. This means there is no need to adjust UseIndex to account for + // these. + + unsigned UseIndex = + std::distance(const_cast<const Use *>(CS.arg_begin()), U); + + assert(UseIndex < CS.arg_size() && "Non-argument use?"); + if (UseIndex >= F->arg_size()) { + assert(F->isVarArg() && "More params than args in non-varargs call"); + Captured = true; + return true; } - assert(Found && "Capturing call-site captured nothing?"); - (void)Found; + + Uses.push_back(std::next(F->arg_begin(), UseIndex)); return false; } |