Home | History | Annotate | Line # | Download | only in Analysis
      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 features. Each feature is defined through a triple:
     20 // - the name of an enum member, which will be the feature index
     21 // - a textual name, used for Tensorflow model binding (so it needs to match the
     22 // names used by the Tensorflow model)
     23 // - a documentation description. Currently, that is not used anywhere
     24 // programmatically, and serves as workaround to inability of inserting comments
     25 // in macros.
     26 #define INLINE_FEATURE_ITERATOR(M)                                             \
     27   M(CalleeBasicBlockCount, "callee_basic_block_count",                         \
     28     "number of basic blocks of the callee")                                    \
     29   M(CallSiteHeight, "callsite_height",                                         \
     30     "position of the call site in the original call graph - measured from "    \
     31     "the farthest SCC")                                                        \
     32   M(NodeCount, "node_count",                                                   \
     33     "total current number of defined functions in the module")                 \
     34   M(NrCtantParams, "nr_ctant_params",                                          \
     35     "number of parameters in the call site that are constants")                \
     36   M(CostEstimate, "cost_estimate", "total cost estimate (threshold - free)")   \
     37   M(EdgeCount, "edge_count",                                                   \
     38     "number of module-internal users of the caller, +1 if the caller is "      \
     39     "exposed externally")                                                      \
     40   M(CallerUsers, "caller_users",                                               \
     41     "number of blocks reached from a conditional instruction, in the caller")  \
     42   M(CallerConditionallyExecutedBlocks, "caller_conditionally_executed_blocks", \
     43     "number of blocks reached from a conditional instruction, in the caller")  \
     44   M(CallerBasicBlockCount, "caller_basic_block_count",                         \
     45     "number of basic blocks in the caller")                                    \
     46   M(CalleeConditionallyExecutedBlocks, "callee_conditionally_executed_blocks", \
     47     "number of blocks reached from a conditional instruction, in the callee")  \
     48   M(CalleeUsers, "callee_users",                                               \
     49     "number of blocks reached from a conditional instruction, in the callee")
     50 
     51 enum class FeatureIndex : size_t {
     52 #define POPULATE_INDICES(INDEX_NAME, NAME, COMMENT) INDEX_NAME,
     53   INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
     54 #undef POPULATE_INDICES
     55       NumberOfFeatures
     56 };
     57 
     58 constexpr size_t NumberOfFeatures =
     59     static_cast<size_t>(FeatureIndex::NumberOfFeatures);
     60 
     61 extern const std::array<std::string, NumberOfFeatures> FeatureNameMap;
     62 
     63 extern const char *const DecisionName;
     64 extern const char *const DefaultDecisionName;
     65 extern const char *const RewardName;
     66 
     67 using InlineFeatures = std::vector<int64_t>;
     68 
     69 } // namespace llvm
     70 #endif // LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
     71