OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file implements the Cfg class, including constant pool |
| 11 // management. |
| 12 // |
| 13 //===----------------------------------------------------------------------===// |
| 14 |
| 15 #include "IceCfg.h" |
| 16 #include "IceCfgNode.h" |
| 17 #include "IceDefs.h" |
| 18 #include "IceInst.h" |
| 19 #include "IceOperand.h" |
| 20 |
| 21 namespace Ice { |
| 22 |
| 23 Cfg::Cfg(GlobalContext *Ctx) |
| 24 : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), |
| 25 IsInternalLinkage(false), HasError(false), ErrorMessage(""), Entry(NULL), |
| 26 NextInstNumber(1), CurrentNode(NULL) {} |
| 27 |
| 28 Cfg::~Cfg() {} |
| 29 |
| 30 void Cfg::setError(const IceString &Message) { |
| 31 HasError = true; |
| 32 ErrorMessage = Message; |
| 33 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; |
| 34 } |
| 35 |
| 36 CfgNode *Cfg::makeNode(const IceString &Name) { |
| 37 SizeT LabelIndex = Nodes.size(); |
| 38 CfgNode *Node = CfgNode::create(this, LabelIndex, Name); |
| 39 Nodes.push_back(Node); |
| 40 return Node; |
| 41 } |
| 42 |
| 43 // Create a new Variable with a particular type and an optional |
| 44 // name. The Node argument is the node where the variable is defined. |
| 45 Variable *Cfg::makeVariable(Type Ty, const CfgNode *Node, |
| 46 const IceString &Name) { |
| 47 SizeT Index = Variables.size(); |
| 48 Variables.push_back(Variable::create(this, Ty, Node, Index, Name)); |
| 49 return Variables[Index]; |
| 50 } |
| 51 |
| 52 void Cfg::addArg(Variable *Arg) { |
| 53 Arg->setIsArg(this); |
| 54 Args.push_back(Arg); |
| 55 } |
| 56 |
| 57 void Cfg::computePredecessors() { |
| 58 for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
| 59 (*I)->computePredecessors(); |
| 60 } |
| 61 } |
| 62 |
| 63 // ======================== Dump routines ======================== // |
| 64 |
| 65 void Cfg::dump() { |
| 66 Ostream &Str = Ctx->getStrDump(); |
| 67 setCurrentNode(getEntryNode()); |
| 68 // Print function name+args |
| 69 if (getContext()->isVerbose(IceV_Instructions)) { |
| 70 Str << "define "; |
| 71 if (getInternal()) |
| 72 Str << "internal "; |
| 73 Str << ReturnType << " @" << getFunctionName() << "("; |
| 74 for (SizeT i = 0; i < Args.size(); ++i) { |
| 75 if (i > 0) |
| 76 Str << ", "; |
| 77 Str << Args[i]->getType() << " "; |
| 78 Args[i]->dump(this); |
| 79 } |
| 80 Str << ") {\n"; |
| 81 } |
| 82 setCurrentNode(NULL); |
| 83 // Print each basic block |
| 84 for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; |
| 85 ++I) { |
| 86 (*I)->dump(this); |
| 87 } |
| 88 if (getContext()->isVerbose(IceV_Instructions)) { |
| 89 Str << "}\n"; |
| 90 } |
| 91 } |
| 92 |
| 93 } // end of namespace Ice |
OLD | NEW |