[llvm] [SandboxVectorizer] Define SeedBundle: a set of instructions to be vectorized (PR #110696)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 10:28:47 PDT 2024


================
@@ -0,0 +1,63 @@
+//===- SeedCollection.cpp  -0000000----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Vectorize/SandboxVectorizer/SeedCollector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Analysis/LoopAccessAnalysis.h"
+#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Type.h"
+#include "llvm/SandboxIR/Instruction.h"
+#include "llvm/SandboxIR/Utils.h"
+#include "llvm/Support/Debug.h"
+#include <span>
+
+using namespace llvm;
+
+MutableArrayRef<sandboxir::SeedBundle::SeedList>
+sandboxir::SeedBundle::getSlice(unsigned StartIdx, unsigned MaxVecRegBits,
+                                bool ForcePowerOf2, const DataLayout &DL) {
+  // Use uint32_t for counts to make it clear we are also using the proper
+  // isPowerOf2_[32|64].
+
+  // Count both the bits and the elements of the slice we are about to build.
+  // The bits tell us whether this is a legal slice (that is <= MaxVecRegBits),
+  // and the num of elements help us do the actual slicing.
+  uint32_t BitsSum = 0;
+  // As we are collecting slice elements we may go over the limit, so we need to
+  // remember the last legal one. This is used for the creation of the slice.
+  uint32_t LastGoodBitsSum = 0;
+  uint32_t LastGoodNumSliceElements = 0;
+  // Skip any used elements (which have already been handled) and all below
+  // `StartIdx`.
+  assert(StartIdx >= getFirstUnusedElementIdx() &&
+         "Expected unused at StartIdx");
+  uint32_t FirstGoodElementIdx = StartIdx;
+  // Go through elements starting at FirstGoodElementIdx.
+  for (auto [ElementCnt, S] : enumerate(make_range(
+           std::next(Seeds.begin(), FirstGoodElementIdx), Seeds.end()))) {
----------------
vporpo wrote:

nit: I would prefer to use `Seeds.begin() + FirstGoodElementIdx` here to make sure that it is a random access iterator that actually implements a constant time advancement operator, and is not doing a linear time `operator++` FirstGoodElementIdx times.

https://github.com/llvm/llvm-project/pull/110696


More information about the llvm-commits mailing list