LLVM 23.0.0git
VPRecipeBuilder.h
Go to the documentation of this file.
1//===- VPRecipeBuilder.h - Helper class to build recipes --------*- C++ -*-===//
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#ifndef LLVM_TRANSFORMS_VECTORIZE_VPRECIPEBUILDER_H
10#define LLVM_TRANSFORMS_VECTORIZE_VPRECIPEBUILDER_H
11
13#include "VPlan.h"
14#include "llvm/ADT/DenseMap.h"
16
17namespace llvm {
18
22struct HistogramInfo;
23struct VFRange;
24
25/// Helper class to create VPRecipies from IR instructions.
27 /// The VPlan new recipes are added to.
28 VPlan &Plan;
29
30 /// Target Library Info.
31 const TargetLibraryInfo *TLI;
32
33 /// The legality analysis.
35
36 /// The profitablity analysis.
38
39 VPBuilder &Builder;
40
41 // VPlan construction support: Hold a mapping from ingredients to
42 // their recipe.
44
45 /// Cross-iteration reduction & first-order recurrence phis for which we need
46 /// to add the incoming value from the backedge after all recipes have been
47 /// created.
49
50 /// Check if \p I can be widened at the start of \p Range and possibly
51 /// decrease the range such that the returned value holds for the entire \p
52 /// Range. The function should not be called for memory instructions or calls.
53 bool shouldWiden(Instruction *I, VFRange &Range) const;
54
55 /// Optimize the special case where the operand of \p VPI is a constant
56 /// integer induction variable.
58 tryToOptimizeInductionTruncate(VPInstruction *VPI, VFRange &Range);
59
60 /// Handle call instructions. If \p VPI can be widened for \p Range.Start,
61 /// return a new VPWidenCallRecipe or VPWidenIntrinsicRecipe. Range.End may be
62 /// decreased to ensure same decision from \p Range.Start to \p Range.End.
63 VPSingleDefRecipe *tryToWidenCall(VPInstruction *VPI, VFRange &Range);
64
65 /// Check if \p VPI has an opcode that can be widened and return a
66 /// VPWidenRecipe if it can. The function should only be called if the
67 /// cost-model indicates that widening should be performed.
68 VPWidenRecipe *tryToWiden(VPInstruction *VPI);
69
70public:
74 : Plan(Plan), TLI(TLI), Legal(Legal), CM(CM), Builder(Builder) {}
75
76 /// Create and return a widened recipe for a non-phi recipe \p R if one can be
77 /// created within the given VF \p Range.
79 VFRange &Range);
80
81 /// Check if the load or store instruction \p VPI should widened for \p
82 /// Range.Start and potentially masked. Such instructions are handled by a
83 /// recipe that takes an additional VPInstruction for the mask.
85
86 /// If \p VPI represents a histogram operation (as determined by
87 /// LoopVectorizationLegality) make that safe for vectorization, by emitting a
88 /// llvm.experimental.vector.histogram.add intrinsic in place of the Load +
89 /// Add|Sub + Store operations that perform the histogram in the original
90 /// scalar loop.
92
93 /// If \p VPI is a store of a reduction into an invariant address, delete it.
94 /// If it is the final store of a reduction result, a uniform store recipe
95 /// will be created for it in the middle block. Returns `true` if replacement
96 /// took place. The order of stores must be preserved, hence \p
97 /// FinalRedStoresBuidler.
99 VPBuilder &FinalRedStoresBuilder);
100
101 /// Set the recipe created for given ingredient.
103 assert(!Ingredient2Recipe.contains(I) &&
104 "Cannot reset recipe for instruction.");
105 Ingredient2Recipe[I] = R;
106 }
107
108 /// Return the recipe created for given ingredient.
110 assert(Ingredient2Recipe.count(I) &&
111 "Recording this ingredients recipe was not requested");
112 assert(Ingredient2Recipe[I] != nullptr &&
113 "Ingredient doesn't have a recipe");
114 return Ingredient2Recipe[I];
115 }
116
117 /// Build a VPReplicationRecipe for \p VPI. If it is predicated, add the mask
118 /// as last operand. Range.End may be decreased to ensure same recipe behavior
119 /// from \p Range.Start to \p Range.End.
121
123 if (auto *I = dyn_cast<Instruction>(V)) {
124 if (auto *R = Ingredient2Recipe.lookup(I))
125 return R->getVPSingleValue();
126 }
127 return Plan.getOrAddLiveIn(V);
128 }
129};
130} // end namespace llvm
131
132#endif // LLVM_TRANSFORMS_VECTORIZE_VPRECIPEBUILDER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
This file provides a LoopVectorizationPlanner class.
#define I(x, y, z)
Definition MD5.cpp:57
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains the declarations of the Vectorization Plan base classes:
LoopVectorizationCostModel - estimates the expected speedups due to vectorization.
LoopVectorizationLegality checks if it is legal to vectorize a loop, and to what vectorization factor...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
VPlan-based builder utility analogous to IRBuilder.
A recipe representing a sequence of load -> update -> store as part of a histogram operation.
Definition VPlan.h:2045
This is a concrete Recipe that models a single VPlan-level instruction.
Definition VPlan.h:1223
VPRecipeBase is a base class modeling a sequence of one or more output IR instructions.
Definition VPlan.h:406
VPRecipeBase * tryToCreateWidenNonPhiRecipe(VPSingleDefRecipe *R, VFRange &Range)
Create and return a widened recipe for a non-phi recipe R if one can be created within the given VF R...
VPHistogramRecipe * widenIfHistogram(VPInstruction *VPI)
If VPI represents a histogram operation (as determined by LoopVectorizationLegality) make that safe f...
VPValue * getVPValueOrAddLiveIn(Value *V)
VPRecipeBuilder(VPlan &Plan, const TargetLibraryInfo *TLI, LoopVectorizationLegality *Legal, LoopVectorizationCostModel &CM, VPBuilder &Builder)
void setRecipe(Instruction *I, VPRecipeBase *R)
Set the recipe created for given ingredient.
VPRecipeBase * tryToWidenMemory(VPInstruction *VPI, VFRange &Range)
Check if the load or store instruction VPI should widened for Range.Start and potentially masked.
bool replaceWithFinalIfReductionStore(VPInstruction *VPI, VPBuilder &FinalRedStoresBuilder)
If VPI is a store of a reduction into an invariant address, delete it.
VPReplicateRecipe * handleReplication(VPInstruction *VPI, VFRange &Range)
Build a VPReplicationRecipe for VPI.
VPRecipeBase * getRecipe(Instruction *I)
Return the recipe created for given ingredient.
VPReplicateRecipe replicates a given instruction producing multiple scalar copies of the original sca...
Definition VPlan.h:3196
VPSingleDef is a base class for recipes for modeling a sequence of one or more output IR that define ...
Definition VPlan.h:606
This is the base class of the VPlan Def/Use graph, used for modeling the data flow into,...
Definition VPlanValue.h:49
A recipe for handling phi nodes of integer and floating-point inductions, producing their vector valu...
Definition VPlan.h:2448
VPWidenRecipe is a recipe for producing a widened instruction using the opcode and operands of the re...
Definition VPlan.h:1781
VPlan models a candidate for vectorization, encoding various decisions take to produce efficient outp...
Definition VPlan.h:4518
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
This holds details about a histogram operation – a load -> update -> store sequence where each lane i...
A range of powers-of-2 vectorization factors with fixed start and adjustable end.