OLD | NEW |
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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "IceOperand.h" | 21 #include "IceOperand.h" |
22 #include "IceTargetLowering.h" | 22 #include "IceTargetLowering.h" |
23 | 23 |
24 namespace Ice { | 24 namespace Ice { |
25 | 25 |
26 Cfg::Cfg(GlobalContext *Ctx) | 26 Cfg::Cfg(GlobalContext *Ctx) |
27 : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), | 27 : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), |
28 IsInternalLinkage(false), HasError(false), ErrorMessage(""), Entry(NULL), | 28 IsInternalLinkage(false), HasError(false), ErrorMessage(""), Entry(NULL), |
29 NextInstNumber(1), Live(NULL), | 29 NextInstNumber(1), Live(NULL), |
30 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), | 30 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), |
31 CurrentNode(NULL) {} | 31 VMetadata(new VariablesMetadata(this)), CurrentNode(NULL) {} |
32 | 32 |
33 Cfg::~Cfg() {} | 33 Cfg::~Cfg() {} |
34 | 34 |
35 void Cfg::setError(const IceString &Message) { | 35 void Cfg::setError(const IceString &Message) { |
36 HasError = true; | 36 HasError = true; |
37 ErrorMessage = Message; | 37 ErrorMessage = Message; |
38 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; | 38 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; |
39 } | 39 } |
40 | 40 |
41 CfgNode *Cfg::makeNode(const IceString &Name) { | 41 CfgNode *Cfg::makeNode(const IceString &Name) { |
42 SizeT LabelIndex = Nodes.size(); | 42 SizeT LabelIndex = Nodes.size(); |
43 CfgNode *Node = CfgNode::create(this, LabelIndex, Name); | 43 CfgNode *Node = CfgNode::create(this, LabelIndex, Name); |
44 Nodes.push_back(Node); | 44 Nodes.push_back(Node); |
45 return Node; | 45 return Node; |
46 } | 46 } |
47 | 47 |
48 Variable *Cfg::makeVariable(Type Ty, const CfgNode *Node, | 48 Variable *Cfg::makeVariable(Type Ty, const IceString &Name) { |
49 const IceString &Name) { | 49 return makeVariable<Variable>(Ty, Name); |
50 return makeVariable<Variable>(Ty, Node, Name); | |
51 } | 50 } |
52 | 51 |
53 void Cfg::addArg(Variable *Arg) { | 52 void Cfg::addArg(Variable *Arg) { |
54 Arg->setIsArg(this); | 53 Arg->setIsArg(); |
55 Args.push_back(Arg); | 54 Args.push_back(Arg); |
56 } | 55 } |
57 | 56 |
58 // Returns whether the stack frame layout has been computed yet. This | 57 // Returns whether the stack frame layout has been computed yet. This |
59 // is used for dumping the stack frame location of Variables. | 58 // is used for dumping the stack frame location of Variables. |
60 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } | 59 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } |
61 | 60 |
62 void Cfg::translate() { | 61 void Cfg::translate() { |
63 if (hasError()) | 62 if (hasError()) |
64 return; | 63 return; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (Node->getHasReturn()) | 139 if (Node->getHasReturn()) |
141 getTarget()->addEpilog(Node); | 140 getTarget()->addEpilog(Node); |
142 } | 141 } |
143 } | 142 } |
144 | 143 |
145 // This is a lightweight version of live-range-end calculation. Marks | 144 // This is a lightweight version of live-range-end calculation. Marks |
146 // the last use of only those variables whose definition and uses are | 145 // the last use of only those variables whose definition and uses are |
147 // completely with a single block. It is a quick single pass and | 146 // completely with a single block. It is a quick single pass and |
148 // doesn't need to iterate until convergence. | 147 // doesn't need to iterate until convergence. |
149 void Cfg::livenessLightweight() { | 148 void Cfg::livenessLightweight() { |
| 149 getVMetadata()->init(); |
150 for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { | 150 for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
151 (*I)->livenessLightweight(); | 151 (*I)->livenessLightweight(); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 void Cfg::liveness(LivenessMode Mode) { | 155 void Cfg::liveness(LivenessMode Mode) { |
156 Live.reset(new Liveness(this, Mode)); | 156 Live.reset(new Liveness(this, Mode)); |
| 157 getVMetadata()->init(); |
157 Live->init(); | 158 Live->init(); |
158 // Initialize with all nodes needing to be processed. | 159 // Initialize with all nodes needing to be processed. |
159 llvm::BitVector NeedToProcess(Nodes.size(), true); | 160 llvm::BitVector NeedToProcess(Nodes.size(), true); |
160 while (NeedToProcess.any()) { | 161 while (NeedToProcess.any()) { |
161 // Iterate in reverse topological order to speed up convergence. | 162 // Iterate in reverse topological order to speed up convergence. |
162 for (NodeList::reverse_iterator I = Nodes.rbegin(), E = Nodes.rend(); | 163 for (NodeList::reverse_iterator I = Nodes.rbegin(), E = Nodes.rend(); |
163 I != E; ++I) { | 164 I != E; ++I) { |
164 CfgNode *Node = *I; | 165 CfgNode *Node = *I; |
165 if (NeedToProcess[Node->getIndex()]) { | 166 if (NeedToProcess[Node->getIndex()]) { |
166 NeedToProcess[Node->getIndex()] = false; | 167 NeedToProcess[Node->getIndex()] = false; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 Args[i]->dump(this); | 355 Args[i]->dump(this); |
355 } | 356 } |
356 Str << ") {\n"; | 357 Str << ") {\n"; |
357 } | 358 } |
358 resetCurrentNode(); | 359 resetCurrentNode(); |
359 if (getContext()->isVerbose(IceV_Liveness)) { | 360 if (getContext()->isVerbose(IceV_Liveness)) { |
360 // Print summary info about variables | 361 // Print summary info about variables |
361 for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); | 362 for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); |
362 I != E; ++I) { | 363 I != E; ++I) { |
363 Variable *Var = *I; | 364 Variable *Var = *I; |
364 Str << "//" | 365 Str << "// multiblock="; |
365 << " multiblock=" << Var->isMultiblockLife() << " " | 366 if (getVMetadata()->isTracked(Var)) |
366 << " weight=" << Var->getWeight() << " "; | 367 Str << getVMetadata()->isMultiBlock(Var); |
| 368 else |
| 369 Str << "?"; |
| 370 Str << " weight=" << Var->getWeight() << " "; |
367 Var->dump(this); | 371 Var->dump(this); |
368 if (Variable *Pref = Var->getPreferredRegister()) { | 372 if (Variable *Pref = Var->getPreferredRegister()) { |
369 Str << " pref="; | 373 Str << " pref="; |
370 Pref->dump(this); | 374 Pref->dump(this); |
371 if (Var->getRegisterOverlap()) | 375 if (Var->getRegisterOverlap()) |
372 Str << ",overlap"; | 376 Str << ",overlap"; |
373 Str << " "; | 377 Str << " "; |
374 } | 378 } |
375 Str << " LIVE=" << Var->getLiveRange() << "\n"; | 379 Str << " LIVE=" << Var->getLiveRange() << "\n"; |
376 } | 380 } |
377 } | 381 } |
378 // Print each basic block | 382 // Print each basic block |
379 for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; | 383 for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; |
380 ++I) { | 384 ++I) { |
381 (*I)->dump(this); | 385 (*I)->dump(this); |
382 } | 386 } |
383 if (getContext()->isVerbose(IceV_Instructions)) { | 387 if (getContext()->isVerbose(IceV_Instructions)) { |
384 Str << "}\n"; | 388 Str << "}\n"; |
385 } | 389 } |
386 } | 390 } |
387 | 391 |
388 } // end of namespace Ice | 392 } // end of namespace Ice |
OLD | NEW |