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() { ...@@ -1086,12 +1086,19 @@ void Cfg::emitIAS() {
emitJumpTables(); emitJumpTables();
} }
size_t Cfg::getTotalMemoryMB() { size_t Cfg::getTotalMemoryMB() const {
constexpr size_t OneMB = 1024 * 1024; constexpr size_t _1MB = 1024 * 1024;
using ArbitraryType = int; assert(Allocator != nullptr);
// CfgLocalAllocator draws from the same memory pool regardless of allocated assert(CfgAllocatorTraits::current() == Allocator.get());
// object type, so pick an arbitrary type for the template parameter. return Allocator->getTotalMemory() / _1MB;
return CfgLocalAllocator<ArbitraryType>().current()->getTotalMemory() / OneMB; }
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. // Dumps the IR with an optional introductory message.
......
...@@ -226,9 +226,11 @@ public: ...@@ -226,9 +226,11 @@ public:
const CfgNode *getCurrentNode() const { return CurrentNode; } const CfgNode *getCurrentNode() const { return CurrentNode; }
/// @} /// @}
/// Get the total amount of memory held by the per-Cfg allocator. This is /// Get the total amount of memory held by the per-Cfg allocator.
/// mostly meant for use inside a debugger. size_t getTotalMemoryMB() const;
static size_t getTotalMemoryMB();
/// Get the current memory usage due to liveness data structures.
size_t getLivenessMemoryMB() const;
void emit(); void emit();
void emitIAS(); void emitIAS();
......
...@@ -258,11 +258,14 @@ void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) { ...@@ -258,11 +258,14 @@ void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) {
#undef X #undef X
Str << "|" << Name << "|Spills+Fills|" Str << "|" << Name << "|Spills+Fills|"
<< Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n"; << Stats[CS_NumSpills] + Stats[CS_NumFills] << "\n";
Str << "|" << Name << "|Memory Usage|"; Str << "|" << Name << "|Memory Usage |";
if (ssize_t MemUsed = llvm::TimeRecord::getCurrentTime(false).getMemUsed()) if (const auto MemUsed = static_cast<size_t>(
Str << MemUsed; llvm::TimeRecord::getCurrentTime(false).getMemUsed())) {
else static constexpr size_t _1MB = 1024 * 1024;
Str << (MemUsed / _1MB) << " MB";
} else {
Str << "(requires '-track-memory')"; Str << "(requires '-track-memory')";
}
Str << "\n"; Str << "\n";
Str << "|" << Name << "|CPool Sizes "; Str << "|" << Name << "|CPool Sizes ";
{ {
...@@ -279,7 +282,9 @@ void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) { ...@@ -279,7 +282,9 @@ void GlobalContext::CodeStats::dump(const Cfg *Func, GlobalContext *Ctx) {
} }
Str << "\n"; Str << "\n";
if (Func != nullptr) { 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"; << " 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