forked from OSchip/llvm-project
[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 llvm-svn: 291443
This commit is contained in:
parent
7d6285fb1c
commit
e0e7cdf36c
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue