[PATCH] D100257: [VPlan] Add VPUserID to distinguish between recipes and others.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 11 04:11:43 PDT 2021


fhahn created this revision.
fhahn added reviewers: Ayal, gilr, rengolin, a.elovikov.
Herald added subscribers: tschuett, psnobl, rogfer01, bollu, hiraditya.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.

This allows cast/dyn_cast'ing from VPUser to recipes. This is needed
because there are VPUsers that are not recipes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100257

Files:
  llvm/lib/Transforms/Vectorize/VPlan.h
  llvm/lib/Transforms/Vectorize/VPlanValue.h


Index: llvm/lib/Transforms/Vectorize/VPlanValue.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -191,8 +191,17 @@
 /// This class augments VPValue with operands which provide the inverse def-use
 /// edges from VPValue's users to their defs.
 class VPUser {
+  friend class VPRecipeBase;
+
   SmallVector<VPValue *, 2> Operands;
 
+  /// Subclass identifier (for isa/dyn_cast).
+  enum class VPUserID { Recipe, Other };
+
+  VPUserID ID;
+
+  VPUserID getVPUserID() const { return ID; }
+
 protected:
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   /// Print the operands to \p O.
@@ -200,15 +209,19 @@
 #endif
 
 public:
-  VPUser() {}
-  VPUser(ArrayRef<VPValue *> Operands) {
+  VPUser() : ID(VPUserID::Recipe) {}
+  VPUser(ArrayRef<VPValue *> Operands, VPUserID ID = VPUserID::Other) : ID(ID) {
     for (VPValue *Operand : Operands)
       addOperand(Operand);
   }
 
-  VPUser(std::initializer_list<VPValue *> Operands)
-      : VPUser(ArrayRef<VPValue *>(Operands)) {}
-  template <typename IterT> VPUser(iterator_range<IterT> Operands) {
+  VPUser(std::initializer_list<VPValue *> Operands,
+         VPUserID ID = VPUserID::Other)
+      : VPUser(ArrayRef<VPValue *>(Operands), ID) {}
+
+  template <typename IterT>
+  VPUser(iterator_range<IterT> Operands, VPUserID ID = VPUserID::Other)
+      : ID(ID) {
     for (VPValue *Operand : Operands)
       addOperand(Operand);
   }
@@ -260,6 +273,8 @@
   static inline bool classof(const VPDef *Recipe);
 };
 
+static_assert(sizeof(VPUser) <= 48, "size of VPUser changed");
+
 /// This class augments a recipe with a set of VPValues defined by the recipe.
 /// It allows recipes to define zero, one or multiple VPValues. A VPDef owns
 /// the VPValues it defines and is responsible for deleting its defined values.
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -619,18 +619,18 @@
                      public VPUser {
   friend VPBasicBlock;
   friend class VPBlockUtils;
-
+  friend class VPUser;
 
   /// Each VPRecipe belongs to a single VPBasicBlock.
   VPBasicBlock *Parent = nullptr;
 
 public:
   VPRecipeBase(const unsigned char SC, ArrayRef<VPValue *> Operands)
-      : VPDef(SC), VPUser(Operands) {}
+      : VPDef(SC), VPUser(Operands, VPUser::VPUserID::Recipe) {}
 
   template <typename IterT>
   VPRecipeBase(const unsigned char SC, iterator_range<IterT> Operands)
-      : VPDef(SC), VPUser(Operands) {}
+      : VPDef(SC), VPUser(Operands, VPUser::VPUserID::Recipe) {}
   virtual ~VPRecipeBase() = default;
 
   /// \return the VPBasicBlock which this VPRecipe belongs to.
@@ -681,6 +681,9 @@
     // All VPDefs are also VPRecipeBases.
     return true;
   }
+  static inline bool classof(const VPUser *U) {
+    return U->getVPUserID() == VPUser::VPUserID::Recipe;
+  }
 };
 
 inline bool VPUser::classof(const VPDef *Def) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100257.336653.patch
Type: text/x-patch
Size: 3078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210411/5cee94c6/attachment.bin>


More information about the llvm-commits mailing list