• 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_OPTIMIZER_CODEGEN_METHOD_PROPERTIES_H
17 #define COMPILER_OPTIMIZER_CODEGEN_METHOD_PROPERTIES_H
18 
19 #include <cstddef>
20 #include <iostream>
21 #include "libpandabase/mem/arena_allocator.h"
22 #include "libpandabase/utils/bit_field.h"
23 
24 namespace ark::compiler {
25 class Graph;
26 
27 class MethodProperties {
28 public:
29     explicit MethodProperties(const Graph *graph);
30     MethodProperties(const MethodProperties &) = default;
31     MethodProperties &operator=(const MethodProperties &) = default;
32     MethodProperties(MethodProperties &&) = default;
33     MethodProperties &operator=(MethodProperties &&) = default;
34     ~MethodProperties() = default;
35 
Create(ArenaAllocator * arenaAllocator,const Graph * graph)36     static MethodProperties *Create(ArenaAllocator *arenaAllocator, const Graph *graph)
37     {
38         return arenaAllocator->New<MethodProperties>(graph);
39     }
40 
41 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
42 #define MPROP_GET_FIELD(name, type)                                        \
43     type Get##name() const                                                 \
44     {                                                                      \
45         /* CC-OFFNXT(G.PRE.05, G.PRE.02) function gen, namespace member */ \
46         return name::Get(fields_);                                         \
47     }
48 
49 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
50 #define MPROP_SET_FIELD(name, type)                \
51     void Set##name(type val)                       \
52     {                                              \
53         /* CC-OFFNXT(G.PRE.02) namespace member */ \
54         name::Set(val, &fields_);                  \
55     }
56 
57 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
58 #define MPROP_FIELD(name, type) \
59     MPROP_GET_FIELD(name, type) \
60     MPROP_SET_FIELD(name, type)
61 
62     using FieldsTy = uint32_t;
63 
64     MPROP_FIELD(CanThrow, bool);
65     MPROP_FIELD(HasCalls, bool);
66     MPROP_FIELD(HasLibCalls, bool);
67     MPROP_FIELD(HasRuntimeCalls, bool);
68     MPROP_FIELD(HasSafepoints, bool);
69     MPROP_FIELD(HasRequireState, bool);
70     MPROP_FIELD(HasDeopt, bool);
71     MPROP_FIELD(HasParamsOnStack, bool);
72     MPROP_FIELD(CompactPrologueAllowed, bool);
73     MPROP_FIELD(RequireFrameSetup, bool);
74 
75     using CanThrow = BitField<bool, 0, 1>;
76     using HasCalls = CanThrow::NextFlag;
77     using HasLibCalls = HasCalls::NextFlag;
78     using HasRuntimeCalls = HasLibCalls::NextFlag;
79     using HasSafepoints = HasRuntimeCalls::NextFlag;
80     using HasRequireState = HasSafepoints::NextFlag;
81     using HasDeopt = HasRequireState::NextFlag;
82     using HasParamsOnStack = HasDeopt::NextFlag;
83     using CompactPrologueAllowed = HasParamsOnStack::NextFlag;
84     using RequireFrameSetup = CompactPrologueAllowed::NextFlag;
85 
IsLeaf()86     bool IsLeaf() const
87     {
88         return !GetHasCalls() && !GetHasRuntimeCalls() && !GetHasLibCalls() && !GetHasRequireState() && !GetCanThrow();
89     }
90 
GetLastReturn()91     Inst *GetLastReturn() const
92     {
93         return lastReturn_;
94     }
95 
96 #undef MPROP_GET_FIELD
97 #undef MPROP_SET_FIELD
98 #undef MPROP_FIELD
99 
100 private:
101     void CheckAndSetStackParams(Inst *inst);
102 
103 private:
104     Inst *lastReturn_ {nullptr};
105     FieldsTy fields_ {0};
106 };
107 }  // namespace ark::compiler
108 
109 #endif  // COMPILER_OPTIMIZER_CODEGEN_METHOD_PROPERTIES_H
110