[PATCH] D157442: [VPlan] Move mask handling to VPRecipeBase (NFCI).
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 14:40:11 PDT 2023
fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin.
Herald added subscribers: StephenFan, tschuett, rogfer01, psnobl, bollu, hiraditya.
Herald added a project: All.
fhahn requested review of this revision.
Herald added subscribers: wangpc, vkmr.
Herald added a project: LLVM.
Consolidate mask handling to VPRecipeBase, buy letting subclasses define
the number of non-mask operations, if it is different than the total
number of operands.
This removes a bit of duplication, allows for generic printing of the
mask and potentially allows masking of any recipe (e.g. to use
vector predication).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157442
Files:
llvm/lib/Transforms/Vectorize/VPlan.h
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -792,6 +792,20 @@
bool mayReadOrWriteMemory() const {
return mayReadFromMemory() || mayWriteToMemory();
}
+
+ /// Returns the number of operands excluding mask operands, which must be the
+ /// last operand. Must be overwritten by sub-classes with mask operands.
+ virtual unsigned getNumNonMaskOperands() const { return getNumOperands(); }
+
+ /// Returns true if the recipe is masked.
+ bool isMasked() const { return getNumOperands() != getNumNonMaskOperands(); }
+
+ /// Return the mask used by this recipe. Note that a full mask is represented
+ /// by a nullptr.
+ VPValue *getMask() const {
+ // Mask is optional and therefore the last operand.
+ return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
+ }
};
// Helper macro to define common classof implementations for recipes.
@@ -1681,13 +1695,6 @@
return getOperand(0); // Address is the 1st, mandatory operand.
}
- /// Return the mask used by this recipe. Note that a full mask is represented
- /// by a nullptr.
- VPValue *getMask() const {
- // Mask is optional and therefore the last, currently 2nd operand.
- return HasMask ? getOperand(getNumOperands() - 1) : nullptr;
- }
-
/// Return the VPValues stored by this interleave group. If it is a load
/// interleave group, return an empty ArrayRef.
ArrayRef<VPValue *> getStoredValues() const {
@@ -1720,6 +1727,11 @@
"Op must be an operand of the recipe");
return Op == getAddr() && !llvm::is_contained(getStoredValues(), Op);
}
+
+ /// Returns the number of operands excluding mask operands.
+ unsigned getNumNonMaskOperands() const override {
+ return HasMask ? getNumOperands() - 1 : getNumOperands();
+ }
};
/// A recipe to represent inloop reduction operations, performing a reduction on
@@ -1823,10 +1835,9 @@
/// in a vector.
bool shouldPack() const;
- /// Return the mask of a predicated VPReplicateRecipe.
- VPValue *getMask() {
- assert(isPredicated() && "Trying to get the mask of a unpredicated recipe");
- return getOperand(getNumOperands() - 1);
+ /// Returns the number of operands excluding mask operands.
+ unsigned getNumNonMaskOperands() const override {
+ return isPredicated() ? getNumOperands() - 1 : getNumOperands();
}
};
@@ -1926,10 +1937,6 @@
addOperand(Mask);
}
- bool isMasked() const {
- return isStore() ? getNumOperands() == 3 : getNumOperands() == 2;
- }
-
public:
VPWidenMemoryInstructionRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask,
bool Consecutive, bool Reverse)
@@ -1956,13 +1963,6 @@
return getOperand(0); // Address is the 1st, mandatory operand.
}
- /// Return the mask used by this recipe. Note that a full mask is represented
- /// by a nullptr.
- VPValue *getMask() const {
- // Mask is optional and therefore the last operand.
- return isMasked() ? getOperand(getNumOperands() - 1) : nullptr;
- }
-
/// Returns true if this recipe is a store.
bool isStore() const { return isa<StoreInst>(Ingredient); }
@@ -2001,6 +2001,9 @@
}
Instruction &getIngredient() const { return Ingredient; }
+
+ /// Returns the number of operands excluding mask operands.
+ unsigned getNumNonMaskOperands() const override { return isStore() ? 2 : 1; }
};
/// Recipe to expand a SCEV expression.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157442.548360.patch
Type: text/x-patch
Size: 3558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230808/17c41234/attachment.bin>
More information about the llvm-commits
mailing list