Skip to content

Commit 04fb697

Browse files
Quentin Colombetqcolombet
Quentin Colombet
authored andcommitted
[GraphScheduler] Honor memory dependencies implied by the SaveNode
When a variable is used as output in a save node, this is expected to be its last use. Make sure the GraphSchedule looks at the implicit dependencies between all the uses of a variable and its save node when walking the dependencies. This fixes issue #1283.
1 parent 96abe10 commit 04fb697

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/IR/GraphScheduler.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ class ChildMemSizeBasedScheduler : public Scheduler {
140140
orderedChildren.push_back(N->getPredicate());
141141
}
142142

143+
// SaveNode hack:
144+
// We don't model memory dependencies, but we still need to honor them.
145+
// Make sure the SaveNode happens after the last use of the output variable.
146+
if (auto *save = dyn_cast<SaveNode>(N)) {
147+
Variable *output = save->getVariable();
148+
for (NodeUse &use : output->getUsers()) {
149+
Node *user = use.getUser();
150+
if (user == save) {
151+
continue;
152+
}
153+
// Variables may have users scattered across different functions.
154+
// Only accounts for the ones in that function.
155+
if (&G_ != user->getParent()) {
156+
continue;
157+
}
158+
assert(!isa<SaveNode>(user) &&
159+
"Variables must be saved at most once in each function");
160+
orderedChildren.push_back(user);
161+
}
162+
}
163+
143164
// Order children by (maxSize - resultSize). It gives more
144165
// priority to the nodes that free more memory after
145166
// their computation.

tests/unittests/graphTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ TEST(Graph, schedulingOfSaves) {
546546
}
547547
}
548548
EXPECT_TRUE(A->getPayload().isEqual(zero->getPayload(), 0.0));
549-
// FIXME: This should be true, but right now it is not!
550-
EXPECT_FALSE /*TRUE*/ (allEqual);
549+
EXPECT_TRUE(allEqual);
551550
}
552551

553552
/// Check that the parent link is properly updated while tweaking

0 commit comments

Comments
 (0)