LLVM 17.0.0git
InlineModelFeatureMaps.h
Go to the documentation of this file.
1//===- InlineModelFeatureMaps.h - common model runner defs ------*- 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
10#ifndef LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
11#define LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
12
14
15#include <array>
16#include <string>
17#include <vector>
18
19namespace llvm {
20
21// List of cost features. A "cost" feature is a summand of the heuristic-based
22// inline cost, and we define them separately to preserve the original heuristic
23// behavior.
24#define INLINE_COST_FEATURE_ITERATOR(M) \
25 M(SROASavings, "sroa_savings") \
26 M(SROALosses, "sroa_losses") \
27 M(LoadElimination, "load_elimination") \
28 M(CallPenalty, "call_penalty") \
29 M(CallArgumentSetup, "call_argument_setup") \
30 M(LoadRelativeIntrinsic, "load_relative_intrinsic") \
31 M(LoweredCallArgSetup, "lowered_call_arg_setup") \
32 M(IndirectCallPenalty, "indirect_call_penalty") \
33 M(JumpTablePenalty, "jump_table_penalty") \
34 M(CaseClusterPenalty, "case_cluster_penalty") \
35 M(SwitchPenalty, "switch_penalty") \
36 M(UnsimplifiedCommonInstructions, "unsimplified_common_instructions") \
37 M(NumLoops, "num_loops") \
38 M(DeadBlocks, "dead_blocks") \
39 M(SimplifiedInstructions, "simplified_instructions") \
40 M(ConstantArgs, "constant_args") \
41 M(ConstantOffsetPtrArgs, "constant_offset_ptr_args") \
42 M(CallSiteCost, "callsite_cost") \
43 M(ColdCcPenalty, "cold_cc_penalty") \
44 M(LastCallToStaticBonus, "last_call_to_static_bonus") \
45 M(IsMultipleBlocks, "is_multiple_blocks") \
46 M(NestedInlines, "nested_inlines") \
47 M(NestedInlineCostEstimate, "nested_inline_cost_estimate") \
48 M(Threshold, "threshold")
49
50// clang-format off
51enum class InlineCostFeatureIndex : size_t {
52#define POPULATE_INDICES(INDEX_NAME, NAME) INDEX_NAME,
54#undef POPULATE_INDICES
55
57};
58// clang-format on
59
61 std::array<int,
62 static_cast<size_t>(InlineCostFeatureIndex::NumberOfFeatures)>;
63
65 return Feature != InlineCostFeatureIndex::SROASavings &&
66 Feature != InlineCostFeatureIndex::IsMultipleBlocks &&
67 Feature != InlineCostFeatureIndex::DeadBlocks &&
68 Feature != InlineCostFeatureIndex::SimplifiedInstructions &&
69 Feature != InlineCostFeatureIndex::ConstantArgs &&
70 Feature != InlineCostFeatureIndex::ConstantOffsetPtrArgs &&
71 Feature != InlineCostFeatureIndex::NestedInlines &&
72 Feature != InlineCostFeatureIndex::NestedInlineCostEstimate &&
73 Feature != InlineCostFeatureIndex::Threshold;
74}
75
76// List of features. Each feature is defined through a triple:
77// - the name of an enum member, which will be the feature index
78// - a textual name, used for Tensorflow model binding (so it needs to match the
79// names used by the Tensorflow model)
80// - a documentation description. Currently, that is not used anywhere
81// programmatically, and serves as workaround to inability of inserting comments
82// in macros.
83#define INLINE_FEATURE_ITERATOR(M) \
84 M(CalleeBasicBlockCount, "callee_basic_block_count", \
85 "number of basic blocks of the callee") \
86 M(CallSiteHeight, "callsite_height", \
87 "position of the call site in the original call graph - measured from " \
88 "the farthest SCC") \
89 M(NodeCount, "node_count", \
90 "total current number of defined functions in the module") \
91 M(NrCtantParams, "nr_ctant_params", \
92 "number of parameters in the call site that are constants") \
93 M(CostEstimate, "cost_estimate", "total cost estimate (threshold - free)") \
94 M(EdgeCount, "edge_count", "total number of calls in the module") \
95 M(CallerUsers, "caller_users", \
96 "number of module-internal users of the caller, +1 if the caller is " \
97 "exposed externally") \
98 M(CallerConditionallyExecutedBlocks, "caller_conditionally_executed_blocks", \
99 "number of blocks reached from a conditional instruction, in the caller") \
100 M(CallerBasicBlockCount, "caller_basic_block_count", \
101 "number of basic blocks in the caller") \
102 M(CalleeConditionallyExecutedBlocks, "callee_conditionally_executed_blocks", \
103 "number of blocks reached from a conditional instruction, in the callee") \
104 M(CalleeUsers, "callee_users", \
105 "number of module-internal users of the callee, +1 if the callee is " \
106 "exposed externally")
107
108// clang-format off
109enum class FeatureIndex : size_t {
110// InlineCost features - these must come first
111#define POPULATE_INDICES(INDEX_NAME, NAME) INDEX_NAME,
113#undef POPULATE_INDICES
114
115// Non-cost features
116#define POPULATE_INDICES(INDEX_NAME, NAME, COMMENT) INDEX_NAME,
118#undef POPULATE_INDICES
119
121};
122// clang-format on
123
124constexpr FeatureIndex
126 return static_cast<FeatureIndex>(static_cast<size_t>(Feature));
127}
128
129constexpr size_t NumberOfFeatures =
130 static_cast<size_t>(FeatureIndex::NumberOfFeatures);
131
132extern const std::vector<TensorSpec> FeatureMap;
133
134extern const char *const DecisionName;
135extern const TensorSpec InlineDecisionSpec;
136extern const char *const DefaultDecisionName;
137extern const char *const RewardName;
138
139using InlineFeatures = std::vector<int64_t>;
140
141} // namespace llvm
142#endif // LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
#define INLINE_COST_FEATURE_ITERATOR(M)
#define INLINE_FEATURE_ITERATOR(M)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
constexpr FeatureIndex inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature)
const char *const DefaultDecisionName
constexpr size_t NumberOfFeatures
constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature)
const char *const DecisionName
POPULATE_INDICES(INDEX_NAME, NAME)
const std::vector< TensorSpec > FeatureMap
std::array< int, static_cast< size_t >(InlineCostFeatureIndex::NumberOfFeatures)> InlineCostFeatures
const TensorSpec InlineDecisionSpec
const char *const RewardName
std::vector< int64_t > InlineFeatures