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

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 08:24:14 PDT 2021


fhahn updated this revision to Diff 338880.
fhahn added a comment.

Add comment about the `Other` ID type, making clear that currently there are VPUsers in VPBlockBase, but in the future Other should only be used for live-outs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100257/new/

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,22 @@
 /// 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,
+    // TODO: Currently VPUsers are used in VPBlockBase, but in the future the
+    // only VPUsers should either be recipes or live-outs.
+    Other
+  };
+
+  VPUserID ID;
+
+  VPUserID getVPUserID() const { return ID; }
+
 protected:
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
   /// Print the operands to \p O.
@@ -200,15 +214,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 +278,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
@@ -620,18 +620,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.
@@ -683,6 +683,10 @@
     return true;
   }
 
+  static inline bool classof(const VPUser *U) {
+    return U->getVPUserID() == VPUser::VPUserID::Recipe;
+  }
+
   /// Returns true if the recipe may have side-effects.
   bool mayHaveSideEffects() const;
 };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100257.338880.patch
Type: text/x-patch
Size: 3234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210420/8837cb7b/attachment.bin>


More information about the llvm-commits mailing list