From f1cc7b81db4203464d533099d983108c2a1f67e4 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 | 21 +++++++------------ .../optimizer/optimizations/ecma_inlining.h | 7 ++++--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/compiler/optimizer/optimizations/ecma_inlining.cpp b/compiler/optimizer/optimizations/ecma_inlining.cpp index c1ba5e6e8..baf367307 100644 --- a/compiler/optimizer/optimizations/ecma_inlining.cpp +++ b/compiler/optimizer/optimizations/ecma_inlining.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -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..73774bf06 100644 --- a/compiler/optimizer/optimizations/ecma_inlining.h +++ b/compiler/optimizer/optimizations/ecma_inlining.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -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