Skip to content

Commit

Permalink
Merge remote-tracking branch 'predator/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrik committed Sep 6, 2012
2 parents 110e9eb + 0a18a97 commit 15f99cb
Show file tree
Hide file tree
Showing 62 changed files with 1,363 additions and 680 deletions.
6 changes: 4 additions & 2 deletions cl/builtins.cc
Expand Up @@ -27,7 +27,8 @@

namespace CodeStorage {

bool isBuiltInFnc(const struct cl_operand &op) {
bool isBuiltInFnc(const struct cl_operand &op)
{
const char *name;
if (!fncNameFromCst(&name, &op))
// likely indirect fuction call
Expand All @@ -38,7 +39,8 @@ bool isBuiltInFnc(const struct cl_operand &op) {
|| STREQ("VK_ASSERT", name);
}

bool isBuiltInCall(const Insn &insn) {
bool isBuiltInCall(const Insn &insn)
{
return isBuiltInFnc(insn.operands[/* fnc */ 1]);
}

Expand Down
15 changes: 10 additions & 5 deletions cl/callgraph.cc
Expand Up @@ -35,7 +35,8 @@ namespace CallGraph {
typedef const struct cl_operand &TOp;
typedef const Insn *TInsn;

Node* allocNodeIfNeeded(Graph &cg, Fnc *const fnc) {
Node* allocNodeIfNeeded(Graph &cg, Fnc *const fnc)
{
Node *&node = fnc->cgNode;
if (node)
return node;
Expand All @@ -46,7 +47,8 @@ Node* allocNodeIfNeeded(Graph &cg, Fnc *const fnc) {
return node;
}

void handleCallback(Graph &cg, Node *node, const TInsn insn, TOp op) {
void handleCallback(Graph &cg, Node *node, const TInsn insn, TOp op)
{
int uid;
if (!fncUidFromOperand(&uid, &op))
// not a function
Expand All @@ -70,7 +72,8 @@ void handleCallback(Graph &cg, Node *node, const TInsn insn, TOp op) {
cg.hasCallback = true;
}

void handleCall(Graph &cg, Node *node, const TInsn insn) {
void handleCall(Graph &cg, Node *node, const TInsn insn)
{
// if there is a call, it is no longer a leaf node
cg.leaves.erase(node);

Expand All @@ -92,7 +95,8 @@ void handleCall(Graph &cg, Node *node, const TInsn insn) {
cg.roots.erase(targetNode);
}

void handleFnc(Fnc *const fnc) {
void handleFnc(Fnc *const fnc)
{
Graph &cg = fnc->stor->callGraph;
Node *const node = allocNodeIfNeeded(cg, fnc);

Expand All @@ -114,7 +118,8 @@ void handleFnc(Fnc *const fnc) {
}
}

void buildCallGraph(const Storage &stor) {
void buildCallGraph(const Storage &stor)
{
StopWatch watch;

BOOST_FOREACH(Fnc *fnc, stor.fncs)
Expand Down
6 changes: 4 additions & 2 deletions cl/cl_chain.cc
Expand Up @@ -103,11 +103,13 @@ class ClChain: public ICodeListener {
} \
} while (0)

ClChain::~ClChain() {
ClChain::~ClChain()
{
CL_CHAIN_FOREACH(destroy);
}

void ClChain::append(cl_code_listener *item) {
void ClChain::append(cl_code_listener *item)
{
list_.push_back(item);
}

Expand Down
60 changes: 40 additions & 20 deletions cl/cl_dotgen.cc
Expand Up @@ -228,11 +228,13 @@ void ClDotGenerator::createDotFile(std::ofstream &str, std::string fileName,
CL_ERROR("unable to create file '" << fileName << "'");
}

void ClDotGenerator::closeSub(std::ofstream &str) {
void ClDotGenerator::closeSub(std::ofstream &str)
{
str << "}" << std::endl;
}

void ClDotGenerator::closeDot(std::ofstream &str) {
void ClDotGenerator::closeDot(std::ofstream &str)
{
ClDotGenerator::closeSub(str);

if (!str)
Expand All @@ -253,21 +255,25 @@ ClDotGenerator::ClDotGenerator(const char *glDotFile):
}
}

ClDotGenerator::~ClDotGenerator() {
ClDotGenerator::~ClDotGenerator()
{
if (hasGlDotFile_)
this->closeDot(glOut_);
}

void ClDotGenerator::acknowledge() {
void ClDotGenerator::acknowledge()
{
// we haven't been waiting for acknowledge anyway, sorry...
}

void ClDotGenerator::gobbleEdge(std::string dst, EdgeType type) {
void ClDotGenerator::gobbleEdge(std::string dst, EdgeType type)
{
perBbEdgeMap_[dst] = type;
perFncEdgeMap_[dst] = type;
}

void ClDotGenerator::emitEdge(std::string dst, EdgeType type) {
void ClDotGenerator::emitEdge(std::string dst, EdgeType type)
{
switch (type) {
case ET_LC_CALL:
case ET_LC_CALL_INDIR:
Expand All @@ -291,7 +297,8 @@ void ClDotGenerator::emitEdge(std::string dst, EdgeType type) {
<< " [color=" << EtColors[type] << "];" << std::endl;
}

void ClDotGenerator::emitBb() {
void ClDotGenerator::emitBb()
{
// colorize current BB node
perFileOut_ << "\t" << SL_QUOTE_BB(bb_)
<< " [color=" << NtColors[nodeType_]
Expand Down Expand Up @@ -321,7 +328,8 @@ void ClDotGenerator::emitCallSet(std::ofstream &str, TCallSet &cs,
}
}

void ClDotGenerator::emitPendingCalls() {
void ClDotGenerator::emitPendingCalls()
{
TCallMultiMap::iterator i;
for (i = perFncCalls_.begin(); i != perFncCalls_.end(); ++i) {
const string &dst = i->first;
Expand Down Expand Up @@ -351,7 +359,8 @@ void ClDotGenerator::emitPendingCalls() {
perFncEdgeMap_.clear();
}

void ClDotGenerator::emitFncEntry(const char *label) {
void ClDotGenerator::emitFncEntry(const char *label)
{
FILE_FNC_STREAM(SL_SUBGRAPH(fnc_ << "." << label, fnc_
<< "() at " << loc_.file << ":" << loc_.line)
<< "\tcolor=blue;" << std::endl
Expand All @@ -368,7 +377,8 @@ void ClDotGenerator::emitFncEntry(const char *label) {
perFileOut_ << "\tURL=" << SL_QUOTE_URL(fnc_) << ";" << std::endl;
}

void ClDotGenerator::emitInsnJmp(const char *label) {
void ClDotGenerator::emitInsnJmp(const char *label)
{
perFncOut_ << "\t" << SL_QUOTE_BB(bb_ << SL_BB_POS_SUFFIX)
<< " [shape=box, color=black, fontcolor=black,"
<< " style=bold, label=goto];" << std::endl;
Expand Down Expand Up @@ -396,7 +406,8 @@ void ClDotGenerator::emitInsnCond(const char *then_label,
<< " [color=green];" << std::endl;
}

void ClDotGenerator::emitOpIfNeeded() {
void ClDotGenerator::emitOpIfNeeded()
{
switch (lastInsn_) {
case CL_INSN_UNOP:
case CL_INSN_BINOP:
Expand All @@ -417,7 +428,8 @@ void ClDotGenerator::emitOpIfNeeded() {
<< std::endl;
}

void ClDotGenerator::emitInsnCall() {
void ClDotGenerator::emitInsnCall()
{
perFncOut_ << "\t" << SL_QUOTE_BB(bb_ << SL_BB_POS_SUFFIX)
<< " [shape=box, color=blue, fontcolor=blue, style=dashed,"
<< " label=call];" << std::endl;
Expand All @@ -429,7 +441,8 @@ void ClDotGenerator::emitInsnCall() {
<< std::endl;
}

void ClDotGenerator::checkForFncRef(const struct cl_operand *op) {
void ClDotGenerator::checkForFncRef(const struct cl_operand *op)
{
if (CL_OPERAND_CST != op->code)
return;

Expand All @@ -447,7 +460,8 @@ void ClDotGenerator::checkForFncRef(const struct cl_operand *op) {
perBbCalls_[name].insert(str.str());
}

void ClDotGenerator::file_open(const char *file_name) {
void ClDotGenerator::file_open(const char *file_name)
{
CL_LOC_SET_FILE(loc_, file_name);
ClDotGenerator::createDotFile(perFileOut_, file_name, true);
perFileOut_ << SL_GRAPH(file_name);
Expand Down Expand Up @@ -483,7 +497,8 @@ void ClDotGenerator::fnc_open(const struct cl_operand *fnc)
<< std::endl;
}

void ClDotGenerator::fnc_arg_decl(int, const struct cl_operand *) {
void ClDotGenerator::fnc_arg_decl(int, const struct cl_operand *)
{
}

void ClDotGenerator::fnc_close()
Expand All @@ -500,7 +515,8 @@ void ClDotGenerator::fnc_close()
bb_.clear();
}

void ClDotGenerator::bb_open(const char *bb_name) {
void ClDotGenerator::bb_open(const char *bb_name)
{
if (!bb_.empty())
// emit last BB
this->emitBb();
Expand All @@ -516,7 +532,8 @@ void ClDotGenerator::bb_open(const char *bb_name) {
<< "\tURL=\"\";" << std::endl;
}

void ClDotGenerator::insn(const struct cl_insn *cli) {
void ClDotGenerator::insn(const struct cl_insn *cli)
{
switch (cli->code) {
case CL_INSN_NOP:
case CL_INSN_LABEL:
Expand Down Expand Up @@ -626,7 +643,8 @@ void ClDotGenerator::insn_call_open(const struct cl_loc *loc,
CL_INSN_JMP;
}

void ClDotGenerator::insn_call_arg(int, const struct cl_operand *arg_src) {
void ClDotGenerator::insn_call_arg(int, const struct cl_operand *arg_src)
{
this->checkForFncRef(arg_src);
}

Expand Down Expand Up @@ -655,14 +673,16 @@ void ClDotGenerator::insn_switch_case(const struct cl_loc *,
<< " [color=yellow];" << std::endl;
}

void ClDotGenerator::insn_switch_close() {
void ClDotGenerator::insn_switch_close()
{
lastInsn_ =
/* FIXME: we have no CL_INSN_SWITCH in enum cl_insn_e */
CL_INSN_JMP;
}

// /////////////////////////////////////////////////////////////////////////////
// public interface, see cl_dotgen.hh for more details
ICodeListener* createClDotGenerator(const char *args) {
ICodeListener* createClDotGenerator(const char *args)
{
return new ClDotGenerator(args);
}
3 changes: 2 additions & 1 deletion cl/cl_easy.cc
Expand Up @@ -80,6 +80,7 @@ class ClEasy: public ClStorageBuilder {

// /////////////////////////////////////////////////////////////////////////////
// interface, see cl_easy.hh for details
ICodeListener* createClEasy(const char *configString) {
ICodeListener* createClEasy(const char *configString)
{
return new ClEasy(configString);
}
9 changes: 6 additions & 3 deletions cl/cl_factory.cc
Expand Up @@ -224,7 +224,8 @@ namespace {
}
}

ClfChainFactory::ClfChainFactory() {
ClfChainFactory::ClfChainFactory()
{
map_["unify_labels_gl"] = createClfUniLabelGl;
map_["unify_labels_static"] = createClfUniLabelStatic;
map_["unify_labels_fnc"] = createClfUniLabelFnc;
Expand Down Expand Up @@ -302,11 +303,13 @@ ClFactory::ClFactory():
d->map["typedot"] = &createClTypeDotGenerator;
}

ClFactory::~ClFactory() {
ClFactory::~ClFactory()
{
delete d;
}

ICodeListener* ClFactory::create(const char *config_string) {
ICodeListener* ClFactory::create(const char *config_string)
{
CL_FACTORY_DEBUG("ClFactory: config_string: " << config_string);

TStringMap args;
Expand Down
6 changes: 4 additions & 2 deletions cl/cl_locator.cc
Expand Up @@ -98,13 +98,15 @@ ClLocator::ClLocator():
{
}

void ClLocator::printLocation(const struct cl_loc *loc) {
void ClLocator::printLocation(const struct cl_loc *loc)
{
CL_DEBUG_MSG(cl_loc_fallback(loc, &lastLoc_),
"linearized code follows...");
}

// /////////////////////////////////////////////////////////////////////////////
// public interface, see cl_locator.hh for more details
ICodeListener* createClLocator(const char *) {
ICodeListener* createClLocator(const char *)
{
return new ClLocator;
}

0 comments on commit 15f99cb

Please sign in to comment.