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