• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_AOT_COMPILED_METHOD_H
17 #define COMPILER_AOT_COMPILED_METHOD_H
18 
19 #include "utils/arch.h"
20 #include "utils/span.h"
21 #include "compiler/code_info/code_info.h"
22 #include "compiler/optimizer/code_generator/callconv.h"
23 
24 #include <cstdint>
25 #include <vector>
26 
27 namespace ark {
28 class Method;
29 }  // namespace ark
30 
31 namespace ark::compiler {
32 class CompiledMethod {
33 public:
CompiledMethod(Arch arch,Method * method,size_t index)34     CompiledMethod(Arch arch, Method *method, size_t index) : arch_(arch), method_(method), index_(index) {}
35     NO_COPY_OPERATOR(CompiledMethod);
36     DEFAULT_COPY_CTOR(CompiledMethod);
37     DEFAULT_MOVE_SEMANTIC(CompiledMethod);
38     ~CompiledMethod() = default;
39 
SetCode(Span<const uint8_t> data)40     void SetCode(Span<const uint8_t> data)
41     {
42         code_.reserve(data.size());
43         std::copy(data.begin(), data.end(), std::back_inserter(code_));
44     }
45 
SetCodeInfo(Span<const uint8_t> data)46     void SetCodeInfo(Span<const uint8_t> data)
47     {
48         codeInfo_.reserve(data.size());
49         std::copy(data.begin(), data.end(), std::back_inserter(codeInfo_));
50     }
51 
GetMethod()52     Method *GetMethod()
53     {
54         return method_;
55     }
56 
GetMethod()57     const Method *GetMethod() const
58     {
59         return method_;
60     }
61 
GetCode()62     Span<const uint8_t> GetCode() const
63     {
64         return Span(code_);
65     }
66 
GetCodeInfo()67     Span<const uint8_t> GetCodeInfo() const
68     {
69         return Span(codeInfo_);
70     }
71 
GetOverallSize()72     size_t GetOverallSize() const
73     {
74         return RoundUp(CodePrefix::STRUCT_SIZE, GetCodeAlignment(arch_)) + RoundUp(code_.size(), CodeInfo::ALIGNMENT) +
75                RoundUp(codeInfo_.size(), CodeInfo::SIZE_ALIGNMENT);
76     }
77 
GetIndex()78     size_t GetIndex() const
79     {
80         return index_;
81     }
82 
83 #ifdef PANDA_COMPILER_DEBUG_INFO
GetCfiInfo()84     const CfiInfo &GetCfiInfo() const
85     {
86         return cfiInfo_;
87     }
88 
GetCfiInfo()89     CfiInfo &GetCfiInfo()
90     {
91         return cfiInfo_;
92     }
93 
SetCfiInfo(const CfiInfo & cfiInfo)94     void SetCfiInfo(const CfiInfo &cfiInfo)
95     {
96         cfiInfo_ = cfiInfo;
97     }
98 #endif
99 
100 private:
101     Arch arch_ {RUNTIME_ARCH};
102     Method *method_ {nullptr};
103     size_t index_ {0};
104     std::vector<uint8_t> code_;
105     std::vector<uint8_t> codeInfo_;
106 #ifdef PANDA_COMPILER_DEBUG_INFO
107     CfiInfo cfiInfo_;
108 #endif
109 };
110 }  // namespace ark::compiler
111 
112 #endif  // COMPILER_AOT_COMPILED_METHOD_H
113