[llvm] 3605b87 - [NFC][VPlan] Use VPUser to store block's predicate
Andrei Elovikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 23 11:09:01 PST 2021
Author: Andrei Elovikov
Date: 2021-02-23T11:08:27-08:00
New Revision: 3605b873f6f0df36037f418974433e2c759e978b
URL: https://github.com/llvm/llvm-project/commit/3605b873f6f0df36037f418974433e2c759e978b
DIFF: https://github.com/llvm/llvm-project/commit/3605b873f6f0df36037f418974433e2c759e978b.diff
LOG: [NFC][VPlan] Use VPUser to store block's predicate
Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D96529
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index d7fcba41cf35..fcb964efb973 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -171,6 +171,58 @@ VPBlockBase *VPBlockBase::getEnclosingBlockWithPredecessors() {
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<VPBlockBase *, 8> Blocks(depth_first(Entry));
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 3a2bd49f2044..c92c4ef82ae7 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -277,8 +277,10 @@ class VPBlockBase {
/// 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 @@ class VPBlockBase {
}
/// \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.
More information about the llvm-commits
mailing list