[llvm] r291443 - [IR] Adding const_value_op_iterator for IR/User.h
Mohammed Agabaria via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 9 06:00:57 PST 2017
Author: magabari
Date: Mon Jan 9 08:00:57 2017
New Revision: 291443
URL: http://llvm.org/viewvc/llvm-project?rev=291443&view=rev
Log:
[IR] Adding const_value_op_iterator for IR/User.h
const value op iterator is missing from User.h class.
Differential Revision: https://reviews.llvm.org/D28464
Modified:
llvm/trunk/include/llvm/IR/User.h
llvm/trunk/unittests/IR/UserTest.cpp
Modified: llvm/trunk/include/llvm/IR/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/User.h?rev=291443&r1=291442&r2=291443&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/User.h (original)
+++ llvm/trunk/include/llvm/IR/User.h Mon Jan 9 08:00:57 2017
@@ -238,6 +238,26 @@ public:
return make_range(value_op_begin(), value_op_end());
}
+ struct const_value_op_iterator
+ : iterator_adaptor_base<const_value_op_iterator, const_op_iterator,
+ std::random_access_iterator_tag, const Value *,
+ ptrdiff_t, const Value *, const Value *> {
+ explicit const_value_op_iterator(const Use *U = nullptr) :
+ iterator_adaptor_base(U) {}
+ const Value *operator*() const { return *I; }
+ const Value *operator->() const { return operator*(); }
+ };
+
+ const_value_op_iterator value_op_begin() const {
+ return const_value_op_iterator(op_begin());
+ }
+ const_value_op_iterator value_op_end() const {
+ return const_value_op_iterator(op_end());
+ }
+ iterator_range<const_value_op_iterator> operand_values() const {
+ return make_range(value_op_begin(), value_op_end());
+ }
+
/// \brief Drop all references to operands.
///
/// This function is in charge of "letting go" of all objects that this User
Modified: llvm/trunk/unittests/IR/UserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/UserTest.cpp?rev=291443&r1=291442&r2=291443&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/UserTest.cpp (original)
+++ llvm/trunk/unittests/IR/UserTest.cpp Mon Jan 9 08:00:57 2017
@@ -84,6 +84,22 @@ TEST(UserTest, ValueOpIteration) {
EXPECT_FALSE(P.value_op_begin() >= P.value_op_end());
EXPECT_EQ(10, std::distance(P.value_op_begin(), P.value_op_end()));
+ // const value op iteration
+ const PHINode *IP = &P;
+ EXPECT_TRUE(IP->value_op_begin() == IP->value_op_begin());
+ EXPECT_FALSE(IP->value_op_begin() == IP->value_op_end());
+ EXPECT_TRUE(IP->value_op_begin() != IP->value_op_end());
+ EXPECT_FALSE(IP->value_op_end() != IP->value_op_end());
+ EXPECT_TRUE(IP->value_op_begin() < IP->value_op_end());
+ EXPECT_FALSE(IP->value_op_begin() < IP->value_op_begin());
+ EXPECT_TRUE(IP->value_op_end() > IP->value_op_begin());
+ EXPECT_FALSE(IP->value_op_begin() > IP->value_op_begin());
+ EXPECT_TRUE(IP->value_op_begin() <= IP->value_op_begin());
+ EXPECT_FALSE(IP->value_op_end() <= IP->value_op_begin());
+ EXPECT_TRUE(IP->value_op_begin() >= IP->value_op_begin());
+ EXPECT_FALSE(IP->value_op_begin() >= IP->value_op_end());
+ EXPECT_EQ(10, std::distance(IP->value_op_begin(), IP->value_op_end()));
+
User::value_op_iterator I = P.value_op_begin();
I += 3;
EXPECT_EQ(std::next(P.value_op_begin(), 3), I);
@@ -91,6 +107,15 @@ TEST(UserTest, ValueOpIteration) {
I++;
EXPECT_EQ(P.getOperand(6), I[2]);
EXPECT_EQ(P.value_op_end(), (I - 2) + 8);
+
+ // const value op
+ User::const_value_op_iterator CI = IP->value_op_begin();
+ CI += 3;
+ EXPECT_EQ(std::next(IP->value_op_begin(), 3), CI);
+ EXPECT_EQ(IP->getOperand(3), *CI);
+ CI++;
+ EXPECT_EQ(IP->getOperand(6), CI[2]);
+ EXPECT_EQ(IP->value_op_end(), (CI - 2) + 8);
}
TEST(UserTest, PersonalityUser) {
More information about the llvm-commits
mailing list