1b0b88643SFlorian Hahn //===- VPlanAnalysis.h - Various Analyses working on VPlan ------*- C++ -*-===// 2b0b88643SFlorian Hahn // 3b0b88643SFlorian Hahn // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b0b88643SFlorian Hahn // See https://llvm.org/LICENSE.txt for license information. 5b0b88643SFlorian Hahn // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b0b88643SFlorian Hahn // 7b0b88643SFlorian Hahn //===----------------------------------------------------------------------===// 8b0b88643SFlorian Hahn 9b0b88643SFlorian Hahn #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H 10b0b88643SFlorian Hahn #define LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H 11b0b88643SFlorian Hahn 12b0b88643SFlorian Hahn #include "llvm/ADT/DenseMap.h" 13ef89e3efSFlorian Hahn #include "llvm/ADT/DenseSet.h" 14*b29c5b66SDavid Sherwood #include "llvm/IR/Type.h" 15b0b88643SFlorian Hahn 16b0b88643SFlorian Hahn namespace llvm { 17b0b88643SFlorian Hahn 18b0b88643SFlorian Hahn class LLVMContext; 19b0b88643SFlorian Hahn class VPValue; 20b0b88643SFlorian Hahn class VPBlendRecipe; 21b0b88643SFlorian Hahn class VPInstruction; 22b0b88643SFlorian Hahn class VPWidenRecipe; 23b0b88643SFlorian Hahn class VPWidenCallRecipe; 24b0b88643SFlorian Hahn class VPWidenIntOrFpInductionRecipe; 25a9bafe91SFlorian Hahn class VPWidenMemoryRecipe; 26b0b88643SFlorian Hahn struct VPWidenSelectRecipe; 27b0b88643SFlorian Hahn class VPReplicateRecipe; 28ef89e3efSFlorian Hahn class VPRecipeBase; 29ef89e3efSFlorian Hahn class VPlan; 30b0b88643SFlorian Hahn class Type; 31b0b88643SFlorian Hahn 32b0b88643SFlorian Hahn /// An analysis for type-inference for VPValues. 33b0b88643SFlorian Hahn /// It infers the scalar type for a given VPValue by bottom-up traversing 34b0b88643SFlorian Hahn /// through defining recipes until root nodes with known types are reached (e.g. 35b0b88643SFlorian Hahn /// live-ins or load recipes). The types are then propagated top down through 36b0b88643SFlorian Hahn /// operations. 37b0b88643SFlorian Hahn /// Note that the analysis caches the inferred types. A new analysis object must 38b0b88643SFlorian Hahn /// be constructed once a VPlan has been modified in a way that invalidates any 39b0b88643SFlorian Hahn /// of the previously inferred types. 40b0b88643SFlorian Hahn class VPTypeAnalysis { 41b0b88643SFlorian Hahn DenseMap<const VPValue *, Type *> CachedTypes; 423d66d693SFlorian Hahn /// Type of the canonical induction variable. Used for all VPValues without 433d66d693SFlorian Hahn /// any underlying IR value (like the vector trip count or the backedge-taken 443d66d693SFlorian Hahn /// count). 453d66d693SFlorian Hahn Type *CanonicalIVTy; 46b0b88643SFlorian Hahn LLVMContext &Ctx; 47b0b88643SFlorian Hahn 48b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPBlendRecipe *R); 49b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPInstruction *R); 50b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R); 51b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPWidenRecipe *R); 52b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R); 53a9bafe91SFlorian Hahn Type *inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R); 54b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPWidenSelectRecipe *R); 55b0b88643SFlorian Hahn Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R); 56b0b88643SFlorian Hahn 57b0b88643SFlorian Hahn public: 58*b29c5b66SDavid Sherwood VPTypeAnalysis(Type *CanonicalIVTy) 59*b29c5b66SDavid Sherwood : CanonicalIVTy(CanonicalIVTy), Ctx(CanonicalIVTy->getContext()) {} 60b0b88643SFlorian Hahn 61b0b88643SFlorian Hahn /// Infer the type of \p V. Returns the scalar type of \p V. 62b0b88643SFlorian Hahn Type *inferScalarType(const VPValue *V); 63097ba536SFlorian Hahn 64097ba536SFlorian Hahn /// Return the LLVMContext used by the analysis. 65097ba536SFlorian Hahn LLVMContext &getContext() { return Ctx; } 66b0b88643SFlorian Hahn }; 67b0b88643SFlorian Hahn 68ef89e3efSFlorian Hahn // Collect a VPlan's ephemeral recipes (those used only by an assume). 69ef89e3efSFlorian Hahn void collectEphemeralRecipesForVPlan(VPlan &Plan, 70ef89e3efSFlorian Hahn DenseSet<VPRecipeBase *> &EphRecipes); 71b0b88643SFlorian Hahn } // end namespace llvm 72b0b88643SFlorian Hahn 73b0b88643SFlorian Hahn #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H 74