This is an archive of the discontinued LLVM Phabricator instance.

[IR] Add getArg() method to Function class
ClosedPublic

Authored by hmwildermuth on Jul 18 2019, 7:56 AM.

Details

Summary

Adds a method which, when called with function.getArg(i), returns an Argument* to the i'th argument.

Diff Detail

Repository
rL LLVM

Event Timeline

hmwildermuth created this revision.Jul 18 2019, 7:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2019, 7:56 AM
hmwildermuth changed the repository for this revision from rL LLVM to rG LLVM Github Monorepo.Jul 18 2019, 12:17 PM

Suggest sending this change with patch that uses and tests it.

Suggest sending this change with patch that uses and tests it.

@tejohnson any more recommendations?

Suggest sending this change with patch that uses and tests it.

@tejohnson any more recommendations?

It looks fine but is there a plan for a follow on patch that uses this new facility in the code (not just in a unit test)? Wondering since I see that the type of arg_begin() is actually "Argument *" so there is already a fair amount of code that just does something like either arg_begin()[index] or arg_begin()+index. Not opposed to adding a new interface for this, but wondering what the motivating case is.

Also, for future patches - please upload patches with context (see https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface) to make them easier to review.

Suggest sending this change with patch that uses and tests it.

@tejohnson any more recommendations?

It looks fine but is there a plan for a follow on patch that uses this new facility in the code (not just in a unit test)? Wondering since I see that the type of arg_begin() is actually "Argument *" so there is already a fair amount of code that just does something like either arg_begin()[index] or arg_begin()+index. Not opposed to adding a new interface for this, but wondering what the motivating case is.

Also, for future patches - please upload patches with context (see https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface) to make them easier to review.

Thank you for your tip on the patch context, this is my first patch.

The idea is that the method name should be as descriptive as possible for the use; something like arg_begin()[index] is much less descriptive than getArg(index). The reason I originally wrote the patch is because I was writing an LLVM pass and needed a specific argument to a function, but the documentation was unclear to me at the time on how to do it and the use of arg_begin and the arg_iterator type added unnecessary confusion. There also seem to be similar implementations in other classes, e.g. getOperandList () and getOperandUse(index) in the User class, so there is somewhat of a precedent for this kind of facility.

In terms of using this facility, I have no distinct plan but I may go through and replace arg_begin()[index] as I come across them, and would recommend that others should as well to improve readability.

This revision is now accepted and ready to land.Jul 29 2019, 8:06 AM

I can't seem to commit it myself, could someone else do it for me? Potentially @tejohnson

I can't seem to commit it myself, could someone else do it for me? Potentially @tejohnson

Sure, I will commit for you tomorrow. To get commit access for future patches see https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

This revision was automatically updated to reflect the committed changes.