File indexing completed on 2026-05-10 08:43:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
0011 #define LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
0012
0013 #include "llvm/Analysis/TensorSpec.h"
0014
0015 #include <array>
0016 #include <vector>
0017
0018 namespace llvm {
0019
0020
0021
0022
0023 #define INLINE_COST_FEATURE_ITERATOR(M) \
0024 M(int64_t, {1}, sroa_savings, \
0025 "Savings from SROA (scalar replacement of aggregates)") \
0026 M(int64_t, {1}, sroa_losses, \
0027 "Losses from SROA (scalar replacement of aggregates)") \
0028 M(int64_t, {1}, load_elimination, "Cost of load elimination in the call") \
0029 M(int64_t, {1}, call_penalty, \
0030 "Accumulation of penalty applied to call sites when inlining") \
0031 M(int64_t, {1}, call_argument_setup, \
0032 "Accumulation of call argument setup costs") \
0033 M(int64_t, {1}, load_relative_intrinsic, \
0034 "Accumulation of costs of loading relative intrinsics") \
0035 M(int64_t, {1}, lowered_call_arg_setup, \
0036 "Accumulation of cost of lowered call argument setups") \
0037 M(int64_t, {1}, indirect_call_penalty, \
0038 "Accumulation of costs for indirect calls") \
0039 M(int64_t, {1}, jump_table_penalty, "Accumulation of costs for jump tables") \
0040 M(int64_t, {1}, case_cluster_penalty, \
0041 "Accumulation of costs for case clusters") \
0042 M(int64_t, {1}, switch_default_dest_penalty, \
0043 "Accumulation of costs for switch default destination") \
0044 M(int64_t, {1}, switch_penalty, \
0045 "Accumulation of costs for switch statements") \
0046 M(int64_t, {1}, unsimplified_common_instructions, \
0047 "Costs from unsimplified common instructions") \
0048 M(int64_t, {1}, num_loops, "Number of loops in the caller") \
0049 M(int64_t, {1}, dead_blocks, "Number of dead blocks in the caller") \
0050 M(int64_t, {1}, simplified_instructions, \
0051 "Number of simplified instructions") \
0052 M(int64_t, {1}, constant_args, \
0053 "Number of constant arguments in the call site") \
0054 M(int64_t, {1}, constant_offset_ptr_args, \
0055 "Number of constant offset pointer args in the call site") \
0056 M(int64_t, {1}, callsite_cost, "Estimated cost of the call site") \
0057 M(int64_t, {1}, cold_cc_penalty, "Penalty for a cold calling convention") \
0058 M(int64_t, {1}, last_call_to_static_bonus, \
0059 "Bonus for being the last call to static") \
0060 M(int64_t, {1}, is_multiple_blocks, \
0061 "Boolean; is the Callee multiple blocks") \
0062 M(int64_t, {1}, nested_inlines, \
0063 "Would the default inliner perfom nested inlining") \
0064 M(int64_t, {1}, nested_inline_cost_estimate, \
0065 "Estimate of the accumulated cost of nested inlines") \
0066 M(int64_t, {1}, threshold, "Threshold for the heuristic inliner")
0067
0068
0069 enum class InlineCostFeatureIndex : size_t {
0070 #define POPULATE_INDICES(DTYPE, SHAPE, NAME, DOC) NAME,
0071 INLINE_COST_FEATURE_ITERATOR(POPULATE_INDICES)
0072 #undef POPULATE_INDICES
0073
0074 NumberOfFeatures
0075 };
0076
0077
0078 using InlineCostFeatures =
0079 std::array<int,
0080 static_cast<size_t>(InlineCostFeatureIndex::NumberOfFeatures)>;
0081
0082 constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature) {
0083 return Feature != InlineCostFeatureIndex::sroa_savings &&
0084 Feature != InlineCostFeatureIndex::is_multiple_blocks &&
0085 Feature != InlineCostFeatureIndex::dead_blocks &&
0086 Feature != InlineCostFeatureIndex::simplified_instructions &&
0087 Feature != InlineCostFeatureIndex::constant_args &&
0088 Feature != InlineCostFeatureIndex::constant_offset_ptr_args &&
0089 Feature != InlineCostFeatureIndex::nested_inlines &&
0090 Feature != InlineCostFeatureIndex::nested_inline_cost_estimate &&
0091 Feature != InlineCostFeatureIndex::threshold;
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101 #define INLINE_FEATURE_ITERATOR(M) \
0102 M(int64_t, {1}, callee_basic_block_count, \
0103 "number of basic blocks of the callee") \
0104 M(int64_t, {1}, callsite_height, \
0105 "position of the call site in the original call graph - measured from " \
0106 "the farthest SCC") \
0107 M(int64_t, {1}, node_count, \
0108 "total current number of defined functions in the module") \
0109 M(int64_t, {1}, nr_ctant_params, \
0110 "number of parameters in the call site that are constants") \
0111 M(int64_t, {1}, cost_estimate, "total cost estimate (threshold - free)") \
0112 M(int64_t, {1}, edge_count, "total number of calls in the module") \
0113 M(int64_t, {1}, caller_users, \
0114 "number of module-internal users of the caller, +1 if the caller is " \
0115 "exposed externally") \
0116 M(int64_t, {1}, caller_conditionally_executed_blocks, \
0117 "number of blocks reached from a conditional instruction, in the caller") \
0118 M(int64_t, {1}, caller_basic_block_count, \
0119 "number of basic blocks in the caller") \
0120 M(int64_t, {1}, callee_conditionally_executed_blocks, \
0121 "number of blocks reached from a conditional instruction, in the callee") \
0122 M(int64_t, {1}, callee_users, \
0123 "number of module-internal users of the callee, +1 if the callee is " \
0124 "exposed externally") \
0125 M(int64_t, {1}, is_callee_avail_external, \
0126 "Is callee an available-externally linkage type (i.e. could be DCEd if " \
0127 "not " \
0128 "fully inlined by ElimAvailExtern)") \
0129 M(int64_t, {1}, is_caller_avail_external, \
0130 "Is caller an available-externally linkage type (i.e. could be DCEd if " \
0131 "not " \
0132 "fully inlined by ElimAvailExtern)")
0133
0134
0135 enum class FeatureIndex : size_t {
0136 #define POPULATE_INDICES(DTYPE, SHAPE, NAME, COMMENT) NAME,
0137
0138 INLINE_COST_FEATURE_ITERATOR(POPULATE_INDICES)
0139
0140
0141 INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
0142 #undef POPULATE_INDICES
0143
0144 NumberOfFeatures
0145 };
0146
0147
0148 constexpr FeatureIndex
0149 inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) {
0150 return static_cast<FeatureIndex>(static_cast<size_t>(Feature));
0151 }
0152
0153 constexpr size_t NumberOfFeatures =
0154 static_cast<size_t>(FeatureIndex::NumberOfFeatures);
0155
0156 extern const std::vector<TensorSpec> FeatureMap;
0157
0158 extern const char *const DecisionName;
0159 extern const TensorSpec InlineDecisionSpec;
0160 extern const char *const DefaultDecisionName;
0161 extern const TensorSpec DefaultDecisionSpec;
0162 extern const char *const RewardName;
0163
0164 using InlineFeatures = std::vector<int64_t>;
0165
0166 }
0167 #endif