Skip to content

Commit 0c9f7ef

Browse files
authored
[SandboxVec][DAG] Implement extend(ArrayRef) (#109493)
This builds the DAG from an ArrayRef of Instructions.
1 parent c28e268 commit 0c9f7ef

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/ADT/DenseMap.h"
2626
#include "llvm/ADT/iterator_range.h"
2727
#include "llvm/SandboxIR/SandboxIR.h"
28+
#include "llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h"
2829

2930
namespace llvm::sandboxir {
3031

@@ -72,9 +73,9 @@ class DependencyGraph {
7273
It->second = std::make_unique<DGNode>(I);
7374
return It->second.get();
7475
}
75-
// TODO: extend() should work with intervals not the whole BB.
76-
/// Build the dependency graph for \p BB.
77-
void extend(BasicBlock *BB);
76+
/// Build/extend the dependency graph such that it includes \p Instrs. Returns
77+
/// the interval spanning \p Instrs.
78+
InstrInterval extend(ArrayRef<Instruction *> Instrs);
7879
#ifndef NDEBUG
7980
void print(raw_ostream &OS) const;
8081
LLVM_DUMP_METHOD void dump() const;

llvm/lib/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/Transforms/Vectorize/SandboxVectorizer/DependencyGraph.h"
10+
#include "llvm/ADT/ArrayRef.h"
1011

1112
using namespace llvm::sandboxir;
1213

@@ -30,16 +31,21 @@ void DGNode::dump() const {
3031
}
3132
#endif // NDEBUG
3233

33-
void DependencyGraph::extend(BasicBlock *BB) {
34-
if (BB->empty())
35-
return;
34+
InstrInterval DependencyGraph::extend(ArrayRef<Instruction *> Instrs) {
35+
if (Instrs.empty())
36+
return {};
3637
// TODO: For now create a chain of dependencies.
37-
DGNode *LastN = getOrCreateNode(&*BB->begin());
38-
for (auto &I : drop_begin(*BB)) {
39-
auto *N = getOrCreateNode(&I);
38+
InstrInterval Interval(Instrs);
39+
auto *TopI = Interval.top();
40+
auto *BotI = Interval.bottom();
41+
DGNode *LastN = getOrCreateNode(TopI);
42+
for (Instruction *I = TopI->getNextNode(), *E = BotI->getNextNode(); I != E;
43+
I = I->getNextNode()) {
44+
auto *N = getOrCreateNode(I);
4045
N->addMemPred(LastN);
4146
LastN = N;
4247
}
48+
return Interval;
4349
}
4450

4551
#ifndef NDEBUG

llvm/unittests/Transforms/Vectorize/SandboxVectorizer/DependencyGraphTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ define void @foo(ptr %ptr, i8 %v0, i8 %v1) {
4444
auto *S1 = cast<sandboxir::StoreInst>(&*It++);
4545
auto *Ret = cast<sandboxir::ReturnInst>(&*It++);
4646
sandboxir::DependencyGraph DAG;
47-
DAG.extend(BB);
47+
auto Span = DAG.extend({&*BB->begin(), BB->getTerminator()});
48+
// Check extend().
49+
EXPECT_EQ(Span.top(), &*BB->begin());
50+
EXPECT_EQ(Span.bottom(), BB->getTerminator());
4851

4952
sandboxir::DGNode *N0 = DAG.getNode(S0);
5053
sandboxir::DGNode *N1 = DAG.getNode(S1);

0 commit comments

Comments
 (0)