[llvm] 0c9f7ef - [SandboxVec][DAG] Implement extend(ArrayRef) (#109493)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 19:09:04 PDT 2024


Author: vporpo
Date: 2024-09-20T19:09:00-07:00
New Revision: 0c9f7ef52739b28f42c03c2bd1c87b744b687e6f

URL: https://github.com/llvm/llvm-project/commit/0c9f7ef52739b28f42c03c2bd1c87b744b687e6f
DIFF: https://github.com/llvm/llvm-project/commit/0c9f7ef52739b28f42c03c2bd1c87b744b687e6f.diff

LOG: [SandboxVec][DAG] Implement extend(ArrayRef) (#109493)

This builds the DAG from an ArrayRef of Instructions.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
    llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
    llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
index 8a2021a5e6ba60..3aa44781a2dd5c 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h
@@ -25,6 +25,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/SandboxIR/SandboxIR.h"
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h"
 
 namespace llvm::sandboxir {
 
@@ -72,9 +73,9 @@ class DependencyGraph {
       It->second = std::make_unique<DGNode>(I);
     return It->second.get();
   }
-  // TODO: extend() should work with intervals not the whole BB.
-  /// Build the dependency graph for \p BB.
-  void extend(BasicBlock *BB);
+  /// Build/extend the dependency graph such that it includes \p Instrs. Returns
+  /// the interval spanning \p Instrs.
+  InstrInterval extend(ArrayRef<Instruction *> Instrs);
 #ifndef NDEBUG
   void print(raw_ostream &OS) const;
   LLVM_DUMP_METHOD void dump() const;

diff  --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
index 41e50953a4ec8a..139e581ce03d96 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h"
+#include "llvm/ADT/ArrayRef.h"
 
 using namespace llvm::sandboxir;
 
@@ -30,16 +31,21 @@ void DGNode::dump() const {
 }
 #endif // NDEBUG
 
-void DependencyGraph::extend(BasicBlock *BB) {
-  if (BB->empty())
-    return;
+InstrInterval DependencyGraph::extend(ArrayRef<Instruction *> Instrs) {
+  if (Instrs.empty())
+    return {};
   // TODO: For now create a chain of dependencies.
-  DGNode *LastN = getOrCreateNode(&*BB->begin());
-  for (auto &I : drop_begin(*BB)) {
-    auto *N = getOrCreateNode(&I);
+  InstrInterval Interval(Instrs);
+  auto *TopI = Interval.top();
+  auto *BotI = Interval.bottom();
+  DGNode *LastN = getOrCreateNode(TopI);
+  for (Instruction *I = TopI->getNextNode(), *E = BotI->getNextNode(); I != E;
+       I = I->getNextNode()) {
+    auto *N = getOrCreateNode(I);
     N->addMemPred(LastN);
     LastN = N;
   }
+  return Interval;
 }
 
 #ifndef NDEBUG

diff  --git a/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp b/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp
index dc85a22f7f4832..c62b2a4e508c06 100644
--- a/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp
@@ -44,7 +44,10 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
   auto *S1 = cast<sandboxir::StoreInst>(&*It++);
   auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
   sandboxir::DependencyGraph DAG;
-  DAG.extend(BB);
+  auto Span = DAG.extend({&*BB->begin(), BB->getTerminator()});
+  // Check extend().
+  EXPECT_EQ(Span.top(), &*BB->begin());
+  EXPECT_EQ(Span.bottom(), BB->getTerminator());
 
   sandboxir::DGNode *N0 = DAG.getNode(S0);
   sandboxir::DGNode *N1 = DAG.getNode(S1);


        


More information about the llvm-commits mailing list