1 /** 2 * Copyright (c) 2021-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 #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 panda::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 * arena_allocator,const Graph * graph)36 static MethodProperties *Create(ArenaAllocator *arena_allocator, const Graph *graph) 37 { 38 return arena_allocator->New<MethodProperties>(graph); 39 } 40 41 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 42 #define MPROP_GET_FIELD(name, type) \ 43 type Get##name() const \ 44 { \ 45 return name::Get(fields_); \ 46 } 47 48 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 49 #define MPROP_SET_FIELD(name, type) \ 50 void Set##name(type val) \ 51 { \ 52 name::Set(val, &fields_); \ 53 } 54 55 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) 56 #define MPROP_FIELD(name, type) \ 57 MPROP_GET_FIELD(name, type) \ 58 MPROP_SET_FIELD(name, type) 59 60 using FieldsTy = uint32_t; 61 62 MPROP_FIELD(CanThrow, bool); 63 MPROP_FIELD(HasCalls, bool); 64 MPROP_FIELD(HasLibCalls, bool); 65 MPROP_FIELD(HasRuntimeCalls, bool); 66 MPROP_FIELD(HasSafepoints, bool); 67 MPROP_FIELD(HasRequireState, bool); 68 MPROP_FIELD(HasDeopt, bool); 69 MPROP_FIELD(HasParamsOnStack, bool); 70 MPROP_FIELD(CompactPrologueAllowed, bool); 71 MPROP_FIELD(RequireFrameSetup, bool); 72 73 using CanThrow = BitField<bool, 0, 1>; 74 using HasCalls = CanThrow::NextFlag; 75 using HasLibCalls = HasCalls::NextFlag; 76 using HasRuntimeCalls = HasLibCalls::NextFlag; 77 using HasSafepoints = HasRuntimeCalls::NextFlag; 78 using HasRequireState = HasSafepoints::NextFlag; 79 using HasDeopt = HasRequireState::NextFlag; 80 using HasParamsOnStack = HasDeopt::NextFlag; 81 using CompactPrologueAllowed = HasParamsOnStack::NextFlag; 82 using RequireFrameSetup = CompactPrologueAllowed::NextFlag; 83 IsLeaf()84 bool IsLeaf() const 85 { 86 return !GetHasCalls() && !GetHasRuntimeCalls() && !GetHasLibCalls() && !GetHasRequireState() && !GetCanThrow(); 87 } 88 GetLastReturn()89 Inst *GetLastReturn() const 90 { 91 return last_return_; 92 } 93 94 #undef MPROP_GET_FIELD 95 #undef MPROP_SET_FIELD 96 #undef MPROP_FIELD 97 98 private: 99 Inst *last_return_ {nullptr}; 100 FieldsTy fields_ {0}; 101 }; 102 } // namespace panda::compiler 103 104 #endif // COMPILER_OPTIMIZER_CODEGEN_METHOD_PROPERTIES_H 105