Commit a3984a12 by John Porto

Subzero. Outputs liveness memory usage.

BUG= R=stichnot@chromium.org Review URL: https://codereview.chromium.org/1850163003 .
parent 7bb9cab3
......@@ -1086,12 +1086,19 @@ void Cfg::emitIAS() {
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.
......
......@@ -226,9 +226,11 @@ public:
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();
......
......@@ -258,11 +258,14 @@ void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) {
#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 @@ void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) {
}
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";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment