From cf2de5a9701057c16dcf62c52791a2a55cae1bbe Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 26 Mar 2014 18:04:27 +0000 Subject: Add args() iteartor adapter to Function, for range-for loops. This patch is in similar vein to what done earlier to Module::globals/aliases etc. It allows to iterate over function arguments like this: for (Argument Arg : F.args()) { ... } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204835 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Function.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'include/llvm/IR') diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index 11208bb917..cb43bbaa93 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -18,6 +18,7 @@ #ifndef LLVM_IR_FUNCTION_H #define LLVM_IR_FUNCTION_H +#include "llvm/ADT/iterator_range.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" @@ -404,9 +405,9 @@ public: const BasicBlock &back() const { return BasicBlocks.back(); } BasicBlock &back() { return BasicBlocks.back(); } - //===--------------------------------------------------------------------===// - // Argument iterator forwarding functions - // +/// @name Function Argument Iteration +/// @{ + arg_iterator arg_begin() { CheckLazyArguments(); return ArgumentList.begin(); @@ -424,6 +425,16 @@ public: return ArgumentList.end(); } + iterator_range args() { + return iterator_range(arg_begin(), arg_end()); + } + + iterator_range args() const { + return iterator_range(arg_begin(), arg_end()); + } + +/// @} + size_t arg_size() const; bool arg_empty() const; -- cgit v1.2.3