| 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 |
| 57 void Cfg::addImplicitArg(Variable *Arg) { |
| 58 Arg->setIsImplicitArg(); |
| 59 ImplicitArgs.push_back(Arg); |
| 60 } |
| 61 |
| 58 // Returns whether the stack frame layout has been computed yet. This | 62 // Returns whether the stack frame layout has been computed yet. This |
| 59 // is used for dumping the stack frame location of Variables. | 63 // is used for dumping the stack frame location of Variables. |
| 60 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } | 64 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } |
| 61 | 65 |
| 62 void Cfg::translate() { | 66 void Cfg::translate() { |
| 63 if (hasError()) | 67 if (hasError()) |
| 64 return; | 68 return; |
| 65 | 69 |
| 66 dump("Initial CFG"); | 70 dump("Initial CFG"); |
| 67 | 71 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (Node->getHasReturn()) | 144 if (Node->getHasReturn()) |
| 141 getTarget()->addEpilog(Node); | 145 getTarget()->addEpilog(Node); |
| 142 } | 146 } |
| 143 } | 147 } |
| 144 | 148 |
| 145 // This is a lightweight version of live-range-end calculation. Marks | 149 // This is a lightweight version of live-range-end calculation. Marks |
| 146 // the last use of only those variables whose definition and uses are | 150 // 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 | 151 // completely with a single block. It is a quick single pass and |
| 148 // doesn't need to iterate until convergence. | 152 // doesn't need to iterate until convergence. |
| 149 void Cfg::livenessLightweight() { | 153 void Cfg::livenessLightweight() { |
| 154 getVMetadata()->init(); |
| 150 for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { | 155 for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
| 151 (*I)->livenessLightweight(); | 156 (*I)->livenessLightweight(); |
| 152 } | 157 } |
| 153 } | 158 } |
| 154 | 159 |
| 155 void Cfg::liveness(LivenessMode Mode) { | 160 void Cfg::liveness(LivenessMode Mode) { |
| 156 Live.reset(new Liveness(this, Mode)); | 161 Live.reset(new Liveness(this, Mode)); |
| 162 getVMetadata()->init(); |
| 157 Live->init(); | 163 Live->init(); |
| 158 // Initialize with all nodes needing to be processed. | 164 // Initialize with all nodes needing to be processed. |
| 159 llvm::BitVector NeedToProcess(Nodes.size(), true); | 165 llvm::BitVector NeedToProcess(Nodes.size(), true); |
| 160 while (NeedToProcess.any()) { | 166 while (NeedToProcess.any()) { |
| 161 // Iterate in reverse topological order to speed up convergence. | 167 // Iterate in reverse topological order to speed up convergence. |
| 162 for (NodeList::reverse_iterator I = Nodes.rbegin(), E = Nodes.rend(); | 168 for (NodeList::reverse_iterator I = Nodes.rbegin(), E = Nodes.rend(); |
| 163 I != E; ++I) { | 169 I != E; ++I) { |
| 164 CfgNode *Node = *I; | 170 CfgNode *Node = *I; |
| 165 if (NeedToProcess[Node->getIndex()]) { | 171 if (NeedToProcess[Node->getIndex()]) { |
| 166 NeedToProcess[Node->getIndex()] = false; | 172 NeedToProcess[Node->getIndex()] = false; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 Args[i]->dump(this); | 360 Args[i]->dump(this); |
| 355 } | 361 } |
| 356 Str << ") {\n"; | 362 Str << ") {\n"; |
| 357 } | 363 } |
| 358 resetCurrentNode(); | 364 resetCurrentNode(); |
| 359 if (getContext()->isVerbose(IceV_Liveness)) { | 365 if (getContext()->isVerbose(IceV_Liveness)) { |
| 360 // Print summary info about variables | 366 // Print summary info about variables |
| 361 for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); | 367 for (VarList::const_iterator I = Variables.begin(), E = Variables.end(); |
| 362 I != E; ++I) { | 368 I != E; ++I) { |
| 363 Variable *Var = *I; | 369 Variable *Var = *I; |
| 364 Str << "//" | 370 Str << "// multiblock="; |
| 365 << " multiblock=" << Var->isMultiblockLife() << " " | 371 if (getVMetadata()->isTracked(Var)) |
| 366 << " weight=" << Var->getWeight() << " "; | 372 Str << getVMetadata()->isMultiBlock(Var); |
| 373 else |
| 374 Str << "?"; |
| 375 Str << " weight=" << Var->getWeight() << " "; |
| 367 Var->dump(this); | 376 Var->dump(this); |
| 368 if (Variable *Pref = Var->getPreferredRegister()) { | 377 if (Variable *Pref = Var->getPreferredRegister()) { |
| 369 Str << " pref="; | 378 Str << " pref="; |
| 370 Pref->dump(this); | 379 Pref->dump(this); |
| 371 if (Var->getRegisterOverlap()) | 380 if (Var->getRegisterOverlap()) |
| 372 Str << ",overlap"; | 381 Str << ",overlap"; |
| 373 Str << " "; | 382 Str << " "; |
| 374 } | 383 } |
| 375 Str << " LIVE=" << Var->getLiveRange() << "\n"; | 384 Str << " LIVE=" << Var->getLiveRange() << "\n"; |
| 376 } | 385 } |
| 377 } | 386 } |
| 378 // Print each basic block | 387 // Print each basic block |
| 379 for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; | 388 for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; |
| 380 ++I) { | 389 ++I) { |
| 381 (*I)->dump(this); | 390 (*I)->dump(this); |
| 382 } | 391 } |
| 383 if (getContext()->isVerbose(IceV_Instructions)) { | 392 if (getContext()->isVerbose(IceV_Instructions)) { |
| 384 Str << "}\n"; | 393 Str << "}\n"; |
| 385 } | 394 } |
| 386 } | 395 } |
| 387 | 396 |
| 388 } // end of namespace Ice | 397 } // end of namespace Ice |
| OLD | NEW |