From f69dee553066f113f6b36874c114e83d0922b4b8 Mon Sep 17 00:00:00 2001 From: Daniel Kofanov Date: Wed, 1 Nov 2023 18:23:21 +0300 Subject: [PATCH] [Compiler] Introduce new inlining policy Signed-off-by: Daniel Kofanov --- .../optimizer/optimizations/ecma_inlining.cpp | 19 ++++++------------- .../optimizer/optimizations/ecma_inlining.h | 5 +++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/compiler/optimizer/optimizations/ecma_inlining.cpp b/compiler/optimizer/optimizations/ecma_inlining.cpp index c1ba5e6e8..9a2a2ff04 100644 --- a/compiler/optimizer/optimizations/ecma_inlining.cpp +++ b/compiler/optimizer/optimizations/ecma_inlining.cpp @@ -25,8 +25,9 @@ namespace ark::compiler::ecmascript { -EcmaInlining::EcmaInlining(Graph *graph, uint32_t instructionsCount, uint32_t inlineDepth, uint32_t methodsInlined) - : Inlining(graph, instructionsCount, inlineDepth, methodsInlined), +EcmaInlining::EcmaInlining(Graph *graph, uint32_t instructionsCount, uint32_t methodsInlined, + const ArenaVector *inlinedStack) + : Inlining(graph, instructionsCount, methodsInlined, inlinedStack), jsFunctions_(graph->GetLocalAllocator()->Adapter()) { instructionsLimit_ = g_options.GetCompilerEcmaInliningMaxInsts(); @@ -113,7 +114,7 @@ Graph *EcmaInlining::BuildGraph(InlineContext *ctx, CallInst *callInst, CallInst // Propagate instruction id counter to inlined graph, thereby avoid instructions id duplication graphInl->SetCurrentInstructionId(GetGraph()->GetCurrentInstructionId()); - graphInl->SetMaxInliningDepth(depth_); + graphInl->SetMaxInliningDepth(GetCurrentDepth()); auto stats = GetGraph()->GetPassManager()->GetStatistics(); auto savedPbcInstNum = stats->GetPbcInstNum(); @@ -132,16 +133,8 @@ Graph *EcmaInlining::BuildGraph(InlineContext *ctx, CallInst *callInst, CallInst // Don't inline if we reach the limit of instructions and method is big enough. auto inlinedInstsCount = CalculateInstructionsCount(graphInl); - if (!CheckInstructionLimit(callInst, ctx, inlinedInstsCount)) { - stats->SetPbcInstNum(savedPbcInstNum); - [[maybe_unused]] auto runtime = GetGraph()->GetRuntime(); - EVENT_INLINE(runtime->GetMethodFullName(GetGraph()->GetMethod()), runtime->GetMethodFullName(ctx->method), - callInst->GetId(), events::InlineKind::DYNAMIC_MONOMORPHIC, events::InlineResult::LIMIT); - LOG_INLINING(DEBUG) << "Reach the limit of instructions and method is big enough."; - return nullptr; - } - if ((depth_ + 1) < g_options.GetCompilerInliningMaxDepth()) { - graphInl->RunPass(instructionsCount_ + inlinedInstsCount, depth_ + 1, methodsInlined_ + 1); + if ((GetCurrentDepth() + 1U) < g_options.GetCompilerInliningMaxDepth()) { + graphInl->RunPass(instructionsCount_ + inlinedInstsCount, methodsInlined_ + 1U, &inlinedStack_); } instructionsCount_ += CalculateInstructionsCount(graphInl); GetGraph()->SetMaxMarkerIdx(graphInl->GetCurrentMarkerIdx()); diff --git a/compiler/optimizer/optimizations/ecma_inlining.h b/compiler/optimizer/optimizations/ecma_inlining.h index 871bd96a3..120843e01 100644 --- a/compiler/optimizer/optimizations/ecma_inlining.h +++ b/compiler/optimizer/optimizations/ecma_inlining.h @@ -25,8 +25,9 @@ class EcmaInlining : public Inlining { public: using Inlining::Inlining; - explicit EcmaInlining(Graph *graph, uint32_t instructionsCount, uint32_t inlineDepth, uint32_t methodsInlined); - explicit EcmaInlining(Graph *graph) : EcmaInlining(graph, 0, 0, 0) {}; + explicit EcmaInlining(Graph *graph, uint32_t instructionsCount, uint32_t methodsInlined, + const ArenaVector *inlinedStack); + explicit EcmaInlining(Graph *graph) : EcmaInlining(graph, 0, 0, nullptr) {}; NO_MOVE_SEMANTIC(EcmaInlining); NO_COPY_SEMANTIC(EcmaInlining); -- Gitee