xref: /freebsd/contrib/llvm-project/llvm/lib/Transforms/Vectorize/VPlanAnalysis.h (revision a0ca4af9455b844c5e094fc1b09b1390ffa979fc)
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 
14 namespace llvm {
15 
16 class LLVMContext;
17 class VPValue;
18 class VPBlendRecipe;
19 class VPInstruction;
20 class VPWidenRecipe;
21 class VPWidenCallRecipe;
22 class VPWidenIntOrFpInductionRecipe;
23 class VPWidenMemoryInstructionRecipe;
24 struct VPWidenSelectRecipe;
25 class VPReplicateRecipe;
26 class Type;
27 
28 /// An analysis for type-inference for VPValues.
29 /// It infers the scalar type for a given VPValue by bottom-up traversing
30 /// through defining recipes until root nodes with known types are reached (e.g.
31 /// live-ins or load recipes). The types are then propagated top down through
32 /// operations.
33 /// Note that the analysis caches the inferred types. A new analysis object must
34 /// be constructed once a VPlan has been modified in a way that invalidates any
35 /// of the previously inferred types.
36 class VPTypeAnalysis {
37   DenseMap<const VPValue *, Type *> CachedTypes;
38   LLVMContext &Ctx;
39 
40   Type *inferScalarTypeForRecipe(const VPBlendRecipe *R);
41   Type *inferScalarTypeForRecipe(const VPInstruction *R);
42   Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R);
43   Type *inferScalarTypeForRecipe(const VPWidenRecipe *R);
44   Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R);
45   Type *inferScalarTypeForRecipe(const VPWidenMemoryInstructionRecipe *R);
46   Type *inferScalarTypeForRecipe(const VPWidenSelectRecipe *R);
47   Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);
48 
49 public:
50   VPTypeAnalysis(LLVMContext &Ctx) : Ctx(Ctx) {}
51 
52   /// Infer the type of \p V. Returns the scalar type of \p V.
53   Type *inferScalarType(const VPValue *V);
54 
55   /// Return the LLVMContext used by the analysis.
56   LLVMContext &getContext() { return Ctx; }
57 };
58 
59 } // end namespace llvm
60 
61 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
62