15f757f3fSDimitry Andric //===- VPlanAnalysis.h - Various Analyses working on VPlan ------*- C++ -*-===// 25f757f3fSDimitry Andric // 35f757f3fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 45f757f3fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 55f757f3fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65f757f3fSDimitry Andric // 75f757f3fSDimitry Andric //===----------------------------------------------------------------------===// 85f757f3fSDimitry Andric 95f757f3fSDimitry Andric #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H 105f757f3fSDimitry Andric #define LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H 115f757f3fSDimitry Andric 125f757f3fSDimitry Andric #include "llvm/ADT/DenseMap.h" 13*0fca6ea1SDimitry Andric #include "llvm/ADT/DenseSet.h" 145f757f3fSDimitry Andric 155f757f3fSDimitry Andric namespace llvm { 165f757f3fSDimitry Andric 175f757f3fSDimitry Andric class LLVMContext; 185f757f3fSDimitry Andric class VPValue; 195f757f3fSDimitry Andric class VPBlendRecipe; 205f757f3fSDimitry Andric class VPInstruction; 215f757f3fSDimitry Andric class VPWidenRecipe; 225f757f3fSDimitry Andric class VPWidenCallRecipe; 235f757f3fSDimitry Andric class VPWidenIntOrFpInductionRecipe; 24*0fca6ea1SDimitry Andric class VPWidenMemoryRecipe; 255f757f3fSDimitry Andric struct VPWidenSelectRecipe; 265f757f3fSDimitry Andric class VPReplicateRecipe; 27*0fca6ea1SDimitry Andric class VPRecipeBase; 28*0fca6ea1SDimitry Andric class VPlan; 295f757f3fSDimitry Andric class Type; 305f757f3fSDimitry Andric 315f757f3fSDimitry Andric /// An analysis for type-inference for VPValues. 325f757f3fSDimitry Andric /// It infers the scalar type for a given VPValue by bottom-up traversing 335f757f3fSDimitry Andric /// through defining recipes until root nodes with known types are reached (e.g. 345f757f3fSDimitry Andric /// live-ins or load recipes). The types are then propagated top down through 355f757f3fSDimitry Andric /// operations. 365f757f3fSDimitry Andric /// Note that the analysis caches the inferred types. A new analysis object must 375f757f3fSDimitry Andric /// be constructed once a VPlan has been modified in a way that invalidates any 385f757f3fSDimitry Andric /// of the previously inferred types. 395f757f3fSDimitry Andric class VPTypeAnalysis { 405f757f3fSDimitry Andric DenseMap<const VPValue *, Type *> CachedTypes; 41*0fca6ea1SDimitry Andric /// Type of the canonical induction variable. Used for all VPValues without 42*0fca6ea1SDimitry Andric /// any underlying IR value (like the vector trip count or the backedge-taken 43*0fca6ea1SDimitry Andric /// count). 44*0fca6ea1SDimitry Andric Type *CanonicalIVTy; 455f757f3fSDimitry Andric LLVMContext &Ctx; 465f757f3fSDimitry Andric 475f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPBlendRecipe *R); 485f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPInstruction *R); 495f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPWidenCallRecipe *R); 505f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPWidenRecipe *R); 515f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPWidenIntOrFpInductionRecipe *R); 52*0fca6ea1SDimitry Andric Type *inferScalarTypeForRecipe(const VPWidenMemoryRecipe *R); 535f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPWidenSelectRecipe *R); 545f757f3fSDimitry Andric Type *inferScalarTypeForRecipe(const VPReplicateRecipe *R); 555f757f3fSDimitry Andric 565f757f3fSDimitry Andric public: 57*0fca6ea1SDimitry Andric VPTypeAnalysis(Type *CanonicalIVTy, LLVMContext &Ctx) 58*0fca6ea1SDimitry Andric : CanonicalIVTy(CanonicalIVTy), Ctx(Ctx) {} 595f757f3fSDimitry Andric 605f757f3fSDimitry Andric /// Infer the type of \p V. Returns the scalar type of \p V. 615f757f3fSDimitry Andric Type *inferScalarType(const VPValue *V); 625f757f3fSDimitry Andric 635f757f3fSDimitry Andric /// Return the LLVMContext used by the analysis. 645f757f3fSDimitry Andric LLVMContext &getContext() { return Ctx; } 655f757f3fSDimitry Andric }; 665f757f3fSDimitry Andric 67*0fca6ea1SDimitry Andric // Collect a VPlan's ephemeral recipes (those used only by an assume). 68*0fca6ea1SDimitry Andric void collectEphemeralRecipesForVPlan(VPlan &Plan, 69*0fca6ea1SDimitry Andric DenseSet<VPRecipeBase *> &EphRecipes); 705f757f3fSDimitry Andric } // end namespace llvm 715f757f3fSDimitry Andric 725f757f3fSDimitry Andric #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H 73