@@ -68,15 +68,10 @@ class VPRecipeBuilder {
68
68
69
69
VPBuilder &Builder;
70
70
71
- // / When we if-convert we need to create edge masks. We have to cache values
72
- // / so that we don't end up with exponential recursion/IR. Note that
73
- // / if-conversion currently takes place during VPlan-construction, so these
74
- // / caches are only used at that stage.
75
- using EdgeMaskCacheTy =
76
- DenseMap<std::pair<BasicBlock *, BasicBlock *>, VPValue *>;
77
- using BlockMaskCacheTy = DenseMap<BasicBlock *, VPValue *>;
78
- EdgeMaskCacheTy EdgeMaskCache;
79
- BlockMaskCacheTy BlockMaskCache;
71
+ // / The mask of each VPBB, generated earlier and used for predicating recipes
72
+ // / in VPBB.
73
+ // / TODO: remove by applying predication when generating the masks.
74
+ DenseMap<VPBasicBlock *, VPValue *> &BlockMaskCache;
80
75
81
76
// VPlan construction support: Hold a mapping from ingredients to
82
77
// their recipe.
@@ -90,10 +85,6 @@ class VPRecipeBuilder {
90
85
// / A mapping of partial reduction exit instructions to their scaling factor.
91
86
DenseMap<const Instruction *, unsigned > ScaledReductionMap;
92
87
93
- // / A mapping from VP blocks to IR blocks, used temporarily while migrating
94
- // / away from IR references.
95
- const DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB;
96
-
97
88
// / Loop versioning instance for getting noalias metadata guaranteed by
98
89
// / runtime checks.
99
90
LoopVersioning *LVer;
@@ -122,11 +113,6 @@ class VPRecipeBuilder {
122
113
tryToOptimizeInductionTruncate (TruncInst *I, ArrayRef<VPValue *> Operands,
123
114
VFRange &Range);
124
115
125
- // / Handle non-loop phi nodes, returning a new VPBlendRecipe. Currently
126
- // / all such phi nodes are turned into a sequence of select instructions as
127
- // / the vectorizer currently performs full if-conversion.
128
- VPBlendRecipe *tryToBlend (VPWidenPHIRecipe *PhiR);
129
-
130
116
// / Handle call instructions. If \p CI can be widened for \p Range.Start,
131
117
// / return a new VPWidenCallRecipe or VPWidenIntrinsicRecipe. Range.End may be
132
118
// / decreased to ensure same decision from \p Range.Start to \p Range.End.
@@ -164,10 +150,11 @@ class VPRecipeBuilder {
164
150
LoopVectorizationLegality *Legal,
165
151
LoopVectorizationCostModel &CM,
166
152
PredicatedScalarEvolution &PSE, VPBuilder &Builder,
167
- const DenseMap<const VPBlockBase *, BasicBlock *> &VPB2IRBB ,
153
+ DenseMap<VPBasicBlock *, VPValue *> &BlockMaskCache ,
168
154
LoopVersioning *LVer)
169
155
: Plan(Plan), OrigLoop(OrigLoop), TLI(TLI), TTI(TTI), Legal(Legal),
170
- CM (CM), PSE(PSE), Builder(Builder), VPB2IRBB(VPB2IRBB), LVer(LVer) {}
156
+ CM (CM), PSE(PSE), Builder(Builder), BlockMaskCache(BlockMaskCache),
157
+ LVer(LVer) {}
171
158
172
159
std::optional<unsigned > getScalingForReduction (const Instruction *ExitInst) {
173
160
auto It = ScaledReductionMap.find (ExitInst);
@@ -196,38 +183,11 @@ class VPRecipeBuilder {
196
183
Ingredient2Recipe[I] = R;
197
184
}
198
185
199
- // / Create the mask for the vector loop header block.
200
- void createHeaderMask ();
201
-
202
- // / A helper function that computes the predicate of the block BB, assuming
203
- // / that the header block of the loop is set to True or the loop mask when
204
- // / tail folding.
205
- void createBlockInMask (const VPBasicBlock *VPBB) {
206
- return createBlockInMask (VPB2IRBB.lookup (VPBB));
186
+ // / Returns the *entry* mask for block \p VPBB or null if the mask is
187
+ // / all-true.
188
+ VPValue *getBlockInMask (VPBasicBlock *VPBB) const {
189
+ return BlockMaskCache.lookup (VPBB);
207
190
}
208
- void createBlockInMask (BasicBlock *BB);
209
-
210
- // / Returns the *entry* mask for the block \p VPBB.
211
- VPValue *getBlockInMask (const VPBasicBlock *VPBB) const {
212
- return getBlockInMask (VPB2IRBB.lookup (VPBB));
213
- }
214
-
215
- // / Returns the *entry* mask for the block \p BB.
216
- VPValue *getBlockInMask (BasicBlock *BB) const ;
217
-
218
- // / Create an edge mask for every destination of cases and/or default.
219
- void createSwitchEdgeMasks (SwitchInst *SI);
220
-
221
- // / A helper function that computes the predicate of the edge between SRC
222
- // / and DST.
223
- VPValue *createEdgeMask (BasicBlock *Src, BasicBlock *Dst);
224
-
225
- // / A helper that returns the previously computed predicate of the edge
226
- // / between SRC and DST.
227
- VPValue *getEdgeMask (const VPBasicBlock *Src, const VPBasicBlock *Dst) const {
228
- return getEdgeMask (VPB2IRBB.lookup (Src), VPB2IRBB.lookup (Dst));
229
- }
230
- VPValue *getEdgeMask (BasicBlock *Src, BasicBlock *Dst) const ;
231
191
232
192
// / Return the recipe created for given ingredient.
233
193
VPRecipeBase *getRecipe (Instruction *I) {
@@ -252,6 +212,15 @@ class VPRecipeBuilder {
252
212
}
253
213
return Plan.getOrAddLiveIn (V);
254
214
}
215
+
216
+ void updateBlockMaskCache (DenseMap<VPValue *, VPValue *> &Old2New) {
217
+ for (auto &[_, V] : BlockMaskCache) {
218
+ if (auto *New = Old2New.lookup (V)) {
219
+ V->replaceAllUsesWith (New);
220
+ V = New;
221
+ }
222
+ }
223
+ }
255
224
};
256
225
} // end namespace llvm
257
226
0 commit comments