[llvm] abc2412 - [SandboxVec][InstrInterval] Add ArrayRef constructor (#109357)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 20 16:17:13 PDT 2024


Author: vporpo
Date: 2024-09-20T16:17:09-07:00
New Revision: abc2412f077546066289d0e34c3b499d54337446

URL: https://github.com/llvm/llvm-project/commit/abc2412f077546066289d0e34c3b499d54337446
DIFF: https://github.com/llvm/llvm-project/commit/abc2412f077546066289d0e34c3b499d54337446.diff

LOG: [SandboxVec][InstrInterval] Add ArrayRef constructor (#109357)

The new constructor creates an InstrInterval from an
ArrayRef<Instruction *>. This patch also adds top() and bottom()
getters.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h
    llvm/unittests/Transforms/Vectorize/SandboxVectorizer/InstrIntervalTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/InstrInterval.h
index dcf9ca00ba11ac..1343f521b29bb4 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;
+      else 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