[MLIR][NVVM] Add Op for TMA Store with reduction (#118853)
[llvm-project.git] / lldb / source / API / SBMemoryRegionInfo.cpp
blobcd25be5d527696e906bc9add4685c015ee489534
1 //===-- SBMemoryRegionInfo.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 "lldb/API/SBMemoryRegionInfo.h"
10 #include "Utils.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBError.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/Target/MemoryRegionInfo.h"
15 #include "lldb/Utility/Instrumentation.h"
16 #include "lldb/Utility/StreamString.h"
17 #include <optional>
19 using namespace lldb;
20 using namespace lldb_private;
22 SBMemoryRegionInfo::SBMemoryRegionInfo() : m_opaque_up(new MemoryRegionInfo()) {
23 LLDB_INSTRUMENT_VA(this);
26 SBMemoryRegionInfo::SBMemoryRegionInfo(const char *name, lldb::addr_t begin,
27 lldb::addr_t end, uint32_t permissions,
28 bool mapped, bool stack_memory)
29 : SBMemoryRegionInfo() {
30 LLDB_INSTRUMENT_VA(this, name, begin, end, permissions, mapped, stack_memory);
31 m_opaque_up->SetName(name);
32 m_opaque_up->GetRange().SetRangeBase(begin);
33 m_opaque_up->GetRange().SetRangeEnd(end);
34 m_opaque_up->SetLLDBPermissions(permissions);
35 m_opaque_up->SetMapped(mapped ? MemoryRegionInfo::eYes
36 : MemoryRegionInfo::eNo);
37 m_opaque_up->SetIsStackMemory(stack_memory ? MemoryRegionInfo::eYes
38 : MemoryRegionInfo::eNo);
41 SBMemoryRegionInfo::SBMemoryRegionInfo(const MemoryRegionInfo *lldb_object_ptr)
42 : m_opaque_up(new MemoryRegionInfo()) {
43 if (lldb_object_ptr)
44 ref() = *lldb_object_ptr;
47 SBMemoryRegionInfo::SBMemoryRegionInfo(const SBMemoryRegionInfo &rhs) {
48 LLDB_INSTRUMENT_VA(this, rhs);
49 m_opaque_up = clone(rhs.m_opaque_up);
52 const SBMemoryRegionInfo &SBMemoryRegionInfo::
53 operator=(const SBMemoryRegionInfo &rhs) {
54 LLDB_INSTRUMENT_VA(this, rhs);
56 if (this != &rhs)
57 m_opaque_up = clone(rhs.m_opaque_up);
58 return *this;
61 SBMemoryRegionInfo::~SBMemoryRegionInfo() = default;
63 void SBMemoryRegionInfo::Clear() {
64 LLDB_INSTRUMENT_VA(this);
66 m_opaque_up->Clear();
69 bool SBMemoryRegionInfo::operator==(const SBMemoryRegionInfo &rhs) const {
70 LLDB_INSTRUMENT_VA(this, rhs);
72 return ref() == rhs.ref();
75 bool SBMemoryRegionInfo::operator!=(const SBMemoryRegionInfo &rhs) const {
76 LLDB_INSTRUMENT_VA(this, rhs);
78 return ref() != rhs.ref();
81 MemoryRegionInfo &SBMemoryRegionInfo::ref() { return *m_opaque_up; }
83 const MemoryRegionInfo &SBMemoryRegionInfo::ref() const { return *m_opaque_up; }
85 lldb::addr_t SBMemoryRegionInfo::GetRegionBase() {
86 LLDB_INSTRUMENT_VA(this);
88 return m_opaque_up->GetRange().GetRangeBase();
91 lldb::addr_t SBMemoryRegionInfo::GetRegionEnd() {
92 LLDB_INSTRUMENT_VA(this);
94 return m_opaque_up->GetRange().GetRangeEnd();
97 bool SBMemoryRegionInfo::IsReadable() {
98 LLDB_INSTRUMENT_VA(this);
100 return m_opaque_up->GetReadable() == MemoryRegionInfo::eYes;
103 bool SBMemoryRegionInfo::IsWritable() {
104 LLDB_INSTRUMENT_VA(this);
106 return m_opaque_up->GetWritable() == MemoryRegionInfo::eYes;
109 bool SBMemoryRegionInfo::IsExecutable() {
110 LLDB_INSTRUMENT_VA(this);
112 return m_opaque_up->GetExecutable() == MemoryRegionInfo::eYes;
115 bool SBMemoryRegionInfo::IsMapped() {
116 LLDB_INSTRUMENT_VA(this);
118 return m_opaque_up->GetMapped() == MemoryRegionInfo::eYes;
121 const char *SBMemoryRegionInfo::GetName() {
122 LLDB_INSTRUMENT_VA(this);
124 return m_opaque_up->GetName().AsCString();
127 bool SBMemoryRegionInfo::HasDirtyMemoryPageList() {
128 LLDB_INSTRUMENT_VA(this);
130 return m_opaque_up->GetDirtyPageList().has_value();
133 uint32_t SBMemoryRegionInfo::GetNumDirtyPages() {
134 LLDB_INSTRUMENT_VA(this);
136 uint32_t num_dirty_pages = 0;
137 const std::optional<std::vector<addr_t>> &dirty_page_list =
138 m_opaque_up->GetDirtyPageList();
139 if (dirty_page_list)
140 num_dirty_pages = dirty_page_list->size();
142 return num_dirty_pages;
145 addr_t SBMemoryRegionInfo::GetDirtyPageAddressAtIndex(uint32_t idx) {
146 LLDB_INSTRUMENT_VA(this, idx);
148 addr_t dirty_page_addr = LLDB_INVALID_ADDRESS;
149 const std::optional<std::vector<addr_t>> &dirty_page_list =
150 m_opaque_up->GetDirtyPageList();
151 if (dirty_page_list && idx < dirty_page_list->size())
152 dirty_page_addr = (*dirty_page_list)[idx];
154 return dirty_page_addr;
157 int SBMemoryRegionInfo::GetPageSize() {
158 LLDB_INSTRUMENT_VA(this);
160 return m_opaque_up->GetPageSize();
163 bool SBMemoryRegionInfo::GetDescription(SBStream &description) {
164 LLDB_INSTRUMENT_VA(this, description);
166 Stream &strm = description.ref();
167 const addr_t load_addr = m_opaque_up->GetRange().base;
169 strm.Printf("[0x%16.16" PRIx64 "-0x%16.16" PRIx64 " ", load_addr,
170 load_addr + m_opaque_up->GetRange().size);
171 strm.Printf(m_opaque_up->GetReadable() ? "R" : "-");
172 strm.Printf(m_opaque_up->GetWritable() ? "W" : "-");
173 strm.Printf(m_opaque_up->GetExecutable() ? "X" : "-");
174 strm.Printf("]");
176 return true;