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

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 a $ to the profiler generated labels. 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[] = ".L$__Sz_block_name_";
81 constexpr char BlockStatsGlobalPrefix[] = ".L$__Sz_profile_";
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 anonymous namespace
106
107 void Cfg::profileBlocks() {
108 GlobalInits.reset(new VariableDeclarationList());
109 for (CfgNode *Node : Nodes) {
110 IceString NodeAsmName = Node->getAsmName();
111 GlobalInits->push_back(nodeNameDeclaration(NodeAsmName));
112 GlobalInits->push_back(
113 blockProfilingInfoDeclaration(NodeAsmName, GlobalInits->back()));
114 Node->profileExecutionCount(GlobalInits->back());
115 }
116 }
117
118 bool Cfg::isProfileGlobal(const VariableDeclaration &Var) {
119 return Var.getName().find(BlockStatsGlobalPrefix) == 0;
120 }
121
122 void Cfg::addCallToProfileSummary() {
123 Constant *ProfileSummarySym =
124 Ctx->getConstantExternSym("__Sz_profile_summary");
125 constexpr bool HasTailCall = false;
126 auto *Call =
127 InstCall::create(this, 0, nullptr, ProfileSummarySym, HasTailCall);
128 getEntryNode()->getInsts().push_front(Call);
129 }
130
78 void Cfg::translate() { 131 void Cfg::translate() {
79 if (hasError()) 132 if (hasError())
80 return; 133 return;
81 // FunctionTimer conditionally pushes/pops a TimerMarker if 134 // FunctionTimer conditionally pushes/pops a TimerMarker if
82 // TimeEachFunction is enabled. 135 // TimeEachFunction is enabled.
83 std::unique_ptr<TimerMarker> FunctionTimer; 136 std::unique_ptr<TimerMarker> FunctionTimer;
84 if (ALLOW_DUMP) { 137 if (ALLOW_DUMP) {
85 const IceString &TimingFocusOn = 138 const IceString &TimingFocusOn =
86 getContext()->getFlags().getTimingFocusOn(); 139 getContext()->getFlags().getTimingFocusOn();
87 const IceString &Name = getFunctionName(); 140 const IceString &Name = getFunctionName();
88 if (TimingFocusOn == "*" || TimingFocusOn == Name) { 141 if (TimingFocusOn == "*" || TimingFocusOn == Name) {
89 setFocusedTiming(); 142 setFocusedTiming();
90 getContext()->resetTimer(GlobalContext::TSK_Default); 143 getContext()->resetTimer(GlobalContext::TSK_Default);
91 getContext()->setTimerName(GlobalContext::TSK_Default, Name); 144 getContext()->setTimerName(GlobalContext::TSK_Default, Name);
92 } 145 }
93 if (getContext()->getFlags().getTimeEachFunction()) 146 if (getContext()->getFlags().getTimeEachFunction())
94 FunctionTimer.reset(new TimerMarker( 147 FunctionTimer.reset(new TimerMarker(
95 getContext()->getTimerID(GlobalContext::TSK_Funcs, Name), 148 getContext()->getTimerID(GlobalContext::TSK_Funcs, Name),
96 getContext(), GlobalContext::TSK_Funcs)); 149 getContext(), GlobalContext::TSK_Funcs));
97 } 150 }
98 TimerMarker T(TimerStack::TT_translate, this); 151 TimerMarker T(TimerStack::TT_translate, this);
99 152
100 dump("Initial CFG"); 153 dump("Initial CFG");
101 154
155 if (getContext()->getFlags().getEnableBlockProfile()) {
156 profileBlocks();
157 // TODO(jpp): this is fragile, at best. Figure out a better way of detecting
158 // exit functions.
159 if (GlobalContext::matchSymbolName(getFunctionName(), "exit")) {
160 addCallToProfileSummary();
161 }
162 dump("Profiled CFG");
163 }
164
102 // The set of translation passes and their order are determined by 165 // The set of translation passes and their order are determined by
103 // the target. 166 // the target.
104 getTarget()->translate(); 167 getTarget()->translate();
105 168
106 dump("Final output"); 169 dump("Final output");
107 if (getFocusedTiming()) 170 if (getFocusedTiming())
108 getContext()->dumpTimers(); 171 getContext()->dumpTimers();
109 } 172 }
110 173
111 void Cfg::computeInOutEdges() { 174 void Cfg::computeInOutEdges() {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 } 604 }
542 } 605 }
543 // Print each basic block 606 // Print each basic block
544 for (CfgNode *Node : Nodes) 607 for (CfgNode *Node : Nodes)
545 Node->dump(this); 608 Node->dump(this);
546 if (isVerbose(IceV_Instructions)) 609 if (isVerbose(IceV_Instructions))
547 Str << "}\n"; 610 Str << "}\n";
548 } 611 }
549 612
550 } // end of namespace Ice 613 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.h ('k') | src/IceCfgNode.h » ('j') | src/IceGlobalContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698