diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -277,8 +277,10 @@ /// which is the branch condition. VPUser CondBitUser; - /// Current block predicate - null if the block does not need a predicate. - VPValue *Predicate = nullptr; + /// If the block is predicated, its predicate is stored as an operand of this + /// VPUser to maintain the def-use relations. Otherwise there is no operand + /// here. + VPUser PredicateUser; /// VPlan containing the block. Can only be set on the entry block of the /// plan. @@ -424,35 +426,18 @@ } /// \return the condition bit selecting the successor. - VPValue *getCondBit() { - if (CondBitUser.getNumOperands()) - return CondBitUser.getOperand(0); - return nullptr; - } - - const VPValue *getCondBit() const { - if (CondBitUser.getNumOperands()) - return CondBitUser.getOperand(0); - return nullptr; - } - - void setCondBit(VPValue *CV) { - if (!CV) { - if (CondBitUser.getNumOperands() == 1) - CondBitUser.removeLastOperand(); - return; - } - if (CondBitUser.getNumOperands() == 1) - CondBitUser.setOperand(0, CV); - else - CondBitUser.addOperand(CV); - } - - VPValue *getPredicate() { return Predicate; } - - const VPValue *getPredicate() const { return Predicate; } - - void setPredicate(VPValue *Pred) { Predicate = Pred; } + VPValue *getCondBit(); + /// \return the condition bit selecting the successor. + const VPValue *getCondBit() const; + /// Set the condition bit selecting the successor. + void setCondBit(VPValue *CV); + + /// \return the block's predicate. + VPValue *getPredicate(); + /// \return the block's predicate. + const VPValue *getPredicate() const; + /// Set the block's predicate. + void setPredicate(VPValue *Pred); /// Set a given VPBlockBase \p Successor as the single successor of this /// VPBlockBase. This VPBlockBase is not added as predecessor of \p Successor. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -171,6 +171,58 @@ return Parent->getEnclosingBlockWithPredecessors(); } +static VPValue *getSingleOperandOrNull(VPUser &U) { + if (U.getNumOperands() == 1) + return U.getOperand(0); + + return nullptr; +} + +static const VPValue *getSingleOperandOrNull(const VPUser &U) { + if (U.getNumOperands() == 1) + return U.getOperand(0); + + return nullptr; +} + +static void resetSingleOpUser(VPUser &U, VPValue *NewVal) { + assert(U.getNumOperands() <= 1 && "Didn't expect more than one operand!"); + if (!NewVal) { + if (U.getNumOperands() == 1) + U.removeLastOperand(); + return; + } + + if (U.getNumOperands() == 1) + U.setOperand(0, NewVal); + else + U.addOperand(NewVal); +} + +VPValue *VPBlockBase::getCondBit() { + return getSingleOperandOrNull(CondBitUser); +} + +const VPValue *VPBlockBase::getCondBit() const { + return getSingleOperandOrNull(CondBitUser); +} + +void VPBlockBase::setCondBit(VPValue *CV) { + resetSingleOpUser(CondBitUser, CV); +} + +VPValue *VPBlockBase::getPredicate() { + return getSingleOperandOrNull(PredicateUser); +} + +const VPValue *VPBlockBase::getPredicate() const { + return getSingleOperandOrNull(PredicateUser); +} + +void VPBlockBase::setPredicate(VPValue *CV) { + resetSingleOpUser(PredicateUser, CV); +} + void VPBlockBase::deleteCFG(VPBlockBase *Entry) { SmallVector Blocks(depth_first(Entry));