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 PANDA_PROFILING_GEN_H 17#define PANDA_PROFILING_GEN_H 18 19#include "libpandafile/bytecode_instruction-inl.h" 20#include <array> 21 22namespace ark::profiling { 23 24% require 'set' 25% require_relative '../../templates/common.rb' 26 27enum class ProfilingKind { 28 NONE, 29% Panda::profiles.each do |name, _| 30 <%= name.snakecase.upcase %>, 31% end 32}; 33 34inline constexpr const char* GetProfilingKindName(ProfilingKind kind) 35{ 36 // NOLINTNEXTLINE(hicpp-multiway-paths-covered) 37 switch (kind) { 38% Panda::profiles.each do |prof, _| 39 case ProfilingKind::<%= prof.snakecase.upcase %>: 40 return "<%= prof.snakecase.upcase %>"; 41% end 42 default: 43 return "INVALID"; 44 } 45} 46 47% sizes = Panda::profiles.values.map(&:size).uniq.sort 48inline constexpr std::array<uint8_t, <%= sizes.size %>> GetOrderedProfileSizes() { 49 return {<%= sizes.join(', ') %>}; 50} 51 52inline size_t GetProfileSizeInBytes(BytecodeInstruction::Opcode opcode) 53{ 54 // NOLINTNEXTLINE(hicpp-multiway-paths-covered) 55 switch (opcode) { 56% Panda::instructions.select { |x| x.profiled? }.each do |inst| 57 case BytecodeInstruction::Opcode::<%= inst.opcode.upcase %>: 58 return <%= inst.profile.size %>; 59% end 60 default: 61 return 0; 62 } 63} 64 65inline ProfilingKind GetProfileKind(BytecodeInstruction::Opcode opcode) 66{ 67 // NOLINTNEXTLINE(hicpp-multiway-paths-covered) 68 switch (opcode) { 69% Panda::instructions.select { |x| x.profiled? }.each do |inst| 70 case BytecodeInstruction::Opcode::<%= inst.opcode.upcase %>: 71 return ProfilingKind::<%= inst.profile.name.snakecase.upcase %>; 72% end 73 default: 74 return ProfilingKind::NONE; 75 } 76} 77 78} // namespace ark::profiling 79 80#endif // PANDA_PROFILING_GEN_H 81