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
14namespace llvm {
15
16class LLVMContext;
17class VPValue;
18class VPBlendRecipe;
19class VPInstruction;
20class VPWidenRecipe;
21class VPWidenCallRecipe;
22class VPWidenIntOrFpInductionRecipe;
23class VPWidenMemoryRecipe;
24struct VPWidenSelectRecipe;
25class VPReplicateRecipe;
26class 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.
36class VPTypeAnalysis {
37 DenseMap<const VPValue *, Type *> CachedTypes;
38 /// Type of the canonical induction variable. Used for all VPValues without
39 /// any underlying IR value (like the vector trip count or the backedge-taken
40 /// count).
41 Type *CanonicalIVTy;
42 LLVMContext &Ctx;
43
44 Type *inferScalarTypeForRecipe(const VPBlendRecipe *R);
45 Type *inferScalarTypeForRecipe(const VPInstruction *R);
46 Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R);
47 Type *inferScalarTypeForRecipe(const VPWidenRecipe *R);
48 Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R);
49 Type *inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R);
50 Type *inferScalarTypeForRecipe(const VPWidenSelectRecipe *R);
51 Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R);
52
53public:
54 VPTypeAnalysis(Type *CanonicalIVTy, LLVMContext &Ctx)
55 : CanonicalIVTy(CanonicalIVTy), Ctx(Ctx) {}
56
57 /// Infer the type of \p V. Returns the scalar type of \p V.
58 Type *inferScalarType(const VPValue *V);
59
60 /// Return the LLVMContext used by the analysis.
61 LLVMContext &getContext() { return Ctx; }
62};
63
64} // end namespace llvm
65
66#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
67

source code of llvm/lib/Transforms/Vectorize/VPlanAnalysis.h