[PATCH] D156135: [ADT] Support iterating size-based integer ranges.

Ivan Kosarev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 26 08:28:59 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe9df4c98927e: [ADT] Support iterating size-based integer ranges. (authored by kosarev).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156135/new/

https://reviews.llvm.org/D156135

Files:
  llvm/include/llvm/ADT/Sequence.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/IR/Instructions.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
  llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
  llvm/unittests/ADT/SequenceTest.cpp


Index: llvm/unittests/ADT/SequenceTest.cpp
===================================================================
--- llvm/unittests/ADT/SequenceTest.cpp
+++ llvm/unittests/ADT/SequenceTest.cpp
@@ -182,6 +182,8 @@
 }
 
 TEST(SequenceTest, Iteration) {
+  EXPECT_THAT(seq(5), ElementsAre(0, 1, 2, 3, 4));
+
   EXPECT_THAT(seq(-4, 5), ElementsAre(-4, -3, -2, -1, 0, 1, 2, 3, 4));
   EXPECT_THAT(reverse(seq(-4, 5)), ElementsAre(4, 3, 2, 1, 0, -1, -2, -3, -4));
 
Index: llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceOperandBundles.cpp
@@ -55,7 +55,7 @@
     OperandBundlesToKeepIndexes.reserve(Call.getNumOperandBundles());
 
     // Enumerate every operand bundle on this call.
-    for (unsigned BundleIndex : seq(0U, Call.getNumOperandBundles()))
+    for (unsigned BundleIndex : seq(Call.getNumOperandBundles()))
       if (O.shouldKeep()) // Should we keep this one?
         OperandBundlesToKeepIndexes.emplace_back(BundleIndex);
   }
Index: llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
+++ llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
@@ -106,7 +106,7 @@
         for (const auto &LiveIn : Entry.MBB->liveins())
           Loop.MBB->addLiveIn(LiveIn);
       }
-      for (auto _ : seq(0U, LoopUnrollFactor)) {
+      for (auto _ : seq(LoopUnrollFactor)) {
         (void)_;
         Loop.addInstructions(Instructions);
       }
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1303,7 +1303,7 @@
   }
   for (const std::pair<BasicBlock *, int /*Num*/> &NewSuccessor :
        NewSuccessors) {
-    for (auto I : seq(0, NewSuccessor.second)) {
+    for (auto I : seq(NewSuccessor.second)) {
       (void)I;
       AddPredecessorToBlock(NewSuccessor.first, Pred, BB);
     }
Index: llvm/lib/IR/Instructions.cpp
===================================================================
--- llvm/lib/IR/Instructions.cpp
+++ llvm/lib/IR/Instructions.cpp
@@ -2607,7 +2607,7 @@
   assert(Mask.size() == (unsigned)ReplicationFactor * VF &&
          "Unexpected mask size.");
 
-  for (int CurrElt : seq(0, VF)) {
+  for (int CurrElt : seq(VF)) {
     ArrayRef<int> CurrSubMask = Mask.take_front(ReplicationFactor);
     assert(CurrSubMask.size() == (unsigned)ReplicationFactor &&
            "Run out of mask?");
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -652,7 +652,7 @@
     if (LNumOps != RNumOps)
       return (int)LNumOps - (int)RNumOps;
 
-    for (unsigned Idx : seq(0u, LNumOps)) {
+    for (unsigned Idx : seq(LNumOps)) {
       int Result =
           CompareValueComplexity(EqCacheValue, LI, LInst->getOperand(Idx),
                                  RInst->getOperand(Idx), Depth + 1);
Index: llvm/include/llvm/ADT/Sequence.h
===================================================================
--- llvm/include/llvm/ADT/Sequence.h
+++ llvm/include/llvm/ADT/Sequence.h
@@ -306,6 +306,16 @@
   return iota_range<T>(Begin, End, false);
 }
 
+/// Iterate over an integral type from 0 up to - but not including - Size.
+/// Note: Size value has to be within [INTMAX_MIN, INTMAX_MAX - 1] for
+/// forward iteration (resp. [INTMAX_MIN + 1, INTMAX_MAX - 1] for reverse
+/// iteration).
+template <typename T, typename = std::enable_if_t<std::is_integral<T>::value &&
+                                                  !std::is_enum<T>::value>>
+auto seq(T Size) {
+  return seq<T>(0, Size);
+}
+
 /// Iterate over an integral type from Begin to End inclusive.
 /// Note: Begin and End values have to be within [INTMAX_MIN, INTMAX_MAX - 1]
 /// for forward iteration (resp. [INTMAX_MIN + 1, INTMAX_MAX - 1] for reverse


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156135.544383.patch
Type: text/x-patch
Size: 4141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230726/ec817af5/attachment.bin>


More information about the llvm-commits mailing list