Subzero. Outputs liveness memory usage.
BUG=
R=stichnot@chromium.org
Review URL: https://codereview.chromium.org/1850163003 .
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index b42f326..1965fe2 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -1086,12 +1086,19 @@
emitJumpTables();
}
-size_t Cfg::getTotalMemoryMB() {
- constexpr size_t OneMB = 1024 * 1024;
- using ArbitraryType = int;
- // CfgLocalAllocator draws from the same memory pool regardless of allocated
- // object type, so pick an arbitrary type for the template parameter.
- return CfgLocalAllocator<ArbitraryType>().current()->getTotalMemory() / OneMB;
+size_t Cfg::getTotalMemoryMB() const {
+ constexpr size_t _1MB = 1024 * 1024;
+ assert(Allocator != nullptr);
+ assert(CfgAllocatorTraits::current() == Allocator.get());
+ return Allocator->getTotalMemory() / _1MB;
+}
+
+size_t Cfg::getLivenessMemoryMB() const {
+ constexpr size_t _1MB = 1024 * 1024;
+ if (Live == nullptr) {
+ return 0;
+ }
+ return Live->getAllocator()->getTotalMemory() / _1MB;
}
// Dumps the IR with an optional introductory message.
diff --git a/src/IceCfg.h b/src/IceCfg.h
index f6f3309..f9682e0 100644
--- a/src/IceCfg.h
+++ b/src/IceCfg.h
@@ -226,9 +226,11 @@
const CfgNode *getCurrentNode() const { return CurrentNode; }
/// @}
- /// Get the total amount of memory held by the per-Cfg allocator. This is
- /// mostly meant for use inside a debugger.
- static size_t getTotalMemoryMB();
+ /// Get the total amount of memory held by the per-Cfg allocator.
+ size_t getTotalMemoryMB() const;
+
+ /// Get the current memory usage due to liveness data structures.
+ size_t getLivenessMemoryMB() const;
void emit();
void emitIAS();
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index b85b470..bacaec3 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -258,11 +258,14 @@
#undef X
Str << "|" << Name << "|Spills+Fills|"
<< Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n";
- Str << "|" << Name << "|Memory Usage|";
- if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed())
- Str << MemUsed;
- else
+ Str << "|" << Name << "|Memory Usage |";
+ if (const auto MemUsed = static_cast<size_t>(
+ llvm::TimeRecord::getCurrentTime(false).getMemUsed())) {
+ static constexpr size_t _1MB = 1024 * 1024;
+ Str << (MemUsed / _1MB) << " MB";
+ } else {
Str << "(requires '-track-memory')";
+ }
Str << "\n";
Str << "|" << Name << "|CPool Sizes ";
{
@@ -279,7 +282,9 @@
}
Str << "\n";
if (Func != nullptr) {
- Str << "|" << Name << "|Cfg Memory |" << Func->getTotalMemoryMB()
+ Str << "|" << Name << "|Cfg Memory |" << Func->getTotalMemoryMB()
+ << " MB\n";
+ Str << "|" << Name << "|Liveness Memory |" << Func->getLivenessMemoryMB()
<< " MB\n";
}
}