This is an archive of the discontinued LLVM Phabricator instance.

[FunctionAttrs] Remove a loop, NFC refactor
ClosedPublic

Authored by sanjoy on Nov 4 2015, 6:00 PM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy updated this revision to Diff 39299.Nov 4 2015, 6:00 PM
sanjoy retitled this revision from to [FunctionAttrs] Remove a loop, NFC refactor.
sanjoy updated this object.
sanjoy added reviewers: reames, chandlerc, nlewycky.
sanjoy added a subscriber: llvm-commits.
chandlerc accepted this revision.Nov 4 2015, 6:06 PM
chandlerc edited edge metadata.

Generally much cleaner, minor comments below, submit whenever.

lib/Transforms/IPO/FunctionAttrs.cpp
324–325 ↗(On Diff #39299)

Why op_begin here rather than arg_begin?

Also, its a bit odd that the use index here is the correct increment amount for the function argument iterator -- where is the function operand to the callsite?

I'd at least leave some comments to remind the reader of the surprising indexing contract of argument operands vs. function operands and the function argument list.

334–336 ↗(On Diff #39299)

This can be:

Uses.push_back(std::next(F->arg_begin(), UseIndex));
This revision is now accepted and ready to land.Nov 4 2015, 6:06 PM
sanjoy added inline comments.Nov 4 2015, 6:12 PM
lib/Transforms/IPO/FunctionAttrs.cpp
324–325 ↗(On Diff #39299)

Why op_begin here rather than arg_begin?

Also, its a bit odd that the use index here is the correct increment
amount for the function argument iterator -- where is the function
operand to the callsite?

For callsites, op_begin == arg_begin. The callee and the two
successor blocks (for invokes) are the last operands to the call or
invoke instruction.

I'll change this to use arg_begin instead, that will make things
more obvious.

I'd at least leave some comments to remind the reader of the
surprising indexing contract of argument operands vs. function
operands and the function argument list.

Will do.

334–336 ↗(On Diff #39299)

I didn't know std::next took a parameter, thanks! Will fix.

This revision was automatically updated to reflect the committed changes.