[llvm] [SandboxVec][InstrInterval] Add ArrayRef constructor (PR #109357)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 18:50:25 PDT 2024
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/109357
The new constructor creates an InstrInterval from an ArrayRef<Instruction *>. This patch also adds top() and bottom() getters.
>From e25d136c7899b2c844142f316791f10181853552 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Wed, 18 Sep 2024 10:00:42 -0700
Subject: [PATCH] [SandboxVec][InstrInterval] Add ArrayRef constructor
The new constructor creates an InstrInterval from an ArrayRef<Instruction *>.
This patch also adds top() and bottom() getters.
---
.../SandboxVectorizer/InstrInterval.h | 13 ++++++++++++
.../SandboxVectorizer/InstrIntervalTest.cpp | 20 +++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h
index dcf9ca00ba11ac..d9ad3874ef6e33 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h
@@ -80,6 +80,17 @@ class InstrInterval {
assert((FromI == ToI || FromI->comesBefore(ToI)) &&
"FromI should come before TopI!");
}
+ InstrInterval(ArrayRef<Instruction *> Instrs) {
+ assert(!Instrs.empty() && "Expected non-empty Instrs!");
+ FromI = Instrs[0];
+ ToI = Instrs[0];
+ for (auto *I : drop_begin(Instrs)) {
+ if (I->comesBefore(FromI))
+ FromI = I;
+ if (ToI->comesBefore(I))
+ ToI = I;
+ }
+ }
bool empty() const {
assert(((FromI == nullptr && ToI == nullptr) ||
(FromI != nullptr && ToI != nullptr)) &&
@@ -92,6 +103,8 @@ class InstrInterval {
return (FromI == I || FromI->comesBefore(I)) &&
(I == ToI || I->comesBefore(ToI));
}
+ Instruction *top() const { return FromI; }
+ Instruction *bottom() const { return ToI; }
using iterator =
InstrIntervalIterator<sandboxir::Instruction &, InstrInterval>;
diff --git a/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/InstrIntervalTest.cpp b/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/InstrIntervalTest.cpp
index 9553158150525b..e22bb78a07d300 100644
--- a/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/InstrIntervalTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/SandboxVectorizer/InstrIntervalTest.cpp
@@ -50,6 +50,26 @@ define void @foo(i8 %v0) {
#ifndef NDEBUG
EXPECT_DEATH(sandboxir::InstrInterval(I1, I0), ".*before.*");
#endif // NDEBUG
+ // Check InstrInterval(ArrayRef), from(), to().
+ {
+ sandboxir::InstrInterval Interval(
+ SmallVector<sandboxir::Instruction *>({I0, Ret}));
+ EXPECT_EQ(Interval.top(), I0);
+ EXPECT_EQ(Interval.bottom(), Ret);
+ }
+ {
+ sandboxir::InstrInterval Interval(
+ SmallVector<sandboxir::Instruction *>({Ret, I0}));
+ EXPECT_EQ(Interval.top(), I0);
+ EXPECT_EQ(Interval.bottom(), Ret);
+ }
+ {
+ sandboxir::InstrInterval Interval(
+ SmallVector<sandboxir::Instruction *>({I0, I0}));
+ EXPECT_EQ(Interval.top(), I0);
+ EXPECT_EQ(Interval.bottom(), I0);
+ }
+
// Check empty().
EXPECT_FALSE(Interval.empty());
sandboxir::InstrInterval Empty;
More information about the llvm-commits
mailing list