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

Ivan Kosarev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 08:23:28 PDT 2023


kosarev created this revision.
kosarev added reviewers: chandlerc, dblaikie, gchatelet, aaron.ballman.
Herald added a subscriber: hiraditya.
Herald added a project: All.
kosarev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

It seems the ranges start with 0 in most cases.


Repository:
  rG LLVM Github Monorepo

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


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.543567.patch
Type: text/x-patch
Size: 3683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230724/1f936039/attachment.bin>


More information about the llvm-commits mailing list