xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm/Analysis/InlineModelFeatureMaps.h (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
1*5ffd83dbSDimitry Andric //===- InlineModelFeatureMaps.h - common model runner defs ------*- C++ -*-===//
2*5ffd83dbSDimitry Andric //
3*5ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*5ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5ffd83dbSDimitry Andric //
7*5ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
8*5ffd83dbSDimitry Andric //
9*5ffd83dbSDimitry Andric 
10*5ffd83dbSDimitry Andric #ifndef LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
11*5ffd83dbSDimitry Andric #define LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
12*5ffd83dbSDimitry Andric 
13*5ffd83dbSDimitry Andric #include <array>
14*5ffd83dbSDimitry Andric #include <string>
15*5ffd83dbSDimitry Andric #include <vector>
16*5ffd83dbSDimitry Andric 
17*5ffd83dbSDimitry Andric namespace llvm {
18*5ffd83dbSDimitry Andric 
19*5ffd83dbSDimitry Andric // List of features. Each feature is defined through a triple:
20*5ffd83dbSDimitry Andric // - the name of an enum member, which will be the feature index
21*5ffd83dbSDimitry Andric // - a textual name, used for Tensorflow model binding (so it needs to match the
22*5ffd83dbSDimitry Andric // names used by the Tensorflow model)
23*5ffd83dbSDimitry Andric // - a documentation description. Currently, that is not used anywhere
24*5ffd83dbSDimitry Andric // programmatically, and serves as workaround to inability of inserting comments
25*5ffd83dbSDimitry Andric // in macros.
26*5ffd83dbSDimitry Andric #define INLINE_FEATURE_ITERATOR(M)                                             \
27*5ffd83dbSDimitry Andric   M(CalleeBasicBlockCount, "callee_basic_block_count",                         \
28*5ffd83dbSDimitry Andric     "number of basic blocks of the callee")                                    \
29*5ffd83dbSDimitry Andric   M(CallSiteHeight, "callsite_height",                                         \
30*5ffd83dbSDimitry Andric     "position of the call site in the original call graph - measured from "    \
31*5ffd83dbSDimitry Andric     "the farthest SCC")                                                        \
32*5ffd83dbSDimitry Andric   M(NodeCount, "node_count",                                                   \
33*5ffd83dbSDimitry Andric     "total current number of defined functions in the module")                 \
34*5ffd83dbSDimitry Andric   M(NrCtantParams, "nr_ctant_params",                                          \
35*5ffd83dbSDimitry Andric     "number of parameters in the call site that are constants")                \
36*5ffd83dbSDimitry Andric   M(CostEstimate, "cost_estimate", "total cost estimate (threshold - free)")   \
37*5ffd83dbSDimitry Andric   M(EdgeCount, "edge_count",                                                   \
38*5ffd83dbSDimitry Andric     "number of module-internal users of the caller, +1 if the caller is "      \
39*5ffd83dbSDimitry Andric     "exposed externally")                                                      \
40*5ffd83dbSDimitry Andric   M(CallerUsers, "caller_users",                                               \
41*5ffd83dbSDimitry Andric     "number of blocks reached from a conditional instruction, in the caller")  \
42*5ffd83dbSDimitry Andric   M(CallerConditionallyExecutedBlocks, "caller_conditionally_executed_blocks", \
43*5ffd83dbSDimitry Andric     "number of blocks reached from a conditional instruction, in the caller")  \
44*5ffd83dbSDimitry Andric   M(CallerBasicBlockCount, "caller_basic_block_count",                         \
45*5ffd83dbSDimitry Andric     "number of basic blocks in the caller")                                    \
46*5ffd83dbSDimitry Andric   M(CalleeConditionallyExecutedBlocks, "callee_conditionally_executed_blocks", \
47*5ffd83dbSDimitry Andric     "number of blocks reached from a conditional instruction, in the callee")  \
48*5ffd83dbSDimitry Andric   M(CalleeUsers, "callee_users",                                               \
49*5ffd83dbSDimitry Andric     "number of blocks reached from a conditional instruction, in the callee")
50*5ffd83dbSDimitry Andric 
51*5ffd83dbSDimitry Andric enum class FeatureIndex : size_t {
52*5ffd83dbSDimitry Andric #define POPULATE_INDICES(INDEX_NAME, NAME, COMMENT) INDEX_NAME,
53*5ffd83dbSDimitry Andric   INLINE_FEATURE_ITERATOR(POPULATE_INDICES)
54*5ffd83dbSDimitry Andric #undef POPULATE_INDICES
55*5ffd83dbSDimitry Andric       NumberOfFeatures
56*5ffd83dbSDimitry Andric };
57*5ffd83dbSDimitry Andric 
58*5ffd83dbSDimitry Andric constexpr size_t NumberOfFeatures =
59*5ffd83dbSDimitry Andric     static_cast<size_t>(FeatureIndex::NumberOfFeatures);
60*5ffd83dbSDimitry Andric 
61*5ffd83dbSDimitry Andric extern const std::array<std::string, NumberOfFeatures> FeatureNameMap;
62*5ffd83dbSDimitry Andric 
63*5ffd83dbSDimitry Andric extern const char *const DecisionName;
64*5ffd83dbSDimitry Andric extern const char *const DefaultDecisionName;
65*5ffd83dbSDimitry Andric extern const char *const RewardName;
66*5ffd83dbSDimitry Andric 
67*5ffd83dbSDimitry Andric using InlineFeatures = std::vector<int64_t>;
68*5ffd83dbSDimitry Andric 
69*5ffd83dbSDimitry Andric } // namespace llvm
70*5ffd83dbSDimitry Andric #endif // LLVM_ANALYSIS_INLINEMODELFEATUREMAPS_H
71