• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 #ifndef COMPILER_COMPILE_METHOD_H
17 #define COMPILER_COMPILE_METHOD_H
18 
19 #include "compiler_options.h"
20 #include "mem/arena_allocator.h"
21 #include "mem/code_allocator.h"
22 #include "include/method.h"
23 #include "utils/arch.h"
24 #include "compiler_task_runner.h"
25 
26 namespace panda::compiler {
27 class Graph;
28 class RuntimeInterface;
29 
30 class JITStats {
31 public:
JITStats(mem::InternalAllocatorPtr internalAllocator)32     explicit JITStats(mem::InternalAllocatorPtr internalAllocator)
33         : internalAllocator_(internalAllocator), statsList_(internalAllocator->Adapter())
34     {
35     }
36     NO_MOVE_SEMANTIC(JITStats);
37     NO_COPY_SEMANTIC(JITStats);
~JITStats()38     ~JITStats()
39     {
40         DumpCsv();
41     }
42     void SetCompilationStart();
43     void EndCompilationWithStats(const std::string &methodName, bool isOsr, size_t bcSize, size_t codeSize);
44     void ResetCompilationStart();
45 
46 private:
47     void DumpCsv(char sep = ',');
48     struct Entry {
49         PandaString methodName;
50         bool isOsr;
51         size_t bcSize;
52         size_t codeSize;
53         uint64_t time;
54     };
55 
56 private:
57     mem::InternalAllocatorPtr internalAllocator_;
58     uint64_t startTime_ {};
59     std::vector<Entry, typename mem::AllocatorAdapter<Entry>> statsList_;
60 };
61 
62 Arch ChooseArch(Arch arch);
63 
64 // @tparam RUNNER_MODE=BACKGROUND_MODE means that compilation of method
65 // is divided into tasks for TaskManager and occurs in its threads.
66 // Otherwise compilation occurs in-place.
67 template <TaskRunnerMode RUNNER_MODE>
68 void JITCompileMethod(RuntimeInterface *runtime, CodeAllocator *codeAllocator, ArenaAllocator *gdbDebugInfoAllocator,
69                       JITStats *jitStats, CompilerTaskRunner<RUNNER_MODE> taskRunner);
70 template <TaskRunnerMode RUNNER_MODE>
71 void CompileInGraph(RuntimeInterface *runtime, bool isDynamic, Arch arch, CompilerTaskRunner<RUNNER_MODE> taskRunner,
72                     JITStats *jitStats = nullptr);
73 bool CheckMethodInLists(const std::string &methodName);
74 }  // namespace panda::compiler
75 
76 #endif  // COMPILER_COMPILE_METHOD_H
77