[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:45 PDT 2024
================
@@ -0,0 +1,136 @@
+//===- SeedCollector.h ------------------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+// This file contains the mechanism for collecting the seed instructions that
+// are used as starting points for forming the vectorization graph.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SEEDCOLLECTOR_H
+#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_SEEDCOLLECTOR_H
+
+#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Analysis/ScalarEvolution.h"
+#include "llvm/SandboxIR/Instruction.h"
+#include "llvm/SandboxIR/Utils.h"
+#include "llvm/SandboxIR/Value.h"
+#include <iterator>
+#include <memory>
+
+namespace llvm::sandboxir {
+class Instruction;
+class StoreInst;
+class BasicBlock;
+
+/// An ordered set of Instructions that can be vectorized.
+class SeedBundle {
+public:
+ using SeedList = SmallVector<sandboxir::Instruction *>;
+ /// Initialize a bundle with \p I.
+ explicit SeedBundle(sandboxir::Instruction *I, const DataLayout &DL) {
+ insertAt(begin(), I, DL);
+ }
+ explicit SeedBundle(SeedList &&L, const DataLayout &DL)
+ : Seeds(std::move(L)) {
+ for (auto &S : Seeds) {
+ NumUnusedBits += sandboxir::Utils::getNumBits(S, DL);
+ }
+ }
+ /// No need to allow copies.
+ SeedBundle(const SeedBundle &) = delete;
+ SeedBundle &operator=(const SeedBundle &) = delete;
+ virtual ~SeedBundle() {}
+
+ using iterator = SeedList::iterator;
+ using const_iterator = SeedList::const_iterator;
+ iterator begin() { return Seeds.begin(); }
+ iterator end() { return Seeds.end(); }
+ const_iterator begin() const { return Seeds.begin(); }
+ const_iterator end() const { return Seeds.end(); }
+
+ sandboxir::Instruction *operator[](unsigned Idx) const { return Seeds[Idx]; }
+
+ /// Insert \p I into position \p P. Clients should choose Pos
+ /// by symbol, symbol-offset, and program order (which depends if scheduling
+ /// bottom-up or top-down).
+ void insertAt(iterator Pos, sandboxir::Instruction *I, const DataLayout &DL) {
+#ifdef EXPENSIVE_CHECKS
+ for (auto Itr : Seeds) {
+ assert(*Itr != I && "Attempt to insert an instruction twice.");
+ }
+#endif
+ Seeds.insert(Pos, I);
+ NumUnusedBits += sandboxir::Utils::getNumBits(I, DL);
+ }
+
+ unsigned getFirstUnusedElementIdx() const {
+ for (unsigned ElmIdx : seq<unsigned>(0, Seeds.size()))
----------------
vporpo wrote:
nit: `for (auto ElmIdx` since `unsigned` is used in `seq<unsigned>`
https://github.com/llvm/llvm-project/pull/110696
More information about the llvm-commits
mailing list