This is an archive of the discontinued LLVM Phabricator instance.

Add getReturnedArgOperand to Call/InvokeInst, CallSite
ClosedPublic

Authored by hfinkel on Jul 10 2016, 2:28 PM.

Details

Summary

In order to make the optimizer smarter about using the 'returned' argument attribute (generally, but motivated by my llvm.noalias intrinsic work), add a utility function to Call/InvokeInst, and CallSite, to make it easy to get the returned call argument (when one exists).

P.S. There is already an unfortunate amount of code duplication between CallInst and InvokeInst, and this adds to it. We should probably clean that up separately.

Diff Detail

Repository
rL LLVM

Event Timeline

hfinkel updated this revision to Diff 63435.Jul 10 2016, 2:28 PM
hfinkel retitled this revision from to Add getReturnedArgOperand to Call/InvokeInst, CallSite.
hfinkel updated this object.
hfinkel added reviewers: majnemer, chandlerc.
hfinkel added a subscriber: llvm-commits.
majnemer accepted this revision.Jul 10 2016, 2:41 PM
majnemer edited edge metadata.

LGTM, the nit can be optionally addressed.

include/llvm/IR/Attributes.h
343–344 ↗(On Diff #63435)

Maybe this interface would be nicer if it returned an Optional<bool>. I think it would have minimal impact on the callers.

This revision is now accepted and ready to land.Jul 10 2016, 2:41 PM
hfinkel added inline comments.Jul 10 2016, 3:18 PM
include/llvm/IR/Attributes.h
343–344 ↗(On Diff #63435)

True. I'd need to update all existing callers to call hasValue(), right? I can do that separately.

majnemer added inline comments.Jul 10 2016, 3:41 PM
include/llvm/IR/Attributes.h
343–344 ↗(On Diff #63435)

No, Optional has an explicit operator bool().

hfinkel added inline comments.Jul 10 2016, 3:53 PM
include/llvm/IR/Attributes.h
343–344 ↗(On Diff #63435)

OIC, thanks! I think I'll do this later regardless because I should, however, also rename the function when I do this. It should become something like:

Optional<unsigned> getAttrIndex(Attribute::AttrKind Kind) const;
majnemer added inline comments.Jul 10 2016, 4:00 PM
include/llvm/IR/Attributes.h
343–344 ↗(On Diff #63435)

SGTM

This revision was automatically updated to reflect the committed changes.