Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ template <typename T> class Interval {
}
/// Inequality.
bool operator!=(const Interval &Other) const { return !(*this == Other); }
/// \Returns true if this interval comes before \p Other in program order.
/// This expects disjoint intervals.
bool comesBefore(const Interval &Other) const {
assert(disjoint(Other) && "Expect disjoint intervals!");
return bottom()->comesBefore(Other.top());
}
/// \Returns true if this and \p Other have nothing in common.
bool disjoint(const Interval &Other) const {
if (Other.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ void DependencyGraph::createNewNodes(const Interval<Instruction> &NewInterval) {
}
// Link new MemDGNode chain with the old one, if any.
if (!DAGInterval.empty()) {
// TODO: Implement Interval::comesBefore() to replace this check.
bool NewIsAbove = NewInterval.bottom()->comesBefore(DAGInterval.top());
assert(
(NewIsAbove || DAGInterval.bottom()->comesBefore(NewInterval.top())) &&
"Expected NewInterval below DAGInterval.");
bool NewIsAbove = NewInterval.comesBefore(DAGInterval);
const auto &TopInterval = NewIsAbove ? NewInterval : DAGInterval;
const auto &BotInterval = NewIsAbove ? DAGInterval : NewInterval;
MemDGNode *LinkTopN =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ define void @foo(i8 %v0) {
EXPECT_FALSE(Intvl1.disjoint(Intvl3));
EXPECT_TRUE(Intvl1.disjoint(Empty));
}
{
// Check comesBefore().
sandboxir::Interval<sandboxir::Instruction> Intvl1(I0, I0);
sandboxir::Interval<sandboxir::Instruction> Intvl2(I2, I2);
EXPECT_TRUE(Intvl1.comesBefore(Intvl2));
EXPECT_FALSE(Intvl2.comesBefore(Intvl1));

sandboxir::Interval<sandboxir::Instruction> Intvl12(I1, I2);
EXPECT_TRUE(Intvl1.comesBefore(Intvl12));
EXPECT_FALSE(Intvl12.comesBefore(Intvl1));
{
#ifndef NDEBUG
// Check comesBefore() with non-disjoint intervals.
sandboxir::Interval<sandboxir::Instruction> Intvl1(I0, I2);
sandboxir::Interval<sandboxir::Instruction> Intvl2(I2, I2);
EXPECT_DEATH(Intvl1.comesBefore(Intvl2), ".*disjoint.*");
#endif // NDEBUG
}
}
}

// Helper function for returning a vector of instruction pointers from a range
Expand Down
Loading