Commit 1c44d819 by Jim Stichnoth

Subzero: Disable stats and timers under the MINIMAL build.

Specifically, don't bother to collect "-timing" and "-szstats" information since they anyway don't get printed out under the MINIMAL build. This is done by using the ALLOW_DUMP flag to guard whether code and timing stats are collected. This ends up reducing the native translator size by about 3%. ALLOW_DUMP is used as the guard since it already guards the output of the collected data - no sense collecting the data if it can never be printed out. To minimize the number of ALLOW_DUMP tests, we push the tests into the timing/stats class methods. BUG= none R=jvoung@chromium.org, kschimpf@google.com Review URL: https://codereview.chromium.org/788713002
parent a49e9d9c
...@@ -68,11 +68,13 @@ bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } ...@@ -68,11 +68,13 @@ bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); }
void Cfg::translate() { void Cfg::translate() {
if (hasError()) if (hasError())
return; return;
const IceString &TimingFocusOn = getContext()->getFlags().TimingFocusOn; if (ALLOW_DUMP) {
if (TimingFocusOn == "*" || TimingFocusOn == getFunctionName()) { const IceString &TimingFocusOn = getContext()->getFlags().TimingFocusOn;
setFocusedTiming(); if (TimingFocusOn == "*" || TimingFocusOn == getFunctionName()) {
getContext()->resetTimer(GlobalContext::TSK_Default); setFocusedTiming();
getContext()->setTimerName(GlobalContext::TSK_Default, getFunctionName()); getContext()->resetTimer(GlobalContext::TSK_Default);
getContext()->setTimerName(GlobalContext::TSK_Default, getFunctionName());
}
} }
TimerMarker T(TimerStack::TT_translate, this); TimerMarker T(TimerStack::TT_translate, this);
......
...@@ -883,7 +883,7 @@ void Converter::convertFunctions() { ...@@ -883,7 +883,7 @@ void Converter::convertFunctions() {
continue; continue;
TimerIdT TimerID = 0; TimerIdT TimerID = 0;
if (Ctx->getFlags().TimeEachFunction) { if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction) {
TimerID = Ctx->getTimerID(StackID, I.getName()); TimerID = Ctx->getTimerID(StackID, I.getName());
Ctx->pushTimer(TimerID, StackID); Ctx->pushTimer(TimerID, StackID);
} }
...@@ -891,7 +891,7 @@ void Converter::convertFunctions() { ...@@ -891,7 +891,7 @@ void Converter::convertFunctions() {
Cfg *Fcn = FunctionConverter.convertFunction(&I); Cfg *Fcn = FunctionConverter.convertFunction(&I);
translateFcn(Fcn); translateFcn(Fcn);
if (Ctx->getFlags().TimeEachFunction) if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction)
Ctx->popTimer(TimerID, StackID); Ctx->popTimer(TimerID, StackID);
} }
......
...@@ -114,8 +114,10 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit, ...@@ -114,8 +114,10 @@ GlobalContext::GlobalContext(Ostream *OsDump, Ostream *OsEmit,
TestPrefix(TestPrefix), Flags(Flags), HasEmittedFirstMethod(false), TestPrefix(TestPrefix), Flags(Flags), HasEmittedFirstMethod(false),
RNG(""), ObjectWriter() { RNG(""), ObjectWriter() {
// Pre-register built-in stack names. // Pre-register built-in stack names.
newTimerStackID("Total across all functions"); if (ALLOW_DUMP) {
newTimerStackID("Per-function summary"); newTimerStackID("Total across all functions");
newTimerStackID("Per-function summary");
}
if (Flags.UseELFWriter) { if (Flags.UseELFWriter) {
ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr)); ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr));
} }
...@@ -221,7 +223,7 @@ IceString GlobalContext::mangleName(const IceString &Name) const { ...@@ -221,7 +223,7 @@ IceString GlobalContext::mangleName(const IceString &Name) const {
// _Z3barxyz ==> ZN6Prefix3barExyz // _Z3barxyz ==> ZN6Prefix3barExyz
// An unmangled, extern "C" style name, gets a simple prefix: // An unmangled, extern "C" style name, gets a simple prefix:
// bar ==> Prefixbar // bar ==> Prefixbar
if (getTestPrefix().empty()) if (!ALLOW_DUMP || getTestPrefix().empty())
return Name; return Name;
unsigned PrefixLength = getTestPrefix().length(); unsigned PrefixLength = getTestPrefix().length();
...@@ -438,6 +440,8 @@ TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID, ...@@ -438,6 +440,8 @@ TimerIdT GlobalContext::getTimerID(TimerStackIdT StackID,
} }
TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) { TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) {
if (!ALLOW_DUMP)
return 0;
TimerStackIdT NewID = Timers.size(); TimerStackIdT NewID = Timers.size();
Timers.push_back(TimerStack(Name)); Timers.push_back(TimerStack(Name));
return NewID; return NewID;
...@@ -485,10 +489,12 @@ void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) { ...@@ -485,10 +489,12 @@ void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
} }
TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func) TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func)
: ID(ID), Ctx(Func->getContext()), : ID(ID), Ctx(Func->getContext()), Active(false) {
Active(Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled) { if (ALLOW_DUMP) {
if (Active) Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled;
Ctx->pushTimer(ID); if (Active)
Ctx->pushTimer(ID);
}
} }
} // end of namespace Ice } // end of namespace Ice
...@@ -161,25 +161,38 @@ public: ...@@ -161,25 +161,38 @@ public:
ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); } ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); }
// Reset stats at the beginning of a function. // Reset stats at the beginning of a function.
void resetStats() { StatsFunction.reset(); } void resetStats() {
if (ALLOW_DUMP)
StatsFunction.reset();
}
void dumpStats(const IceString &Name, bool Final = false); void dumpStats(const IceString &Name, bool Final = false);
void statsUpdateEmitted(uint32_t InstCount) { void statsUpdateEmitted(uint32_t InstCount) {
if (!ALLOW_DUMP)
return;
StatsFunction.updateEmitted(InstCount); StatsFunction.updateEmitted(InstCount);
StatsCumulative.updateEmitted(InstCount); StatsCumulative.updateEmitted(InstCount);
} }
void statsUpdateRegistersSaved(uint32_t Num) { void statsUpdateRegistersSaved(uint32_t Num) {
if (!ALLOW_DUMP)
return;
StatsFunction.updateRegistersSaved(Num); StatsFunction.updateRegistersSaved(Num);
StatsCumulative.updateRegistersSaved(Num); StatsCumulative.updateRegistersSaved(Num);
} }
void statsUpdateFrameBytes(uint32_t Bytes) { void statsUpdateFrameBytes(uint32_t Bytes) {
if (!ALLOW_DUMP)
return;
StatsFunction.updateFrameBytes(Bytes); StatsFunction.updateFrameBytes(Bytes);
StatsCumulative.updateFrameBytes(Bytes); StatsCumulative.updateFrameBytes(Bytes);
} }
void statsUpdateSpills() { void statsUpdateSpills() {
if (!ALLOW_DUMP)
return;
StatsFunction.updateSpills(); StatsFunction.updateSpills();
StatsCumulative.updateSpills(); StatsCumulative.updateSpills();
} }
void statsUpdateFills() { void statsUpdateFills() {
if (!ALLOW_DUMP)
return;
StatsFunction.updateFills(); StatsFunction.updateFills();
StatsCumulative.updateFills(); StatsCumulative.updateFills();
} }
...@@ -234,21 +247,24 @@ class TimerMarker { ...@@ -234,21 +247,24 @@ class TimerMarker {
public: public:
TimerMarker(TimerIdT ID, GlobalContext *Ctx) TimerMarker(TimerIdT ID, GlobalContext *Ctx)
: ID(ID), Ctx(Ctx), Active(Ctx->getFlags().SubzeroTimingEnabled) { : ID(ID), Ctx(Ctx), Active(false) {
if (Active) if (ALLOW_DUMP) {
Ctx->pushTimer(ID); Active = Ctx->getFlags().SubzeroTimingEnabled;
if (Active)
Ctx->pushTimer(ID);
}
} }
TimerMarker(TimerIdT ID, const Cfg *Func); TimerMarker(TimerIdT ID, const Cfg *Func);
~TimerMarker() { ~TimerMarker() {
if (Active) if (ALLOW_DUMP && Active)
Ctx->popTimer(ID); Ctx->popTimer(ID);
} }
private: private:
TimerIdT ID; TimerIdT ID;
GlobalContext *const Ctx; GlobalContext *const Ctx;
const bool Active; bool Active;
}; };
} // end of namespace Ice } // end of namespace Ice
......
...@@ -22,6 +22,8 @@ namespace Ice { ...@@ -22,6 +22,8 @@ namespace Ice {
TimerStack::TimerStack(const IceString &Name) TimerStack::TimerStack(const IceString &Name)
: Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp), : Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp),
StateChangeCount(0), StackTop(0) { StateChangeCount(0), StackTop(0) {
if (!ALLOW_DUMP)
return;
Nodes.resize(1); // Reserve Nodes[0] for the root node. Nodes.resize(1); // Reserve Nodes[0] for the root node.
IDs.resize(TT__num); IDs.resize(TT__num);
#define STR(s) #s #define STR(s) #s
...@@ -36,6 +38,8 @@ TimerStack::TimerStack(const IceString &Name) ...@@ -36,6 +38,8 @@ TimerStack::TimerStack(const IceString &Name)
// Returns the unique timer ID for the given Name, creating a new ID // Returns the unique timer ID for the given Name, creating a new ID
// if needed. // if needed.
TimerIdT TimerStack::getTimerID(const IceString &Name) { TimerIdT TimerStack::getTimerID(const IceString &Name) {
if (!ALLOW_DUMP)
return 0;
if (IDsIndex.find(Name) == IDsIndex.end()) { if (IDsIndex.find(Name) == IDsIndex.end()) {
IDsIndex[Name] = IDs.size(); IDsIndex[Name] = IDs.size();
IDs.push_back(Name); IDs.push_back(Name);
...@@ -45,6 +49,8 @@ TimerIdT TimerStack::getTimerID(const IceString &Name) { ...@@ -45,6 +49,8 @@ TimerIdT TimerStack::getTimerID(const IceString &Name) {
// Pushes a new marker onto the timer stack. // Pushes a new marker onto the timer stack.
void TimerStack::push(TimerIdT ID) { void TimerStack::push(TimerIdT ID) {
if (!ALLOW_DUMP)
return;
const bool UpdateCounts = false; const bool UpdateCounts = false;
update(UpdateCounts); update(UpdateCounts);
if (Nodes[StackTop].Children.size() <= ID) if (Nodes[StackTop].Children.size() <= ID)
...@@ -62,6 +68,8 @@ void TimerStack::push(TimerIdT ID) { ...@@ -62,6 +68,8 @@ void TimerStack::push(TimerIdT ID) {
// Pop the top marker from the timer stack. Validates via assert() // Pop the top marker from the timer stack. Validates via assert()
// that the expected marker is popped. // that the expected marker is popped.
void TimerStack::pop(TimerIdT ID) { void TimerStack::pop(TimerIdT ID) {
if (!ALLOW_DUMP)
return;
const bool UpdateCounts = true; const bool UpdateCounts = true;
update(UpdateCounts); update(UpdateCounts);
assert(StackTop); assert(StackTop);
...@@ -77,6 +85,8 @@ void TimerStack::pop(TimerIdT ID) { ...@@ -77,6 +85,8 @@ void TimerStack::pop(TimerIdT ID) {
// At a state change (e.g. push or pop), updates the flat and // At a state change (e.g. push or pop), updates the flat and
// cumulative timings for everything on the timer stack. // cumulative timings for everything on the timer stack.
void TimerStack::update(bool UpdateCounts) { void TimerStack::update(bool UpdateCounts) {
if (!ALLOW_DUMP)
return;
++StateChangeCount; ++StateChangeCount;
// Whenever the stack is about to change, we grab the time delta // Whenever the stack is about to change, we grab the time delta
// since the last change and add it to all active cumulative // since the last change and add it to all active cumulative
...@@ -111,6 +121,8 @@ void TimerStack::update(bool UpdateCounts) { ...@@ -111,6 +121,8 @@ void TimerStack::update(bool UpdateCounts) {
} }
void TimerStack::reset() { void TimerStack::reset() {
if (!ALLOW_DUMP)
return;
StateChangeCount = 0; StateChangeCount = 0;
FirstTimestamp = LastTimestamp = timestamp(); FirstTimestamp = LastTimestamp = timestamp();
LeafTimes.assign(LeafTimes.size(), 0); LeafTimes.assign(LeafTimes.size(), 0);
......
...@@ -1112,7 +1112,7 @@ public: ...@@ -1112,7 +1112,7 @@ public:
CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), CachedNumGlobalValueIDs(Context->getNumGlobalIDs()),
NextLocalInstIndex(Context->getNumGlobalIDs()), NextLocalInstIndex(Context->getNumGlobalIDs()),
InstIsTerminating(false) { InstIsTerminating(false) {
if (getFlags().TimeEachFunction) if (ALLOW_DUMP && getFlags().TimeEachFunction)
getTranslator().getContext()->pushTimer( getTranslator().getContext()->pushTimer(
getTranslator().getContext()->getTimerID( getTranslator().getContext()->getTimerID(
Ice::GlobalContext::TSK_Funcs, FuncDecl->getName()), Ice::GlobalContext::TSK_Funcs, FuncDecl->getName()),
...@@ -1210,7 +1210,7 @@ private: ...@@ -1210,7 +1210,7 @@ private:
static const uint64_t AlignPowerLimit = 29; static const uint64_t AlignPowerLimit = 29;
void popTimerIfTimingEachFunction() const { void popTimerIfTimingEachFunction() const {
if (getFlags().TimeEachFunction) { if (ALLOW_DUMP && getFlags().TimeEachFunction) {
getTranslator().getContext()->popTimer( getTranslator().getContext()->popTimer(
getTranslator().getContext()->getTimerID( getTranslator().getContext()->getTimerID(
Ice::GlobalContext::TSK_Funcs, Func->getFunctionName()), Ice::GlobalContext::TSK_Funcs, Func->getFunctionName()),
......
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