[llvm] [SLP] NFC: make candidate state ownership explicit (PR #229846)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 11 10:18:15 PDT 2026
================
@@ -3725,32 +3437,521 @@ class slpvectorizer::BoUpSLP {
/// SCEVs with \p Exp.
Value *emitRuntimeAliasCheck(IRBuilderBase &Builder, SCEVExpander &Exp);
- /// Data to model and emit the runtime alias checks.
- struct RuntimeAliasCheckInfo {
- /// The block whose body is guarded by the checks. Exactly one block is
- /// supported per attempt.
- BasicBlock *BB = nullptr;
- /// Pairs of base objects that must be proven disjoint.
- SmallSetVector<std::pair<const Value *, const Value *>, 4> BasePairs;
- /// Accessed address range [Low, High) for each involved base object.
- SmallMapVector<const Value *, std::pair<const SCEV *, const SCEV *>, 4>
- Bounds;
+#ifdef EXPENSIVE_CHECKS
+ /// Verify ownership of references into the current candidate at phase
+ /// boundaries, without dereferencing observer pointers.
+ void verifyCandidateOwnership() const;
+#endif
+
+ /// Owns the graph and the state discarded before building a new candidate.
+ /// Keep this object in place while its entries exist: TreeEntry::Container
+ /// refers to its graph.
+ /// Analysis caches, search history and reusable block scheduling storage
+ /// remain in BoUpSLP and survive a candidate reset.
+ class CandidateState {
+ friend class BoUpSLP;
+
+ CandidateState() = default;
+ CandidateState(const CandidateState &) = delete;
+ CandidateState &operator=(const CandidateState &) = delete;
+ CandidateState(CandidateState &&) = delete;
+ CandidateState &operator=(CandidateState &&) = delete;
+
+ private:
+ /// Holds all of the tree entries. Declared first so entries are destroyed
+ /// after the candidate state that refers to them.
+ TreeEntry::VecTreeTy VectorizableTree;
+
+ /// Maps a specific scalar to its tree entry(ies).
+ SmallDenseMap<Value *, SmallVector<TreeEntry *>> ScalarToTreeEntries;
+
+ /// List of deleted non-profitable nodes.
+ SmallPtrSet<const TreeEntry *, 8> DeletedNodes;
+
+ /// List of nodes, transformed to gathered, with their conservative
+ /// gather/buildvector cost estimation.
+ SmallDenseMap<const TreeEntry *, InstructionCost> TransformedToGatherNodes;
+
+ /// Maps the operand index and entry to the corresponding tree entry.
+ SmallDenseMap<std::pair<const TreeEntry *, unsigned>, TreeEntry *>
+ OperandsToTreeEntry;
+
+ /// Scalars, used in split vectorize nodes.
+ SmallDenseMap<Value *, SmallVector<TreeEntry *>> ScalarsInSplitNodes;
+
+ /// Maps a value to the proposed vectorizable size.
+ SmallDenseMap<Value *, unsigned> InstrElementSize;
+
+ /// A list of scalars that we found that we need to keep as scalars.
+ ValueSet MustGather;
+
+ /// Maps each peeled reassociated scalar to owning entries. Keeps them
+ /// treated as vectorized while an owner is live.
+ SmallDenseMap<const Value *, SmallVector<const TreeEntry *>>
+ ReassocScalarToTreeEntries;
+
+ /// Peeled reassociated scalars that must survive erasure: claimed by a
+ /// gather node, listed in some tree entry's scalars, or feeding another
+ /// kept scalar.
+ SmallPtrSet<const Value *, 8> KeptReassocScalars;
+
+ /// A set of first non-schedulable values.
+ ValueSet NonScheduledFirst;
+
+ /// A map between the vectorized entries and the last instructions in the
+ /// bundles. The bundles are built in use order, not in the def order of the
+ /// instructions. So, we cannot rely directly on the last instruction in the
+ /// bundle being the last instruction in the program order during
+ /// vectorization process since the basic blocks are affected, need to
+ /// pre-gather them before.
+ SmallDenseMap<const TreeEntry *, WeakTrackingVH> EntryToLastInstruction;
+
+ /// Keeps the mapping between the last instructions and their insertion
+ /// points, which is an instruction-after-the-last-instruction.
+ SmallDenseMap<const Instruction *, Instruction *> LastInstructionToPos;
+
+ /// List of gather nodes, depending on other gather/vector nodes, which
+ /// should be emitted after the vector instruction emission process to
+ /// correctly handle order of the vector instructions and shuffles.
+ SetVector<const TreeEntry *> PostponedGathers;
----------------
alexey-bataev wrote:
Same?
https://github.com/llvm/llvm-project/pull/229846
More information about the llvm-commits
mailing list