Skip to content

Commit cafb6b9

Browse files
authored
[SandboxVec][DAG] Update MemDGNode chain upon instr deletion (#118921)
1 parent a2fb705 commit cafb6b9

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,7 @@ class DependencyGraph {
342342
void notifyCreateInstr(Instruction *I);
343343
/// Called by the callbacks when instruction \p I is about to get
344344
/// deleted.
345-
void notifyEraseInstr(Instruction *I) {
346-
InstrToNodeMap.erase(I);
347-
// TODO: Update the dependencies.
348-
// TODO: Update the MemDGNode chain to remove the node if needed.
349-
}
345+
void notifyEraseInstr(Instruction *I);
350346

351347
public:
352348
/// This constructor also registers callbacks.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,22 @@ void DependencyGraph::notifyCreateInstr(Instruction *I) {
370370
}
371371
}
372372

373+
void DependencyGraph::notifyEraseInstr(Instruction *I) {
374+
// Update the MemDGNode chain if this is a memory node.
375+
if (auto *MemN = dyn_cast_or_null<MemDGNode>(getNodeOrNull(I))) {
376+
auto *PrevMemN = getMemDGNodeBefore(MemN, /*IncludingN=*/false);
377+
auto *NextMemN = getMemDGNodeAfter(MemN, /*IncludingN=*/false);
378+
if (PrevMemN != nullptr)
379+
PrevMemN->NextMemN = NextMemN;
380+
if (NextMemN != nullptr)
381+
NextMemN->PrevMemN = PrevMemN;
382+
}
383+
384+
InstrToNodeMap.erase(I);
385+
386+
// TODO: Update the dependencies.
387+
}
388+
373389
Interval<Instruction> DependencyGraph::extend(ArrayRef<Instruction *> Instrs) {
374390
if (Instrs.empty())
375391
return {};

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,16 @@ define void @foo(ptr %ptr, i8 %v1, i8 %v2, i8 %v3, i8 %arg) {
880880
S2->eraseFromParent();
881881
auto *DeletedN = DAG.getNodeOrNull(S2);
882882
EXPECT_TRUE(DeletedN == nullptr);
883+
884+
// Check the MemDGNode chain.
885+
auto *S1MemN = cast<sandboxir::MemDGNode>(DAG.getNode(S1));
886+
auto *S3MemN = cast<sandboxir::MemDGNode>(DAG.getNode(S3));
887+
EXPECT_EQ(S1MemN->getNextNode(), S3MemN);
888+
EXPECT_EQ(S3MemN->getPrevNode(), S1MemN);
889+
890+
// Check the chain when we erase the top node.
891+
S1->eraseFromParent();
892+
EXPECT_EQ(S3MemN->getPrevNode(), nullptr);
893+
883894
// TODO: Check the dependencies to/from NewSN after they land.
884-
// TODO: Check the MemDGNode chain.
885895
}

0 commit comments

Comments
 (0)