2727#include " llvm/Analysis/ProfileSummaryInfo.h"
2828#include " llvm/Analysis/ReleaseModeModelRunner.h"
2929#include " llvm/Analysis/TargetTransformInfo.h"
30+ #include " llvm/Analysis/TensorSpec.h"
3031#include " llvm/IR/Dominators.h"
3132#include " llvm/IR/InstIterator.h"
3233#include " llvm/IR/Module.h"
@@ -77,10 +78,10 @@ llvm::getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM,
7778 std::unique_ptr<MLModelRunner> AOTRunner;
7879 if (InteractiveChannelBaseName.empty ())
7980 AOTRunner = std::make_unique<ReleaseModeModelRunner<CompiledModelType>>(
80- M.getContext (), FeatureMap , DecisionName,
81+ M.getContext (), getFeatureMap () , DecisionName,
8182 EmbeddedModelRunnerOptions ().setModelSelector (ModelSelector));
8283 else {
83- auto Features = FeatureMap ;
84+ auto Features = getFeatureMap () ;
8485 if (InteractiveIncludeDefault)
8586 Features.push_back (DefaultDecisionSpec);
8687 AOTRunner = std::make_unique<InteractiveModelRunner>(
@@ -106,8 +107,9 @@ static cl::opt<bool> KeepFPICache(
106107 " For test - keep the ML Inline advisor's FunctionPropertiesInfo cache" ),
107108 cl::init(false ));
108109
109- // clang-format off
110- std::vector<TensorSpec> llvm::FeatureMap{
110+ std::vector<TensorSpec> &llvm::getFeatureMap () {
111+ // clang-format off
112+ static std::vector<TensorSpec> FeatureMap{
111113#define POPULATE_NAMES (DTYPE, SHAPE, NAME, __ ) TensorSpec::createSpec<DTYPE>(#NAME, SHAPE),
112114// InlineCost features - these must come first
113115 INLINE_COST_FEATURE_ITERATOR (POPULATE_NAMES)
@@ -116,7 +118,9 @@ std::vector<TensorSpec> llvm::FeatureMap{
116118 INLINE_FEATURE_ITERATOR (POPULATE_NAMES)
117119#undef POPULATE_NAMES
118120};
119- // clang-format on
121+ // clang-format on
122+ return FeatureMap;
123+ }
120124
121125const char *const llvm::DecisionName = " inlining_decision" ;
122126const TensorSpec llvm::InlineDecisionSpec =
@@ -195,9 +199,9 @@ MLInlineAdvisor::MLInlineAdvisor(
195199 }
196200 // Add the IR2Vec features to the feature map
197201 auto IR2VecDim = IR2VecVocabResult->getDimension ();
198- FeatureMap .push_back (
202+ getFeatureMap () .push_back (
199203 TensorSpec::createSpec<float >(" callee_embedding" , {IR2VecDim}));
200- FeatureMap .push_back (
204+ getFeatureMap () .push_back (
201205 TensorSpec::createSpec<float >(" caller_embedding" , {IR2VecDim}));
202206 }
203207}
@@ -471,7 +475,8 @@ std::unique_ptr<InlineAdvice> MLInlineAdvisor::getAdviceImpl(CallBase &CB) {
471475 }
472476 // This one would have been set up to be right at the end.
473477 if (!InteractiveChannelBaseName.empty () && InteractiveIncludeDefault)
474- *ModelRunner->getTensor <int64_t >(FeatureMap.size ()) = GetDefaultAdvice (CB);
478+ *ModelRunner->getTensor <int64_t >(getFeatureMap ().size ()) =
479+ GetDefaultAdvice (CB);
475480 return getAdviceFromModel (CB, ORE);
476481}
477482
@@ -549,8 +554,8 @@ void MLInlineAdvice::reportContextForRemark(
549554 DiagnosticInfoOptimizationBase &OR) {
550555 using namespace ore ;
551556 OR << NV (" Callee" , Callee->getName ());
552- for (size_t I = 0 ; I < FeatureMap .size (); ++I)
553- OR << NV (FeatureMap [I].name (),
557+ for (size_t I = 0 ; I < getFeatureMap () .size (); ++I)
558+ OR << NV (getFeatureMap () [I].name (),
554559 *getAdvisor ()->getModelRunner ().getTensor <int64_t >(I));
555560 OR << NV (" ShouldInline" , isInliningRecommended ());
556561}
0 commit comments