LLVM 22.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:
54
56 // Avoid releasing a pointer twice.
58 llvm::from_range, llvm::make_second_range(InterleaveGroupMap));
59 for (auto *Ptr : DelSet)
60 delete Ptr;
61 }
62
63 /// Get the interleave group that \p Instr belongs to.
64 ///
65 /// \returns nullptr if doesn't have such group.
68 return InterleaveGroupMap.lookup(Instr);
69 }
70};
71
72/// Class that maps (parts of) an existing VPlan to trees of combined
73/// VPInstructions.
74class VPlanSlp {
75 enum class OpMode { Failed, Load, Opcode };
76
77 /// Mapping of values in the original VPlan to a combined VPInstruction.
79
81
82 /// Basic block to operate on. For now, only instructions in a single BB are
83 /// considered.
84 const VPBasicBlock &BB;
85
86 /// Indicates whether we managed to combine all visited instructions or not.
87 bool CompletelySLP = true;
88
89 /// Width of the widest combined bundle in bits.
90 unsigned WidestBundleBits = 0;
91
92 using MultiNodeOpTy =
93 typename std::pair<VPInstruction *, SmallVector<VPValue *, 4>>;
94
95 // Input operand bundles for the current multi node. Each multi node operand
96 // bundle contains values not matching the multi node's opcode. They will
97 // be reordered in reorderMultiNodeOps, once we completed building a
98 // multi node.
100
101 /// Indicates whether we are building a multi node currently.
102 bool MultiNodeActive = false;
103
104 /// Check if we can vectorize Operands together.
105 bool areVectorizable(ArrayRef<VPValue *> Operands) const;
106
107 /// Add combined instruction \p New for the bundle \p Operands.
108 void addCombined(ArrayRef<VPValue *> Operands, VPInstruction *New);
109
110 /// Indicate we hit a bundle we failed to combine. Returns nullptr for now.
111 VPInstruction *markFailed();
112
113 /// Reorder operands in the multi node to maximize sequential memory access
114 /// and commutative operations.
115 SmallVector<MultiNodeOpTy, 4> reorderMultiNodeOps();
116
117 /// Choose the best candidate to use for the lane after \p Last. The set of
118 /// candidates to choose from are values with an opcode matching \p Last's
119 /// or loads consecutive to \p Last.
120 std::pair<OpMode, VPValue *> getBest(OpMode Mode, VPValue *Last,
121 SmallPtrSetImpl<VPValue *> &Candidates,
123
124#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
125 /// Print bundle \p Values to dbgs().
126 void dumpBundle(ArrayRef<VPValue *> Values);
127#endif
128
129public:
130 VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB) : IAI(IAI), BB(BB) {}
131
132 ~VPlanSlp() = default;
133
134 /// Tries to build an SLP tree rooted at \p Operands and returns a
135 /// VPInstruction combining \p Operands, if they can be combined.
137
138 /// Return the width of the widest combined bundle in bits.
139 unsigned getWidestBundleBits() const { return WidestBundleBits; }
140
141 /// Return true if all visited instruction can be combined.
142 bool isCompletelySLP() const { return CompletelySLP; }
143};
144} // end namespace llvm
145
146#endif // LLVM_TRANSFORMS_VECTORIZE_VPLAN_H
#define LLVM_ABI_FOR_TEST
Definition: Compiler.h:218
This file defines the DenseMap class.
mir Rename Register Operands
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
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:203
The group of interleaved loads/stores sharing the same stride and close to each other.
Definition: VectorUtils.h:524
Drive the analysis of interleaved memory accesses in the loop.
Definition: VectorUtils.h:669
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:380
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:541
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:3639
VPBlockBase is the building block of the Hierarchical Control-Flow Graph.
Definition: VPlan.h:81
This is a concrete Recipe that models a single VPlan-level instruction.
Definition: VPlan.h:967
VPInterleavedAccessInfo(const VPInterleavedAccessInfo &)=delete
InterleaveGroup< VPInstruction > * getInterleaveGroup(VPInstruction *Instr) const
Get the interleave group that Instr belongs to.
Definition: VPlanSLP.h:67
VPInterleavedAccessInfo & operator=(const VPInterleavedAccessInfo &)=delete
VPRegionBlock represents a collection of VPBasicBlocks and VPRegionBlocks which form a Single-Entry-S...
Definition: VPlan.h:3827
Class that maps (parts of) an existing VPlan to trees of combined VPInstructions.
Definition: VPlanSLP.h:74
LLVM_ABI_FOR_TEST VPInstruction * buildGraph(ArrayRef< VPValue * > Operands)
Tries to build an SLP tree rooted at Operands and returns a VPInstruction combining Operands,...
Definition: VPlanSLP.cpp:415
bool isCompletelySLP() const
Return true if all visited instruction can be combined.
Definition: VPlanSLP.h:142
~VPlanSlp()=default
VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB)
Definition: VPlanSLP.h:130
unsigned getWidestBundleBits() const
Return the width of the widest combined bundle in bits.
Definition: VPlanSLP.h:139
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition: VPlan.h:3930
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
testing::Matcher< const detail::ErrorHolder & > Failed()
Definition: Error.h:198
constexpr from_range_t from_range
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
Definition: STLExtras.h:1454