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 "VPlan.h"
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
15#include "llvm/ADT/MapVector.h"
16#include "llvm/Analysis/TargetTransformInfo.h"
17#include "llvm/IR/DataLayout.h"
18#include "llvm/IR/Type.h"
19
20namespace llvm {
21
22class VPRecipeBase;
23class VPlan;
24class VPDominatorTree;
25class TargetTransformInfo;
26class InstructionCost;
27
28// Collect a VPlan's ephemeral recipes (those used only by an assume).
29void collectEphemeralRecipesForVPlan(VPlan &Plan,
30 DenseSet<VPRecipeBase *> &EphRecipes);
31
32/// Returns true if the memory accesses in outer loop plain CFG \p Plan can be
33/// vectorized.
34bool proveOuterLoopMemorySafety(VPlan &Plan, PredicatedScalarEvolution &PSE,
35 AAResults &AA, const VPDominatorTree &VPDT,
36 const Loop *OuterLoop);
37
38/// A struct that represents some properties of the register usage
39/// of a loop.
40struct VPRegisterUsage {
41 /// Holds the number of loop invariant values that are used in the loop.
42 /// The key is ClassID of target-provided register class.
43 SmallMapVector<unsigned, unsigned, 4> LoopInvariantRegs;
44 /// Holds the maximum number of concurrent live intervals in the loop.
45 /// The key is ClassID of target-provided register class.
46 SmallMapVector<unsigned, unsigned, 4> MaxLocalUsers;
47
48 /// Calculate the estimated cost of any spills due to using more registers
49 /// than the number available for the target. If non-zero, OverrideMaxNumRegs
50 /// is used in place of the target's number of registers.
51 InstructionCost spillCost(const TargetTransformInfo &TTI,
52 TargetTransformInfo::TargetCostKind CostKind,
53 unsigned OverrideMaxNumRegs = 0) const;
54};
55
56/// Estimate the register usage for \p Plan and vectorization factors in \p VFs
57/// by calculating the highest number of values that are live at a single
58/// location as a rough estimate. Returns the register usage for each VF in \p
59/// VFs.
60SmallVector<VPRegisterUsage, 8>
61calculateRegisterUsageForPlan(VPlan &Plan, ArrayRef<ElementCount> VFs,
62 const TargetTransformInfo &TTI);
63
64} // end namespace llvm
65
66#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
67