|
16 | 16 |
|
17 | 17 | namespace llvm {
|
18 | 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 |
| 49 | +enum class InlineCostFeatureIndex : size_t { |
| 50 | +#define POPULATE_INDICES(INDEX_NAME, NAME) INDEX_NAME, |
| 51 | + INLINE_COST_FEATURE_ITERATOR(POPULATE_INDICES) |
| 52 | +#undef POPULATE_INDICES |
| 53 | + |
| 54 | + NumberOfFeatures |
| 55 | +}; |
| 56 | +// clang-format on |
| 57 | + |
| 58 | +using InlineCostFeatures = |
| 59 | + std::array<int, |
| 60 | + static_cast<size_t>(InlineCostFeatureIndex::NumberOfFeatures)>; |
| 61 | + |
| 62 | +constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature) { |
| 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 && |
| 71 | + Feature != InlineCostFeatureIndex::Threshold; |
| 72 | +} |
| 73 | + |
19 | 74 | // List of features. Each feature is defined through a triple:
|
20 | 75 | // - the name of an enum member, which will be the feature index
|
21 | 76 | // - a textual name, used for Tensorflow model binding (so it needs to match the
|
@@ -48,12 +103,26 @@ namespace llvm {
|
48 | 103 | "number of module-internal users of the callee, +1 if the callee is " \
|
49 | 104 | "exposed externally")
|
50 | 105 |
|
| 106 | +// clang-format off |
51 | 107 | enum class FeatureIndex : size_t {
|
| 108 | +// InlineCost features - these must come first |
| 109 | +#define POPULATE_INDICES(INDEX_NAME, NAME) INDEX_NAME, |
| 110 | + INLINE_COST_FEATURE_ITERATOR(POPULATE_INDICES) |
| 111 | +#undef POPULATE_INDICES |
| 112 | + |
| 113 | +// Non-cost features |
52 | 114 | #define POPULATE_INDICES(INDEX_NAME, NAME, COMMENT) INDEX_NAME,
|
53 | 115 | INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
|
54 | 116 | #undef POPULATE_INDICES
|
55 |
| - NumberOfFeatures |
| 117 | + |
| 118 | + NumberOfFeatures |
56 | 119 | };
|
| 120 | +// clang-format on |
| 121 | + |
| 122 | +constexpr FeatureIndex |
| 123 | +inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) { |
| 124 | + return static_cast<FeatureIndex>(static_cast<size_t>(Feature)); |
| 125 | +} |
57 | 126 |
|
58 | 127 | constexpr size_t NumberOfFeatures =
|
59 | 128 | static_cast<size_t>(FeatureIndex::NumberOfFeatures);
|
|
0 commit comments