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
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index e40bd16..d8e3b24 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -68,11 +68,13 @@
void Cfg::translate() {
if (hasError())
return;
- const IceString &TimingFocusOn = getContext()->getFlags().TimingFocusOn;
- if (TimingFocusOn == "*" || TimingFocusOn == getFunctionName()) {
- setFocusedTiming();
- getContext()->resetTimer(GlobalContext::TSK_Default);
- getContext()->setTimerName(GlobalContext::TSK_Default, getFunctionName());
+ if (ALLOW_DUMP) {
+ const IceString &TimingFocusOn = getContext()->getFlags().TimingFocusOn;
+ if (TimingFocusOn == "*" || TimingFocusOn == getFunctionName()) {
+ setFocusedTiming();
+ getContext()->resetTimer(GlobalContext::TSK_Default);
+ getContext()->setTimerName(GlobalContext::TSK_Default, getFunctionName());
+ }
}
TimerMarker T(TimerStack::TT_translate, this);
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 4eb0343..e06e290 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -883,7 +883,7 @@
continue;
TimerIdT TimerID = 0;
- if (Ctx->getFlags().TimeEachFunction) {
+ if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction) {
TimerID = Ctx->getTimerID(StackID, I.getName());
Ctx->pushTimer(TimerID, StackID);
}
@@ -891,7 +891,7 @@
Cfg *Fcn = FunctionConverter.convertFunction(&I);
translateFcn(Fcn);
- if (Ctx->getFlags().TimeEachFunction)
+ if (ALLOW_DUMP && Ctx->getFlags().TimeEachFunction)
Ctx->popTimer(TimerID, StackID);
}
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index 2f5269b..84d7b68 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -114,8 +114,10 @@
TestPrefix(TestPrefix), Flags(Flags), HasEmittedFirstMethod(false),
RNG(""), ObjectWriter() {
// Pre-register built-in stack names.
- newTimerStackID("Total across all functions");
- newTimerStackID("Per-function summary");
+ if (ALLOW_DUMP) {
+ newTimerStackID("Total across all functions");
+ newTimerStackID("Per-function summary");
+ }
if (Flags.UseELFWriter) {
ObjectWriter.reset(new ELFObjectWriter(*this, *ELFStr));
}
@@ -221,7 +223,7 @@
// _Z3barxyz ==> ZN6Prefix3barExyz
// An unmangled, extern "C" style name, gets a simple prefix:
// bar ==> Prefixbar
- if (getTestPrefix().empty())
+ if (!ALLOW_DUMP || getTestPrefix().empty())
return Name;
unsigned PrefixLength = getTestPrefix().length();
@@ -438,6 +440,8 @@
}
TimerStackIdT GlobalContext::newTimerStackID(const IceString &Name) {
+ if (!ALLOW_DUMP)
+ return 0;
TimerStackIdT NewID = Timers.size();
Timers.push_back(TimerStack(Name));
return NewID;
@@ -485,10 +489,12 @@
}
TimerMarker::TimerMarker(TimerIdT ID, const Cfg *Func)
- : ID(ID), Ctx(Func->getContext()),
- Active(Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled) {
- if (Active)
- Ctx->pushTimer(ID);
+ : ID(ID), Ctx(Func->getContext()), Active(false) {
+ if (ALLOW_DUMP) {
+ Active = Func->getFocusedTiming() || Ctx->getFlags().SubzeroTimingEnabled;
+ if (Active)
+ Ctx->pushTimer(ID);
+ }
}
} // end of namespace Ice
diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
index a082625..3998b53 100644
--- a/src/IceGlobalContext.h
+++ b/src/IceGlobalContext.h
@@ -161,25 +161,38 @@
ELFObjectWriter *getObjectWriter() const { return ObjectWriter.get(); }
// 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 statsUpdateEmitted(uint32_t InstCount) {
+ if (!ALLOW_DUMP)
+ return;
StatsFunction.updateEmitted(InstCount);
StatsCumulative.updateEmitted(InstCount);
}
void statsUpdateRegistersSaved(uint32_t Num) {
+ if (!ALLOW_DUMP)
+ return;
StatsFunction.updateRegistersSaved(Num);
StatsCumulative.updateRegistersSaved(Num);
}
void statsUpdateFrameBytes(uint32_t Bytes) {
+ if (!ALLOW_DUMP)
+ return;
StatsFunction.updateFrameBytes(Bytes);
StatsCumulative.updateFrameBytes(Bytes);
}
void statsUpdateSpills() {
+ if (!ALLOW_DUMP)
+ return;
StatsFunction.updateSpills();
StatsCumulative.updateSpills();
}
void statsUpdateFills() {
+ if (!ALLOW_DUMP)
+ return;
StatsFunction.updateFills();
StatsCumulative.updateFills();
}
@@ -234,21 +247,24 @@
public:
TimerMarker(TimerIdT ID, GlobalContext *Ctx)
- : ID(ID), Ctx(Ctx), Active(Ctx->getFlags().SubzeroTimingEnabled) {
- if (Active)
- Ctx->pushTimer(ID);
+ : ID(ID), Ctx(Ctx), Active(false) {
+ if (ALLOW_DUMP) {
+ Active = Ctx->getFlags().SubzeroTimingEnabled;
+ if (Active)
+ Ctx->pushTimer(ID);
+ }
}
TimerMarker(TimerIdT ID, const Cfg *Func);
~TimerMarker() {
- if (Active)
+ if (ALLOW_DUMP && Active)
Ctx->popTimer(ID);
}
private:
TimerIdT ID;
GlobalContext *const Ctx;
- const bool Active;
+ bool Active;
};
} // end of namespace Ice
diff --git a/src/IceTimerTree.cpp b/src/IceTimerTree.cpp
index cc25baf..9f2340d 100644
--- a/src/IceTimerTree.cpp
+++ b/src/IceTimerTree.cpp
@@ -22,6 +22,8 @@
TimerStack::TimerStack(const IceString &Name)
: Name(Name), FirstTimestamp(timestamp()), LastTimestamp(FirstTimestamp),
StateChangeCount(0), StackTop(0) {
+ if (!ALLOW_DUMP)
+ return;
Nodes.resize(1); // Reserve Nodes[0] for the root node.
IDs.resize(TT__num);
#define STR(s) #s
@@ -36,6 +38,8 @@
// Returns the unique timer ID for the given Name, creating a new ID
// if needed.
TimerIdT TimerStack::getTimerID(const IceString &Name) {
+ if (!ALLOW_DUMP)
+ return 0;
if (IDsIndex.find(Name) == IDsIndex.end()) {
IDsIndex[Name] = IDs.size();
IDs.push_back(Name);
@@ -45,6 +49,8 @@
// Pushes a new marker onto the timer stack.
void TimerStack::push(TimerIdT ID) {
+ if (!ALLOW_DUMP)
+ return;
const bool UpdateCounts = false;
update(UpdateCounts);
if (Nodes[StackTop].Children.size() <= ID)
@@ -62,6 +68,8 @@
// Pop the top marker from the timer stack. Validates via assert()
// that the expected marker is popped.
void TimerStack::pop(TimerIdT ID) {
+ if (!ALLOW_DUMP)
+ return;
const bool UpdateCounts = true;
update(UpdateCounts);
assert(StackTop);
@@ -77,6 +85,8 @@
// At a state change (e.g. push or pop), updates the flat and
// cumulative timings for everything on the timer stack.
void TimerStack::update(bool UpdateCounts) {
+ if (!ALLOW_DUMP)
+ return;
++StateChangeCount;
// Whenever the stack is about to change, we grab the time delta
// since the last change and add it to all active cumulative
@@ -111,6 +121,8 @@
}
void TimerStack::reset() {
+ if (!ALLOW_DUMP)
+ return;
StateChangeCount = 0;
FirstTimestamp = LastTimestamp = timestamp();
LeafTimes.assign(LeafTimes.size(), 0);
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index b74de0a..1609410 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -1112,7 +1112,7 @@
CachedNumGlobalValueIDs(Context->getNumGlobalIDs()),
NextLocalInstIndex(Context->getNumGlobalIDs()),
InstIsTerminating(false) {
- if (getFlags().TimeEachFunction)
+ if (ALLOW_DUMP && getFlags().TimeEachFunction)
getTranslator().getContext()->pushTimer(
getTranslator().getContext()->getTimerID(
Ice::GlobalContext::TSK_Funcs, FuncDecl->getName()),
@@ -1210,7 +1210,7 @@
static const uint64_t AlignPowerLimit = 29;
void popTimerIfTimingEachFunction() const {
- if (getFlags().TimeEachFunction) {
+ if (ALLOW_DUMP && getFlags().TimeEachFunction) {
getTranslator().getContext()->popTimer(
getTranslator().getContext()->getTimerID(
Ice::GlobalContext::TSK_Funcs, Func->getFunctionName()),