LLVM 21.0.0git
VPlanSLP.h
Go to the documentation of this file.
1//===- VPlan.h - VPlan-based SLP ------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file contains the declarations for VPlan-based SLP.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANSLP_H
15#define LLVM_TRANSFORMS_VECTORIZE_VPLANSLP_H
16
17#include "llvm/ADT/DenseMap.h"
21
22namespace llvm {
23
24class VPBasicBlock;
25class VPBlockBase;
26class VPRegionBlock;
27class VPlan;
28class VPValue;
29class VPInstruction;
30
33 InterleaveGroupMap;
34
35 /// Type for mapping of instruction based interleave groups to VPInstruction
36 /// interleave groups
39
40 /// Recursively \p Region and populate VPlan based interleave groups based on
41 /// \p IAI.
42 void visitRegion(VPRegionBlock *Region, Old2NewTy &Old2New,
44 /// Recursively traverse \p Block and populate VPlan based interleave groups
45 /// based on \p IAI.
46 void visitBlock(VPBlockBase *Block, Old2NewTy &Old2New,
48
49public:
51
54 // Avoid releasing a pointer twice.
55 for (auto &I : InterleaveGroupMap)
56 DelSet.insert(I.second);
57 for (auto *Ptr : DelSet)
58 delete Ptr;
59 }
60
61 /// Get the interleave group that \p Instr belongs to.
62 ///
63 /// \returns nullptr if doesn't have such group.
66 return InterleaveGroupMap.lookup(Instr);
67 }
68};
69
70/// Class that maps (parts of) an existing VPlan to trees of combined
71/// VPInstructions.
72class VPlanSlp {
73 enum class OpMode { Failed, Load, Opcode };
74
75 /// A DenseMapInfo implementation for using SmallVector<VPValue *, 4> as
76 /// DenseMap keys.
77 struct BundleDenseMapInfo {
78 static SmallVector<VPValue *, 4> getEmptyKey() {
79 return {reinterpret_cast<VPValue *>(-1)};
80 }
81
82 static SmallVector<VPValue *, 4> getTombstoneKey() {
83 return {reinterpret_cast<VPValue *>(-2)};
84 }
85
86 static unsigned getHashValue(const SmallVector<VPValue *, 4> &V) {
87 return static_cast<unsigned>(hash_combine_range(V.begin(), V.end()));
88 }
89
90 static bool isEqual(const SmallVector<VPValue *, 4> &LHS,
92 return LHS == RHS;
93 }
94 };
95
96 /// Mapping of values in the original VPlan to a combined VPInstruction.
98 BundleToCombined;
99
101
102 /// Basic block to operate on. For now, only instructions in a single BB are
103 /// considered.
104 const VPBasicBlock &BB;
105
106 /// Indicates whether we managed to combine all visited instructions or not.
107 bool CompletelySLP = true;
108
109 /// Width of the widest combined bundle in bits.
110 unsigned WidestBundleBits = 0;
111
112 using MultiNodeOpTy =
113 typename std::pair<VPInstruction *, SmallVector<VPValue *, 4>>;
114
115 // Input operand bundles for the current multi node. Each multi node operand
116 // bundle contains values not matching the multi node's opcode. They will
117 // be reordered in reorderMultiNodeOps, once we completed building a
118 // multi node.
120
121 /// Indicates whether we are building a multi node currently.
122 bool MultiNodeActive = false;
123
124 /// Check if we can vectorize Operands together.
125 bool areVectorizable(ArrayRef<VPValue *> Operands) const;
126
127 /// Add combined instruction \p New for the bundle \p Operands.
128 void addCombined(ArrayRef<VPValue *> Operands, VPInstruction *New);
129
130 /// Indicate we hit a bundle we failed to combine. Returns nullptr for now.
131 VPInstruction *markFailed();
132
133 /// Reorder operands in the multi node to maximize sequential memory access
134 /// and commutative operations.
135 SmallVector<MultiNodeOpTy, 4> reorderMultiNodeOps();
136
137 /// Choose the best candidate to use for the lane after \p Last. The set of
138 /// candidates to choose from are values with an opcode matching \p Last's
139 /// or loads consecutive to \p Last.
140 std::pair<OpMode, VPValue *> getBest(OpMode Mode, VPValue *Last,
141 SmallPtrSetImpl<VPValue *> &Candidates,
143
144#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
145 /// Print bundle \p Values to dbgs().
146 void dumpBundle(ArrayRef<VPValue *> Values);
147#endif
148
149public:
150 VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB) : IAI(IAI), BB(BB) {}
151
152 ~VPlanSlp() = default;
153
154 /// Tries to build an SLP tree rooted at \p Operands and returns a
155 /// VPInstruction combining \p Operands, if they can be combined.
157
158 /// Return the width of the widest combined bundle in bits.
159 unsigned getWidestBundleBits() const { return WidestBundleBits; }
160
161 /// Return true if all visited instruction can be combined.
162 bool isCompletelySLP() const { return CompletelySLP; }
163};
164} // end namespace llvm
165
166#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
This file defines the DenseMap class.
#define I(x, y, z)
Definition: MD5.cpp:58
mir Rename Register Operands
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Value * RHS
Value * LHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:194
The group of interleaved loads/stores sharing the same stride and close to each other.
Definition: VectorUtils.h:488
Drive the analysis of interleaved memory accesses in the loop.
Definition: VectorUtils.h:630
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:363
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:384
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:519
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:3200
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:78
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:845
InterleaveGroup< VPInstruction > * getInterleaveGroup(VPInstruction *Instr) const
Get the interleave group that Instr belongs to.
Definition: VPlanSLP.h:65
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:3377
Class that maps (parts of) an existing VPlan to trees of combined VPInstructions.
Definition: VPlanSLP.h:72
VPInstruction * buildGraph(ArrayRef< VPValue * > Operands)
Tries to build an SLP tree rooted at Operands and returns a VPInstruction combining Operands,...
Definition: VPlanSLP.cpp:413
bool isCompletelySLP() const
Return true if all visited instruction can be combined.
Definition: VPlanSLP.h:162
~VPlanSlp()=default
VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB)
Definition: VPlanSLP.h:150
unsigned getWidestBundleBits() const
Return the width of the widest combined bundle in bits.
Definition: VPlanSLP.h:159
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3476
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition: Error.h:198
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:468