Skip to content

Commit b056827

Browse files
committed
Removing NumberOfFeatures from enum FeatureIndex
1 parent c157323 commit b056827

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

llvm/include/llvm/Analysis/InlineModelFeatureMaps.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ constexpr bool isHeuristicInlineCostFeature(InlineCostFeatureIndex Feature) {
132132
"not " \
133133
"fully inlined by ElimAvailExtern)")
134134

135+
// Not all features listed in FeatureIndex are used by the ML model.
136+
// Specifically, callee_embedding and caller_embedding are used only when the
137+
// usage of IR2Vec embeddings is explicitly enabled. Meaning, the size/number of
138+
// features is not static. So, we cannot determine number of features based on
139+
// the number of elements in this enum.
135140
// clang-format off
136141
enum class FeatureIndex : size_t {
137142
#define POPULATE_INDICES(DTYPE, SHAPE, NAME, COMMENT) NAME,
@@ -146,9 +151,7 @@ enum class FeatureIndex : size_t {
146151
// Dimensions of embeddings are not known in the compile time (until vocab is
147152
// read). Hence macros cannot be used here.
148153
callee_embedding,
149-
caller_embedding,
150-
151-
NumberOfFeatures
154+
caller_embedding
152155
};
153156
// clang-format on
154157

@@ -157,9 +160,6 @@ inlineCostFeatureToMlFeature(InlineCostFeatureIndex Feature) {
157160
return static_cast<FeatureIndex>(static_cast<size_t>(Feature));
158161
}
159162

160-
constexpr size_t NumberOfFeatures =
161-
static_cast<size_t>(FeatureIndex::NumberOfFeatures);
162-
163163
LLVM_ABI extern std::vector<TensorSpec> FeatureMap;
164164

165165
LLVM_ABI extern const char *const DecisionName;

llvm/lib/Analysis/MLInlineAdvisor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
473473
}
474474
// This one would have been set up to be right at the end.
475475
if (!InteractiveChannelBaseName.empty() && InteractiveIncludeDefault)
476-
*ModelRunner->getTensor<int64_t>(FeatureIndex::NumberOfFeatures) =
476+
*ModelRunner->getTensor<int64_t>((int)FeatureMap.size()) =
477477
GetDefaultAdvice(CB);
478478
return getAdviceFromModel(CB, ORE);
479479
}
@@ -552,7 +552,7 @@ void MLInlineAdvice::reportContextForRemark(
552552
DiagnosticInfoOptimizationBase &OR) {
553553
using namespace ore;
554554
OR << NV("Callee", Callee->getName());
555-
for (size_t I = 0; I < NumberOfFeatures; ++I)
555+
for (size_t I = 0; I < FeatureMap.size(); ++I)
556556
OR << NV(FeatureMap[I].name(),
557557
*getAdvisor()->getModelRunner().getTensor<int64_t>(I));
558558
OR << NV("ShouldInline", isInliningRecommended());

0 commit comments

Comments
 (0)