[PATCH] D14363: [FunctionAttrs] Remove a loop, NFC refactor
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 4 18:00:15 PST 2015
sanjoy created this revision.
sanjoy added reviewers: reames, chandlerc, nlewycky.
sanjoy added a subscriber: llvm-commits.
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.
http://reviews.llvm.org/D14363
Files:
lib/Transforms/IPO/FunctionAttrs.cpp
Index: lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- lib/Transforms/IPO/FunctionAttrs.cpp
+++ lib/Transforms/IPO/FunctionAttrs.cpp
@@ -321,23 +321,19 @@
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;
- }
+ unsigned UseIndex =
+ std::distance(const_cast<const Use *>(CS->op_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;
+
+ auto FormalArgIt = F->arg_begin();
+ std::advance(FormalArgIt, UseIndex);
+ Uses.push_back(FormalArgIt);
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14363.39299.patch
Type: text/x-patch
Size: 1251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151105/53e760a9/attachment.bin>
More information about the llvm-commits
mailing list