| Index: src/IceCfg.cpp
|
| diff --git a/src/IceCfg.cpp b/src/IceCfg.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..757f4a902b2432fa929caac65d41b9324dfaf9ce
|
| --- /dev/null
|
| +++ b/src/IceCfg.cpp
|
| @@ -0,0 +1,89 @@
|
| +//===- 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"
|
| +
|
| +IceCfg::IceCfg(IceGlobalContext *Ctx)
|
| + : Ctx(Ctx), Name(""), Type(IceType_void), IsInternal(false),
|
| + HasError(false), ErrorMessage(""), Entry(NULL), NextInstNumber(1),
|
| + CurrentNode(NULL) {}
|
| +
|
| +IceCfg::~IceCfg() {}
|
| +
|
| +void IceCfg::setError(const IceString &Message) {
|
| + HasError = true;
|
| + ErrorMessage = Message;
|
| + Ctx->StrDump << "ICE translation error: " << ErrorMessage << "\n";
|
| +}
|
| +
|
| +IceCfgNode *IceCfg::makeNode(const IceString &Name) {
|
| + uint32_t LabelIndex = Nodes.size();
|
| + IceCfgNode *Node = IceCfgNode::create(this, LabelIndex, Name);
|
| + Nodes.push_back(Node);
|
| + return Node;
|
| +}
|
| +
|
| +// Create a new IceVariable with a particular type and an optional
|
| +// name. The Node argument is the node where the variable is defined.
|
| +IceVariable *IceCfg::makeVariable(IceType Type, const IceCfgNode *Node,
|
| + const IceString &Name) {
|
| + uint32_t Index = Variables.size();
|
| + Variables.push_back(IceVariable::create(this, Type, Node, Index, Name));
|
| + return Variables[Index];
|
| +}
|
| +
|
| +void IceCfg::addArg(IceVariable *Arg) {
|
| + Arg->setIsArg(this);
|
| + Args.push_back(Arg);
|
| +}
|
| +
|
| +void IceCfg::registerEdges() {
|
| + for (IceNodeList::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
|
| + (*I)->registerEdges();
|
| + }
|
| +}
|
| +
|
| +// ======================== Dump routines ======================== //
|
| +
|
| +void IceCfg::dump() {
|
| + IceOstream &Str = Ctx->StrDump;
|
| + setCurrentNode(getEntryNode());
|
| + // Print function name+args
|
| + if (getContext()->isVerbose(IceV_Instructions)) {
|
| + Str << "define ";
|
| + if (getInternal())
|
| + Str << "internal ";
|
| + Str << Type << " @" << Name << "(";
|
| + for (uint32_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 (IceNodeList::const_iterator I = Nodes.begin(), E = Nodes.end(); I != E;
|
| + ++I) {
|
| + (*I)->dump(this);
|
| + }
|
| + if (getContext()->isVerbose(IceV_Instructions)) {
|
| + Str << "}\n";
|
| + }
|
| +}
|
|
|