From 7355c600342f04cb33e7a2730edcbcebfc8447e8 Mon Sep 17 00:00:00 2001 From: Peter Rong Date: Mon, 13 Jan 2025 16:26:43 -0800 Subject: [PATCH 1/2] [ML Inliner] Fix inconsistancy between CallGraph and FunctionLevels When building our internal code, one of the function annotated with `co_await` (c++20) will cause inconsistancy: The function exists in CG but not FunctionLevels. This patch fixes it by using FunctionLevels only. Signed-off-by: Peter Rong --- llvm/lib/Analysis/MLInlineAdvisor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp index 2db58d1c2578b..68d8f794d2389 100644 --- a/llvm/lib/Analysis/MLInlineAdvisor.cpp +++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp @@ -189,7 +189,9 @@ MLInlineAdvisor::MLInlineAdvisor( } unsigned MLInlineAdvisor::getInitialFunctionLevel(const Function &F) const { - return CG.lookup(F) ? FunctionLevels.at(CG.lookup(F)) : 0; + return FunctionLevels.find(CG.lookup(F)) != FunctionLevels.end() + ? FunctionLevels.at(CG.lookup(F)) + : 0; } void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *CurSCC) { From c668980be21052992aa3936c60d4c025f7f54c42 Mon Sep 17 00:00:00 2001 From: Peter Rong Date: Mon, 13 Jan 2025 16:45:59 -0800 Subject: [PATCH 2/2] Update llvm/lib/Analysis/MLInlineAdvisor.cpp Co-authored-by: Ellis Hoag --- llvm/lib/Analysis/MLInlineAdvisor.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp index 68d8f794d2389..d41631c2782f0 100644 --- a/llvm/lib/Analysis/MLInlineAdvisor.cpp +++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp @@ -189,9 +189,10 @@ MLInlineAdvisor::MLInlineAdvisor( } unsigned MLInlineAdvisor::getInitialFunctionLevel(const Function &F) const { - return FunctionLevels.find(CG.lookup(F)) != FunctionLevels.end() - ? FunctionLevels.at(CG.lookup(F)) - : 0; + auto It = FunctionLevels.find(CG.lookup(F)); + if (It == FunctionLevels.end()) + return 0; + return *It; } void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *CurSCC) {