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