[VPlan] Add support for tracking UFs applicable to VPlan (NFC).
authorFlorian Hahn <flo@fhahn.com>
Thu, 22 Dec 2022 18:58:22 +0000 (18:58 +0000)
committerFlorian Hahn <flo@fhahn.com>
Thu, 22 Dec 2022 18:58:25 +0000 (18:58 +0000)
Explicitly track the UFs supported in a VPlan. This is needed to
allow transformations to restrict the UFs which are supported.

Discussed as separate improvement in D135017.

llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

index a425504ddf54a59e4c2631f4bd3c986ad89ff5dd..827f440bf78633c1cda6ea947eab316de172ca2b 100644 (file)
@@ -792,12 +792,21 @@ void VPlan::print(raw_ostream &O) const {
 std::string VPlan::getName() const {
   std::string Out;
   raw_string_ostream RSO(Out);
-  RSO << Name;
+  RSO << Name << " for ";
   if (!VFs.empty()) {
-    RSO << " for VF={" << VFs[0];
+    RSO << "VF={" << VFs[0];
     for (ElementCount VF : drop_begin(VFs))
       RSO << "," << VF;
-    RSO << "},UF>=1";
+    RSO << "},";
+  }
+
+  if (UFs.empty()) {
+    RSO << "UF>=1";
+  } else {
+    RSO << "UF={" << UFs[0];
+    for (unsigned UF : drop_begin(UFs))
+      RSO << "," << UF;
+    RSO << "}";
   }
 
   return Out;
index f76931e675bf582c07ea92117bdb517234decbe9..6bc7f26253e68a8812e0a35ce523e9a796e54903 100644 (file)
@@ -2498,6 +2498,10 @@ class VPlan {
   /// Holds the VFs applicable to this VPlan.
   SmallSetVector<ElementCount, 2> VFs;
 
+  /// Holds the UFs applicable to this VPlan. If empty, the VPlan is valid for
+  /// any UF.
+  SmallSetVector<unsigned, 2> UFs;
+
   /// Holds the name of the VPlan, for printing.
   std::string Name;
 
@@ -2601,6 +2605,14 @@ public:
 
   bool hasScalarVFOnly() const { return VFs.size() == 1 && VFs[0].isScalar(); }
 
+  bool hasUF(unsigned UF) const { return UFs.empty() || UFs.contains(UF); }
+
+  void setUF(unsigned UF) {
+    assert(hasUF(UF) && "Cannot set the UF not already in plan");
+    UFs.clear();
+    UFs.insert(UF);
+  }
+
   /// Return a string with the name of the plan and the applicable VFs and UFs.
   std::string getName() const;
 
index 408b847d4d9befd650965e6a7e072f1dd5fc2f14..65d6b7695e92655a084913d926046327ed21cd53 100644 (file)
@@ -101,7 +101,7 @@ TEST_F(VPlanHCFGTest, testBuildHCFGInnerLoop) {
   raw_string_ostream OS(FullDump);
   Plan->printDOT(OS);
   const char *ExpectedStr = R"(digraph VPlan {
-graph [labelloc=t, fontsize=30; label="Vectorization Plan"]
+graph [labelloc=t, fontsize=30; label="Vectorization Plan\n for UF\>=1"]
 node [shape=rect, fontname=Courier, fontsize=30]
 edge [fontname=Courier, fontsize=30]
 compound=true
index 23ac6600c768c0e9bd81fbb3b2ef95bbb5f9a17d..3f3f2af42d893817b717372e1da79e4e8f81de94 100644 (file)
@@ -703,7 +703,7 @@ TEST(VPBasicBlockTest, print) {
   Plan.printDOT(OS);
 
   const char *ExpectedStr = R"(digraph VPlan {
-graph [labelloc=t, fontsize=30; label="Vectorization Plan"]
+graph [labelloc=t, fontsize=30; label="Vectorization Plan\n for UF\>=1"]
 node [shape=rect, fontname=Courier, fontsize=30]
 edge [fontname=Courier, fontsize=30]
 compound=true
@@ -802,6 +802,21 @@ bb1:
   EMIT vp<%1> = add
 No successors
 }
+)";
+    EXPECT_EQ(ExpectedStr, FullDump);
+  }
+
+  {
+    Plan.setUF(4);
+    std::string FullDump;
+    raw_string_ostream OS(FullDump);
+    Plan.print(OS);
+
+    const char *ExpectedStr = R"(VPlan 'TestPlan for VF={4,vscale x 8},UF={4}' {
+bb1:
+  EMIT vp<%1> = add
+No successors
+}
 )";
     EXPECT_EQ(ExpectedStr, FullDump);
   }