Chromium Code Reviews| Index: src/IceCfg.cpp |
| diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..375cadf948e6a10ddab56bcbe24d81c6a30ab914 |
| --- /dev/null |
| +++ b/src/IceCfg.cpp |
| @@ -0,0 +1,93 @@ |
| +//===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// |
| +// |
| +// The Subzero Code Generator |
| +// |
| +// This file is distributed under the University of Illinois Open Source |
| +// License. See LICENSE.TXT for details. |
| +// |
| +//===----------------------------------------------------------------------===// |
| +// |
| +// This file implements the IceCfg class, including constant pool |
| +// management. |
| +// |
| +//===----------------------------------------------------------------------===// |
| + |
| +#include "IceCfg.h" |
| +#include "IceCfgNode.h" |
| +#include "IceDefs.h" |
| +#include "IceInst.h" |
| +#include "IceOperand.h" |
| + |
| +namespace Ice { |
| + |
| +IceCfg::IceCfg(GlobalContext *Ctx) |
| + : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), |
| + IsInternalLinkage(false), HasError(false), ErrorMessage(""), Entry(NULL), |
| + NextInstNumber(1), CurrentNode(NULL) {} |
| + |
| +IceCfg::~IceCfg() {} |
| + |
| +void IceCfg::setError(const IceString &Message) { |
| + HasError = true; |
| + ErrorMessage = Message; |
| + Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; |
| +} |
| + |
| +CfgNode *IceCfg::makeNode(const IceString &Name) { |
| + IceSize_t LabelIndex = Nodes.size(); |
| + CfgNode *Node = CfgNode::create(this, LabelIndex, Name); |
| + Nodes.push_back(Node); |
| + return Node; |
| +} |
| + |
| +// Create a new Variable with a particular type and an optional |
| +// name. The Node argument is the node where the variable is defined. |
|
JF
2014/04/23 03:51:28
Silly comment... Two spaces after a period? You kn
Jim Stichnoth
2014/04/26 15:02:11
Two spaces is how I always write prose... maybe fi
|
| +Variable *IceCfg::makeVariable(IceType Type, const CfgNode *Node, |
| + const IceString &Name) { |
| + IceSize_t Index = Variables.size(); |
| + Variables.push_back(Variable::create(this, Type, Node, Index, Name)); |
| + return Variables[Index]; |
| +} |
| + |
| +void IceCfg::addArg(Variable *Arg) { |
| + Arg->setIsArg(this); |
| + Args.push_back(Arg); |
| +} |
| + |
| +void IceCfg::computePredecessors() { |
| + for (NodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
| + (*I)->computePredecessors(); |
| + } |
| +} |
| + |
| +// ======================== Dump routines ======================== // |
| + |
| +void IceCfg::dump() { |
| + IceOstream &Str = Ctx->getStrDump(); |
| + setCurrentNode(getEntryNode()); |
| + // Print function name+args |
| + if (getContext()->isVerbose(IceV_Instructions)) { |
| + Str << "define "; |
| + if (getInternal()) |
| + Str << "internal "; |
| + Str << ReturnType << " @" << getFunctionName() << "("; |
| + for (IceSize_t i = 0; i < Args.size(); ++i) { |
| + if (i > 0) |
| + Str << ", "; |
| + Str << Args[i]->getType() << " "; |
| + Args[i]->dump(this); |
| + } |
| + Str << ") {\n"; |
| + } |
| + setCurrentNode(NULL); |
| + // Print each basic block |
| + for (NodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E; |
| + ++I) { |
| + (*I)->dump(this); |
| + } |
| + if (getContext()->isVerbose(IceV_Instructions)) { |
| + Str << "}\n"; |
| + } |
| +} |
| + |
| +} // end of namespace Ice |