Subzero: Fix -timing-funcs and -timing-focus flags.
1. Generate dummy FunctionXXX function names when either of those flags is given.
2. Remove the browser code that automatically sets F/G prefixes instead of Function/Global, since that performance tweak is no longer relevant.
3. Fix a presumably long-standing bug where -timing-focus would accumulate timings into the TLS copy of the timers, but would then try to print timing info based on the currently-empty GlobalContext copy of the timers.
BUG= none
R=kschimpf@google.com
Review URL: https://codereview.chromium.org/1855683002 .
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index e5a71aa..2d16734 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -197,14 +197,18 @@
void Cfg::translate() {
if (hasError())
return;
- if (BuildDefs::dump()) {
+ if (BuildDefs::timers()) {
const std::string TimingFocusOn = getFlags().getTimingFocusOn();
- const std::string Name = getFunctionName().toString();
- if (TimingFocusOn == "*" || TimingFocusOn == Name) {
- setFocusedTiming();
- getContext()->resetTimer(GlobalContext::TSK_Default);
- getContext()->setTimerName(GlobalContext::TSK_Default, Name);
+ if (!TimingFocusOn.empty()) {
+ const std::string Name = getFunctionName().toString();
+ if (TimingFocusOn == "*" || TimingFocusOn == Name) {
+ setFocusedTiming();
+ getContext()->resetTimer(GlobalContext::TSK_Default);
+ getContext()->setTimerName(GlobalContext::TSK_Default, Name);
+ }
}
+ }
+ if (BuildDefs::dump()) {
if (isVerbose(IceV_Status)) {
getContext()->getStrDump() << ">>>Translating "
<< getFunctionNameAndSize() << "\n";
@@ -235,8 +239,10 @@
getTarget()->translate();
dump("Final output");
- if (getFocusedTiming())
+ if (getFocusedTiming()) {
+ getContext()->mergeTimersFromTLS();
getContext()->dumpTimers();
+ }
}
void Cfg::computeInOutEdges() {
diff --git a/src/IceClFlags.def b/src/IceClFlags.def
index b1e2258..c46697d 100644
--- a/src/IceClFlags.def
+++ b/src/IceClFlags.def
@@ -111,14 +111,12 @@
\
X(DefaultFunctionPrefix, std::string, dev_opt_flag, \
"default-function-prefix", \
- cl::desc("Define default function prefix for naming " \
- "unnamed functions"), \
- cl::init(Ice::BuildDefs::dump() ? "Function" : "F")) \
+ cl::desc("Define default function prefix for naming unnamed functions"), \
+ cl::init("Function")) \
\
X(DefaultGlobalPrefix, std::string, dev_opt_flag, "default-global-prefix", \
- cl::desc("Define default global prefix for naming " \
- "unnamed globals"), \
- cl::init(Ice::BuildDefs::dump() ? "Global" : "G")) \
+ cl::desc("Define default global prefix for naming unnamed globals"), \
+ cl::init("Global")) \
\
X(DisableHybridAssembly, bool, dev_opt_flag, "no-hybrid-asm", \
cl::desc("Disable hybrid assembly when -filetype=iasm"), cl::init(false)) \
diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp
index 5689a3e..e7faa50 100644
--- a/src/IceGlobalContext.cpp
+++ b/src/IceGlobalContext.cpp
@@ -966,6 +966,10 @@
}
}
+void GlobalContext::mergeTimersFromTLS() {
+ getTimers()->mergeFrom(ICE_TLS_GET_FIELD(TLS)->Timers);
+}
+
void GlobalContext::dumpTimers(TimerStackIdT StackID, bool DumpCumulative) {
if (!BuildDefs::timers())
return;
@@ -992,7 +996,8 @@
void TimerMarker::push() {
switch (StackID) {
case GlobalContext::TSK_Default:
- Active = getFlags().getSubzeroTimingEnabled();
+ Active = getFlags().getSubzeroTimingEnabled() ||
+ !getFlags().getTimingFocusOn().empty();
break;
case GlobalContext::TSK_Funcs:
Active = getFlags().getTimeEachFunction();
diff --git a/src/IceGlobalContext.h b/src/IceGlobalContext.h
index cce9492..2ce1083 100644
--- a/src/IceGlobalContext.h
+++ b/src/IceGlobalContext.h
@@ -352,10 +352,13 @@
/// newTimerStackID() creates a new TimerStack in the global space. It does
/// not affect any TimerStack objects in TLS.
TimerStackIdT newTimerStackID(const std::string &Name);
- /// dumpTimers() dumps the global timer data. As such, one probably wants to
- /// call mergeTimerStacks() as a prerequisite.
+ /// dumpTimers() dumps the global timer data. This assumes all the
+ /// thread-local copies of timer data have been merged into the global timer
+ /// data.
void dumpTimers(TimerStackIdT StackID = TSK_Default,
bool DumpCumulative = true);
+ /// Merges the current thread's copy of timer data into the global timer data.
+ void mergeTimersFromTLS();
/// The following methods affect only the calling thread's TLS timer data.
TimerIdT getTimerID(TimerStackIdT StackID, const std::string &Name);
void pushTimer(TimerIdT ID, TimerStackIdT StackID);
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 4aef244..0a8e52a 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -477,7 +477,14 @@
Prefix);
} else {
Ice::GlobalContext *Ctx = Translator.getContext();
- if (Ice::BuildDefs::dump() || !Decl->isInternal()) {
+ // Synthesize a dummy name if any of the following is true:
+ // - DUMP is enabled
+ // - The symbol is external
+ // - The -timing-funcs flag is enabled
+ // - The -timing-focus flag is enabled
+ if (Ice::BuildDefs::dump() || !Decl->isInternal() ||
+ Ice::getFlags().getTimeEachFunction() ||
+ !Ice::getFlags().getTimingFocusOn().empty()) {
Decl->setName(Ctx, Translator.createUnnamedName(Prefix, NameIndex));
} else {
Decl->setName(Ctx);