Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Blame | Last modification | View Log | Download | RSS feed

  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 "llvm/Analysis/TensorSpec.h"
  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
  51. enum class InlineCostFeatureIndex : size_t {
  52. #define POPULATE_INDICES(INDEX_NAME, NAME) INDEX_NAME,
  53.   INLINE_COST_FEATURE_ITERATOR(POPULATE_INDICES)
  54. #undef POPULATE_INDICES
  55.  
  56.   NumberOfFeatures
  57. };
  58. // clang-format on
  59.  
  60. using InlineCostFeatures =
  61.     std::array<int,
  62.                static_cast<size_t>(InlineCostFeatureIndex::NumberOfFeatures)>;
  63.  
  64. constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature) {
  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,
  112.   INLINE_COST_FEATURE_ITERATOR(POPULATE_INDICES)
  113. #undef POPULATE_INDICES
  114.  
  115. // Non-cost features
  116. #define POPULATE_INDICES(INDEX_NAME, NAME, COMMENT) INDEX_NAME,
  117.   INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
  118. #undef POPULATE_INDICES
  119.  
  120.   NumberOfFeatures
  121. };
  122. // clang-format on
  123.  
  124. constexpr FeatureIndex
  125. inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) {
  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
  142.