xref: /llvm-project/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h (revision b29c5b66fd1b241b6d8a9cd810cd4e9bad318225)
1 //===- VPlanAnalysis.h - Various Analyses working on VPlan ------*- 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_VPLANANALYSIS_H
10 #define LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
11 
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/IR/Type.h"
15 
16 namespace llvm {
17 
18 class LLVMContext;
19 class VPValue;
20 class VPBlendRecipe;
21 class VPInstruction;
22 class VPWidenRecipe;
23 class VPWidenCallRecipe;
24 class VPWidenIntOrFpInductionRecipe;
25 class VPWidenMemoryRecipe;
26 struct VPWidenSelectRecipe;
27 class VPReplicateRecipe;
28 class VPRecipeBase;
29 class VPlan;
30 class Type;
31 
32 /// An analysis for type-inference for VPValues.
33 /// It infers the scalar type for a given VPValue by bottom-up traversing
34 /// through defining recipes until root nodes with known types are reached (e.g.
35 /// live-ins or load recipes). The types are then propagated top down through
36 /// operations.
37 /// Note that the analysis caches the inferred types. A new analysis object must
38 /// be constructed once a VPlan has been modified in a way that invalidates any
39 /// of the previously inferred types.
40 class VPTypeAnalysis {
41   DenseMap<const VPValue *, Type *> CachedTypes;
42   /// Type of the canonical induction variable. Used for all VPValues without
43   /// any underlying IR value (like the vector trip count or the backedge-taken
44   /// count).
45   Type *CanonicalIVTy;
46   LLVMContext &Ctx;
47 
48   Type *inferScalarTypeForRecipe(const VPBlendRecipe *R);
49   Type *inferScalarTypeForRecipe(const VPInstruction *R);
50   Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R);
51   Type *inferScalarTypeForRecipe(const VPWidenRecipe *R);
52   Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R);
53   Type *inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R);
54   Type *inferScalarTypeForRecipe(const VPWidenSelectRecipe *R);
55   Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);
56 
57 public:
58   VPTypeAnalysis(Type *CanonicalIVTy)
59       : CanonicalIVTy(CanonicalIVTy), Ctx(CanonicalIVTy->getContext()) {}
60 
61   /// Infer the type of \p V. Returns the scalar type of \p V.
62   Type *inferScalarType(const VPValue *V);
63 
64   /// Return the LLVMContext used by the analysis.
65   LLVMContext &getContext() { return Ctx; }
66 };
67 
68 // Collect a VPlan's ephemeral recipes (those used only by an assume).
69 void collectEphemeralRecipesForVPlan(VPlan &Plan,
70                                      DenseSet<VPRecipeBase *> &EphRecipes);
71 } // end namespace llvm
72 
73 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
74