1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ecmascript/compiler/compilation_driver.h"
17
18 namespace panda::ecmascript::kungfu {
UpdatePGO()19 void CompilationDriver::UpdatePGO()
20 {
21 std::unordered_set<EntityId> newMethodIds;
22 auto dfs = [this, &newMethodIds] (const CString &recordName,
23 const std::unordered_set<EntityId> &oldIds) -> std::unordered_set<EntityId> &{
24 newMethodIds.clear();
25 if (!jsPandaFile_->HasTSTypes(recordName)) {
26 return newMethodIds;
27 }
28 uint32_t mainMethodOffset = jsPandaFile_->GetMainMethodIndex(recordName);
29 SearchForCompilation(oldIds, newMethodIds, mainMethodOffset, false);
30 return newMethodIds;
31 };
32 pfLoader_.Update(dfs);
33 }
34
InitializeCompileQueue()35 void CompilationDriver::InitializeCompileQueue()
36 {
37 auto &mainMethodIndexes = bytecodeInfo_.GetMainMethodIndexes();
38 for (auto mainMethodIndex : mainMethodIndexes) {
39 compileQueue_.push(mainMethodIndex);
40 }
41 }
42
FilterMethod(const CString & recordName,const MethodLiteral * methodLiteral,const MethodPcInfo & methodPCInfo) const43 bool CompilationDriver::FilterMethod(const CString &recordName, const MethodLiteral *methodLiteral,
44 const MethodPcInfo &methodPCInfo) const
45 {
46 if (methodPCInfo.methodsSize > bytecodeInfo_.GetMaxMethodSize() ||
47 !pfLoader_.Match(recordName, methodLiteral->GetMethodId())) {
48 return true;
49 }
50 return false;
51 }
52 } // namespace panda::ecmascript::kungfu
53