Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Plugins / Process / Utility / RegisterContextPOSIX_mips64.cpp
blob9e05737d8e6213554edd7179d29338add6b592cf
1 //===-- RegisterContextPOSIX_mips64.cpp -----------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <cerrno>
10 #include <cstdint>
11 #include <cstring>
13 #include "lldb/Target/Process.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Target/Thread.h"
16 #include "lldb/Utility/DataBufferHeap.h"
17 #include "lldb/Utility/DataExtractor.h"
18 #include "lldb/Utility/Endian.h"
19 #include "lldb/Utility/RegisterValue.h"
20 #include "lldb/Utility/Scalar.h"
21 #include "llvm/Support/Compiler.h"
23 #include "RegisterContextPOSIX_mips64.h"
24 #include "RegisterContextFreeBSD_mips64.h"
26 using namespace lldb_private;
27 using namespace lldb;
29 bool RegisterContextPOSIX_mips64::IsGPR(unsigned reg) {
30 return reg < m_registers_count[gpr_registers_count]; // GPR's come first.
33 bool RegisterContextPOSIX_mips64::IsFPR(unsigned reg) {
34 int set = GetRegisterSetCount();
35 if (set > 1)
36 return reg < (m_registers_count[fpr_registers_count]
37 + m_registers_count[gpr_registers_count]);
38 return false;
41 RegisterContextPOSIX_mips64::RegisterContextPOSIX_mips64(
42 Thread &thread, uint32_t concrete_frame_idx,
43 RegisterInfoInterface *register_info)
44 : RegisterContext(thread, concrete_frame_idx) {
45 m_register_info_up.reset(register_info);
46 m_num_registers = GetRegisterCount();
47 int set = GetRegisterSetCount();
49 const RegisterSet *reg_set_ptr;
50 for(int i = 0; i < set; ++i) {
51 reg_set_ptr = GetRegisterSet(i);
52 m_registers_count[i] = reg_set_ptr->num_registers;
55 assert(m_num_registers ==
56 static_cast<uint32_t>(m_registers_count[gpr_registers_count] +
57 m_registers_count[fpr_registers_count] +
58 m_registers_count[msa_registers_count]));
61 RegisterContextPOSIX_mips64::~RegisterContextPOSIX_mips64() = default;
63 void RegisterContextPOSIX_mips64::Invalidate() {}
65 void RegisterContextPOSIX_mips64::InvalidateAllRegisters() {}
67 unsigned RegisterContextPOSIX_mips64::GetRegisterOffset(unsigned reg) {
68 assert(reg < m_num_registers && "Invalid register number.");
69 return GetRegisterInfo()[reg].byte_offset;
72 unsigned RegisterContextPOSIX_mips64::GetRegisterSize(unsigned reg) {
73 assert(reg < m_num_registers && "Invalid register number.");
74 return GetRegisterInfo()[reg].byte_size;
77 size_t RegisterContextPOSIX_mips64::GetRegisterCount() {
78 return m_register_info_up->GetRegisterCount();
81 size_t RegisterContextPOSIX_mips64::GetGPRSize() {
82 return m_register_info_up->GetGPRSize();
85 const RegisterInfo *RegisterContextPOSIX_mips64::GetRegisterInfo() {
86 // Commonly, this method is overridden and g_register_infos is copied and
87 // specialized. So, use GetRegisterInfo() rather than g_register_infos in
88 // this scope.
89 return m_register_info_up->GetRegisterInfo();
92 const RegisterInfo *
93 RegisterContextPOSIX_mips64::GetRegisterInfoAtIndex(size_t reg) {
94 if (reg < m_num_registers)
95 return &GetRegisterInfo()[reg];
96 else
97 return nullptr;
100 size_t RegisterContextPOSIX_mips64::GetRegisterSetCount() {
101 ArchSpec target_arch = m_register_info_up->GetTargetArchitecture();
102 switch (target_arch.GetTriple().getOS()) {
103 default: {
104 const auto *context = static_cast<const RegisterContextFreeBSD_mips64 *>(
105 m_register_info_up.get());
106 return context->GetRegisterSetCount();
112 const RegisterSet *RegisterContextPOSIX_mips64::GetRegisterSet(size_t set) {
113 ArchSpec target_arch = m_register_info_up->GetTargetArchitecture();
114 switch (target_arch.GetTriple().getOS()) {
115 default: {
116 const auto *context = static_cast<const RegisterContextFreeBSD_mips64 *>(
117 m_register_info_up.get());
118 return context->GetRegisterSet(set);
123 const char *RegisterContextPOSIX_mips64::GetRegisterName(unsigned reg) {
124 assert(reg < m_num_registers && "Invalid register offset.");
125 return GetRegisterInfo()[reg].name;
128 bool RegisterContextPOSIX_mips64::IsRegisterSetAvailable(size_t set_index) {
129 size_t num_sets = GetRegisterSetCount();
131 return (set_index < num_sets);
134 // Used when parsing DWARF and EH frame information and any other object file
135 // sections that contain register numbers in them.
136 uint32_t RegisterContextPOSIX_mips64::ConvertRegisterKindToRegisterNumber(
137 lldb::RegisterKind kind, uint32_t num) {
138 const uint32_t num_regs = m_num_registers;
140 assert(kind < kNumRegisterKinds);
141 for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
142 const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
144 if (reg_info->kinds[kind] == num)
145 return reg_idx;
148 return LLDB_INVALID_REGNUM;