Skip to content

Commit abc2412

Browse files
author
vporpo
authored
[SandboxVec][InstrInterval] Add ArrayRef constructor (#109357)
The new constructor creates an InstrInterval from an ArrayRef<Instruction *>. This patch also adds top() and bottom() getters.
1 parent c0b1c62 commit abc2412

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ class InstrInterval {
8080
assert((FromI == ToI || FromI->comesBefore(ToI)) &&
8181
"FromI should come before TopI!");
8282
}
83+
InstrInterval(ArrayRef<Instruction *> Instrs) {
84+
assert(!Instrs.empty() && "Expected non-empty Instrs!");
85+
FromI = Instrs[0];
86+
ToI = Instrs[0];
87+
for (auto *I : drop_begin(Instrs)) {
88+
if (I->comesBefore(FromI))
89+
FromI = I;
90+
else if (ToI->comesBefore(I))
91+
ToI = I;
92+
}
93+
}
8394
bool empty() const {
8495
assert(((FromI == nullptr && ToI == nullptr) ||
8596
(FromI != nullptr && ToI != nullptr)) &&
@@ -92,6 +103,8 @@ class InstrInterval {
92103
return (FromI == I || FromI->comesBefore(I)) &&
93104
(I == ToI || I->comesBefore(ToI));
94105
}
106+
Instruction *top() const { return FromI; }
107+
Instruction *bottom() const { return ToI; }
95108

96109
using iterator =
97110
InstrIntervalIterator<sandboxir::Instruction &, InstrInterval>;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ define void @foo(i8 %v0) {
5050
#ifndef NDEBUG
5151
EXPECT_DEATH(sandboxir::InstrInterval(I1, I0), ".*before.*");
5252
#endif // NDEBUG
53+
// Check InstrInterval(ArrayRef), from(), to().
54+
{
55+
sandboxir::InstrInterval Interval(
56+
SmallVector<sandboxir::Instruction *>({I0, Ret}));
57+
EXPECT_EQ(Interval.top(), I0);
58+
EXPECT_EQ(Interval.bottom(), Ret);
59+
}
60+
{
61+
sandboxir::InstrInterval Interval(
62+
SmallVector<sandboxir::Instruction *>({Ret, I0}));
63+
EXPECT_EQ(Interval.top(), I0);
64+
EXPECT_EQ(Interval.bottom(), Ret);
65+
}
66+
{
67+
sandboxir::InstrInterval Interval(
68+
SmallVector<sandboxir::Instruction *>({I0, I0}));
69+
EXPECT_EQ(Interval.top(), I0);
70+
EXPECT_EQ(Interval.bottom(), I0);
71+
}
72+
5373
// Check empty().
5474
EXPECT_FALSE(Interval.empty());
5575
sandboxir::InstrInterval Empty;

0 commit comments

Comments
 (0)