diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-03-09 03:16:01 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-03-09 03:16:01 +0000 |
commit | cdf4788401afff02e12279fc1fded94d6180639c (patch) | |
tree | 4b7b22b5e5b9ee152848a85ca3a911566532ecef /llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | |
parent | c980afc578f9c1af3b8916b4a503ea26ebaee018 (diff) | |
download | bcm5719-llvm-cdf4788401afff02e12279fc1fded94d6180639c.tar.gz bcm5719-llvm-cdf4788401afff02e12279fc1fded94d6180639c.zip |
[C++11] Add range based accessors for the Use-Def chain of a Value.
This requires a number of steps.
1) Move value_use_iterator into the Value class as an implementation
detail
2) Change it to actually be a *Use* iterator rather than a *User*
iterator.
3) Add an adaptor which is a User iterator that always looks through the
Use to the User.
4) Wrap these in Value::use_iterator and Value::user_iterator typedefs.
5) Add the range adaptors as Value::uses() and Value::users().
6) Update *all* of the callers to correctly distinguish between whether
they wanted a use_iterator (and to explicitly dig out the User when
needed), or a user_iterator which makes the Use itself totally
opaque.
Because #6 requires churning essentially everything that walked the
Use-Def chains, I went ahead and added all of the range adaptors and
switched them to range-based loops where appropriate. Also because the
renaming requires at least churning every line of code, it didn't make
any sense to split these up into multiple commits -- all of which would
touch all of the same lies of code.
The result is still not quite optimal. The Value::use_iterator is a nice
regular iterator, but Value::user_iterator is an iterator over User*s
rather than over the User objects themselves. As a consequence, it fits
a bit awkwardly into the range-based world and it has the weird
extra-dereferencing 'operator->' that so many of our iterators have.
I think this could be fixed by providing something which transforms
a range of T&s into a range of T*s, but that *can* be separated into
another patch, and it isn't yet 100% clear whether this is the right
move.
However, this change gets us most of the benefit and cleans up
a substantial amount of code around Use and User. =]
llvm-svn: 203364
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp index 5da3abcde15..0ab657a2794 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -255,9 +255,7 @@ static bool isSafeAndProfitableToSinkLoad(LoadInst *L) { // profitable to do this xform. if (AllocaInst *AI = dyn_cast<AllocaInst>(L->getOperand(0))) { bool isAddressTaken = false; - for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); - UI != E; ++UI) { - User *U = *UI; + for (User *U : AI->users()) { if (isa<LoadInst>(U)) continue; if (StoreInst *SI = dyn_cast<StoreInst>(U)) { // If storing TO the alloca, then the address isn't taken. @@ -518,7 +516,7 @@ static bool DeadPHICycle(PHINode *PN, if (PotentiallyDeadPHIs.size() == 16) return false; - if (PHINode *PU = dyn_cast<PHINode>(PN->use_back())) + if (PHINode *PU = dyn_cast<PHINode>(PN->user_back())) return DeadPHICycle(PU, PotentiallyDeadPHIs); return false; @@ -649,32 +647,30 @@ Instruction *InstCombiner::SliceUpIllegalIntegerPHI(PHINode &FirstPhi) { return 0; } - - for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end(); - UI != E; ++UI) { - Instruction *User = cast<Instruction>(*UI); + for (User *U : PN->users()) { + Instruction *UserI = cast<Instruction>(U); // If the user is a PHI, inspect its uses recursively. - if (PHINode *UserPN = dyn_cast<PHINode>(User)) { + if (PHINode *UserPN = dyn_cast<PHINode>(UserI)) { if (PHIsInspected.insert(UserPN)) PHIsToSlice.push_back(UserPN); continue; } // Truncates are always ok. - if (isa<TruncInst>(User)) { - PHIUsers.push_back(PHIUsageRecord(PHIId, 0, User)); + if (isa<TruncInst>(UserI)) { + PHIUsers.push_back(PHIUsageRecord(PHIId, 0, UserI)); continue; } // Otherwise it must be a lshr which can only be used by one trunc. - if (User->getOpcode() != Instruction::LShr || - !User->hasOneUse() || !isa<TruncInst>(User->use_back()) || - !isa<ConstantInt>(User->getOperand(1))) + if (UserI->getOpcode() != Instruction::LShr || + !UserI->hasOneUse() || !isa<TruncInst>(UserI->user_back()) || + !isa<ConstantInt>(UserI->getOperand(1))) return 0; - unsigned Shift = cast<ConstantInt>(User->getOperand(1))->getZExtValue(); - PHIUsers.push_back(PHIUsageRecord(PHIId, Shift, User->use_back())); + unsigned Shift = cast<ConstantInt>(UserI->getOperand(1))->getZExtValue(); + PHIUsers.push_back(PHIUsageRecord(PHIId, Shift, UserI->user_back())); } } @@ -809,7 +805,7 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) { // this PHI only has a single use (a PHI), and if that PHI only has one use (a // PHI)... break the cycle. if (PN.hasOneUse()) { - Instruction *PHIUser = cast<Instruction>(PN.use_back()); + Instruction *PHIUser = cast<Instruction>(PN.user_back()); if (PHINode *PU = dyn_cast<PHINode>(PHIUser)) { SmallPtrSet<PHINode*, 16> PotentiallyDeadPHIs; PotentiallyDeadPHIs.insert(&PN); @@ -825,7 +821,7 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) { // late. if (PHIUser->hasOneUse() && (isa<BinaryOperator>(PHIUser) || isa<GetElementPtrInst>(PHIUser)) && - PHIUser->use_back() == &PN) { + PHIUser->user_back() == &PN) { return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType())); } } |