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 TargetTransformInfo;
25class InstructionCost;
26
27struct VPCostContext;
28
29// Collect a VPlan's ephemeral recipes (those used only by an assume).
30void collectEphemeralRecipesForVPlan(VPlan &Plan,
31 DenseSet<VPRecipeBase *> &EphRecipes);
32
33/// A struct that represents some properties of the register usage
34/// of a loop.
35struct VPRegisterUsage {
36 /// Holds the number of loop invariant values that are used in the loop.
37 /// The key is ClassID of target-provided register class.
38 SmallMapVector<unsigned, unsigned, 4> LoopInvariantRegs;
39 /// Holds the maximum number of concurrent live intervals in the loop.
40 /// The key is ClassID of target-provided register class.
41 SmallMapVector<unsigned, unsigned, 4> MaxLocalUsers;
42
43 /// Calculate the estimated cost of any spills due to using more registers
44 /// than the number available for the target. If non-zero, OverrideMaxNumRegs
45 /// is used in place of the target's number of registers.
46 InstructionCost spillCost(const TargetTransformInfo &TTI,
47 TargetTransformInfo::TargetCostKind CostKind,
48 unsigned OverrideMaxNumRegs = 0) const;
49};
50
51/// Estimate the register usage for \p Plan and vectorization factors in \p VFs
52/// by calculating the highest number of values that are live at a single
53/// location as a rough estimate. Returns the register usage for each VF in \p
54/// VFs.
55SmallVector<VPRegisterUsage, 8> calculateRegisterUsageForPlan(
56 VPlan &Plan, ArrayRef<ElementCount> VFs, const TargetTransformInfo &TTI,
57 const SmallPtrSetImpl<const Value *> &ValuesToIgnore);
58
59} // end namespace llvm
60
61#endif // LLVM_TRANSFORMS_VECTORIZE_VPLANANALYSIS_H
62