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

Side by Side 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 unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the Cfg class, including constant pool 10 // This file implements the Cfg class, including constant pool
11 // management. 11 // management.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "assembler.h" 15 #include "assembler.h"
16 #include "IceCfg.h" 16 #include "IceCfg.h"
17 #include "IceCfgNode.h" 17 #include "IceCfgNode.h"
18 #include "IceClFlags.h" 18 #include "IceClFlags.h"
19 #include "IceDefs.h" 19 #include "IceDefs.h"
20 #include "IceELFObjectWriter.h" 20 #include "IceELFObjectWriter.h"
21 #include "IceGlobalInits.h"
21 #include "IceInst.h" 22 #include "IceInst.h"
22 #include "IceLiveness.h" 23 #include "IceLiveness.h"
23 #include "IceOperand.h" 24 #include "IceOperand.h"
24 #include "IceTargetLowering.h" 25 #include "IceTargetLowering.h"
25 26
26 namespace Ice { 27 namespace Ice {
27 28
28 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); 29 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg);
29 30
30 ArenaAllocator<> *getCurrentCfgAllocator() { 31 ArenaAllocator<> *getCurrentCfgAllocator() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 69
69 void Cfg::addImplicitArg(Variable *Arg) { 70 void Cfg::addImplicitArg(Variable *Arg) {
70 Arg->setIsImplicitArg(); 71 Arg->setIsImplicitArg();
71 ImplicitArgs.push_back(Arg); 72 ImplicitArgs.push_back(Arg);
72 } 73 }
73 74
74 // Returns whether the stack frame layout has been computed yet. This 75 // Returns whether the stack frame layout has been computed yet. This
75 // is used for dumping the stack frame location of Variables. 76 // is used for dumping the stack frame location of Variables.
76 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } 77 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); }
77 78
79 namespace {
80 constexpr char BlockNameGlobalPrefix[] = ".Lblock_name_";
81 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
82
83 VariableDeclaration *nodeNameDeclaration(const IceString &NodeAsmName) {
84 VariableDeclaration *Var = VariableDeclaration::create();
85 Var->setName(BlockNameGlobalPrefix + NodeAsmName);
86 Var->setIsConstant(true);
87 Var->addInitializer(new VariableDeclaration::DataInitializer(
88 NodeAsmName.data(), NodeAsmName.size() + 1));
89 Var->setAlignment(8); // Wasteful, 32-bit could use 4 bytes.
90 return Var;
91 }
92
93 VariableDeclaration *
94 blockProfilingInfoDeclaration(const IceString &NodeAsmName,
95 VariableDeclaration *NodeNameDeclaration) {
96 VariableDeclaration *Var = VariableDeclaration::create();
97 Var->setName(BlockStatsGlobalPrefix + NodeAsmName);
98 Var->addInitializer(new VariableDeclaration::ZeroInitializer(8));
99 Var->addInitializer(
100 new VariableDeclaration::RelocInitializer(NodeNameDeclaration, 0));
101 Var->setAlignment(8);
102 return Var;
103 }
104
105 } // end of namespace
Jim Stichnoth 2015/06/08 23:45:31 end of anonymous namespace
John 2015/06/09 15:36:18 Done.
106
107 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.
108 std::unique_ptr<VariableDeclarationList> ProfilerInits(
109 new VariableDeclarationList());
110
111 for (CfgNode *Node : Nodes) {
112 IceString NodeAsmName = Node->getAsmName();
113 ProfilerInits->push_back(nodeNameDeclaration(NodeAsmName));
114 ProfilerInits->push_back(
115 blockProfilingInfoDeclaration(NodeAsmName, ProfilerInits->back()));
116 Node->profileExecutionCount(ProfilerInits->back());
117 }
118
119 return ProfilerInits;
120 }
121
122 bool Cfg::isProfileGlobal(const VariableDeclaration &Var) {
123 return Var.getName().find(BlockStatsGlobalPrefix) == 0;
124 }
125
78 void Cfg::translate() { 126 void Cfg::translate() {
79 if (hasError()) 127 if (hasError())
80 return; 128 return;
81 // FunctionTimer conditionally pushes/pops a TimerMarker if 129 // FunctionTimer conditionally pushes/pops a TimerMarker if
82 // TimeEachFunction is enabled. 130 // TimeEachFunction is enabled.
83 std::unique_ptr<TimerMarker> FunctionTimer; 131 std::unique_ptr<TimerMarker> FunctionTimer;
84 if (ALLOW_DUMP) { 132 if (ALLOW_DUMP) {
85 const IceString &TimingFocusOn = 133 const IceString &TimingFocusOn =
86 getContext()->getFlags().getTimingFocusOn(); 134 getContext()->getFlags().getTimingFocusOn();
87 const IceString &Name = getFunctionName(); 135 const IceString &Name = getFunctionName();
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 589 }
542 } 590 }
543 // Print each basic block 591 // Print each basic block
544 for (CfgNode *Node : Nodes) 592 for (CfgNode *Node : Nodes)
545 Node->dump(this); 593 Node->dump(this);
546 if (isVerbose(IceV_Instructions)) 594 if (isVerbose(IceV_Instructions))
547 Str << "}\n"; 595 Str << "}\n";
548 } 596 }
549 597
550 } // end of namespace Ice 598 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698