Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: src/IceCfg.cpp

Issue 1147023007: Subzero: Basic Block Profiler. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Adds Basic Block Profiling. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/IceCfg.cpp
diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
index 50aa5ee1dbbd25974869e0b766092876a0830a08..73d59ac39bfeedb6e3e8ee75742dd82e78560f9b 100644
--- a/src/IceCfg.cpp
+++ b/src/IceCfg.cpp
@@ -18,6 +18,7 @@
#include "IceClFlags.h"
#include "IceDefs.h"
#include "IceELFObjectWriter.h"
+#include "IceGlobalInits.h"
#include "IceInst.h"
#include "IceLiveness.h"
#include "IceOperand.h"
@@ -75,6 +76,53 @@ void Cfg::addImplicitArg(Variable *Arg) {
// is used for dumping the stack frame location of Variables.
bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); }
+namespace {
+constexpr char BlockNameGlobalPrefix[] = ".Lblock_name_";
+constexpr char BlockStatsGlobalPrefix[] = ".Lprofile_";
Jim Stichnoth 2015/06/08 23:45:31 Document somewhere that this is a "reserved" prefi
John 2015/06/09 15:36:18 What do you mean, "reserved"?
Jim Stichnoth 2015/06/09 16:39:45 For a function named "foo", Subzero generates inte
John 2015/06/09 22:01:16 To avoid name clashes (as long as $ is not a valid
+
+VariableDeclaration *nodeNameDeclaration(const IceString &NodeAsmName) {
+ VariableDeclaration *Var = VariableDeclaration::create();
+ Var->setName(BlockNameGlobalPrefix + NodeAsmName);
+ Var->setIsConstant(true);
+ Var->addInitializer(new VariableDeclaration::DataInitializer(
+ NodeAsmName.data(), NodeAsmName.size() + 1));
+ Var->setAlignment(8); // Wasteful, 32-bit could use 4 bytes.
+ return Var;
+}
+
+VariableDeclaration *
+blockProfilingInfoDeclaration(const IceString &NodeAsmName,
+ VariableDeclaration *NodeNameDeclaration) {
+ VariableDeclaration *Var = VariableDeclaration::create();
+ Var->setName(BlockStatsGlobalPrefix + NodeAsmName);
+ Var->addInitializer(new VariableDeclaration::ZeroInitializer(8));
+ Var->addInitializer(
+ new VariableDeclaration::RelocInitializer(NodeNameDeclaration, 0));
+ Var->setAlignment(8);
+ return Var;
+}
+
+} // end of namespace
Jim Stichnoth 2015/06/08 23:45:31 end of anonymous namespace
John 2015/06/09 15:36:18 Done.
+
+std::unique_ptr<VariableDeclarationList> Cfg::profileBlocks() {
Jim Stichnoth 2015/06/08 23:45:31 Add light documentation of these two functions, ei
John 2015/06/09 15:36:18 Done.
+ std::unique_ptr<VariableDeclarationList> ProfilerInits(
+ new VariableDeclarationList());
+
+ for (CfgNode *Node : Nodes) {
+ IceString NodeAsmName = Node->getAsmName();
+ ProfilerInits->push_back(nodeNameDeclaration(NodeAsmName));
+ ProfilerInits->push_back(
+ blockProfilingInfoDeclaration(NodeAsmName, ProfilerInits->back()));
+ Node->profileExecutionCount(ProfilerInits->back());
+ }
+
+ return ProfilerInits;
+}
+
+bool Cfg::isProfileGlobal(const VariableDeclaration &Var) {
+ return Var.getName().find(BlockStatsGlobalPrefix) == 0;
+}
+
void Cfg::translate() {
if (hasError())
return;

Powered by Google App Engine
This is Rietveld 408576698