[IR] Add getArg() method to Function class

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

Patch by Henry Wildermuth

Differential Revision: https://reviews.llvm.org/D64925

llvm-svn: 367576
This commit is contained in:
Teresa Johnson 2019-08-01 15:31:40 +00:00
parent 3c26163d1a
commit 01dcdcdd92
2 changed files with 14 additions and 0 deletions

View File

@ -710,6 +710,12 @@ public:
return Arguments + NumArgs;
}
Argument* getArg(unsigned i) const {
assert (i < NumArgs && "getArg() out of range!");
CheckLazyArguments();
return Arguments + i;
}
iterator_range<arg_iterator> args() {
return make_range(arg_begin(), arg_end());
}

View File

@ -33,6 +33,14 @@ TEST(FunctionTest, hasLazyArguments) {
// The argument list should be populated at first access.
(void)F->arg_begin();
EXPECT_FALSE(F->hasLazyArguments());
// Checking that getArg gets the arguments from F1 in the correct order.
unsigned i = 0;
for (Argument &A : F->args()) {
EXPECT_EQ(&A, F->getArg(i));
++i;
}
EXPECT_FALSE(F->hasLazyArguments());
}
TEST(FunctionTest, stealArgumentListFrom) {