LLVM  16.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 
19 namespace 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
52 #define POPULATE_INDICES(INDEX_NAME, NAME) INDEX_NAME,
54 #undef POPULATE_INDICES
55 
57 };
58 // clang-format on
59 
60 using InlineCostFeatures =
61  std::array<int,
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
109 enum 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 
124 constexpr FeatureIndex
126  return static_cast<FeatureIndex>(static_cast<size_t>(Feature));
127 }
128 
129 constexpr size_t NumberOfFeatures =
130  static_cast<size_t>(FeatureIndex::NumberOfFeatures);
131 
132 extern const std::array<TensorSpec, NumberOfFeatures> FeatureMap;
133 
134 extern const char *const DecisionName;
135 extern const char *const DefaultDecisionName;
136 extern const char *const RewardName;
137 
138 using InlineFeatures = std::vector<int64_t>;
139 
140 } // namespace llvm
141 #endif // LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
INLINE_COST_FEATURE_ITERATOR
#define INLINE_COST_FEATURE_ITERATOR(M)
Definition: InlineModelFeatureMaps.h:24
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::inlineCostFeatureToMlFeature
constexpr FeatureIndex inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature)
Definition: InlineModelFeatureMaps.h:125
llvm::FeatureMap
const std::array< TensorSpec, NumberOfFeatures > FeatureMap
Definition: MLInlineAdvisor.cpp:62
TensorSpec.h
llvm::FeatureIndex::POPULATE_INDICES
POPULATE_INDICES(INDEX_NAME, NAME)
llvm::FeatureIndex::NumberOfFeatures
@ NumberOfFeatures
size_t
llvm::DecisionName
const char *const DecisionName
Definition: MLInlineAdvisor.cpp:75
llvm::InlineFeatures
std::vector< int64_t > InlineFeatures
Definition: InlineModelFeatureMaps.h:138
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:51
llvm::DefaultDecisionName
const char *const DefaultDecisionName
Definition: MLInlineAdvisor.cpp:76
llvm::isHeuristicInlineCostFeature
constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature)
Definition: InlineModelFeatureMaps.h:64
llvm::FeatureIndex
FeatureIndex
Definition: InlineModelFeatureMaps.h:109
llvm::InlineCostFeatureIndex::POPULATE_INDICES
POPULATE_INDICES(INDEX_NAME, NAME)
llvm::InlineCostFeatureIndex::NumberOfFeatures
@ NumberOfFeatures
llvm::InlineCostFeatures
std::array< int, static_cast< size_t >(InlineCostFeatureIndex::NumberOfFeatures)> InlineCostFeatures
Definition: InlineModelFeatureMaps.h:62
llvm::NumberOfFeatures
constexpr size_t NumberOfFeatures
Definition: InlineModelFeatureMaps.h:129
INLINE_FEATURE_ITERATOR
#define INLINE_FEATURE_ITERATOR(M)
Definition: InlineModelFeatureMaps.h:83
llvm::RewardName
const char *const RewardName
Definition: MLInlineAdvisor.cpp:77