7 #include <llvm/ADT/GraphTraits.h>
8 #include <llvm/Support/DOTGraphTraits.h>
10 #include "core/block.h"
11 #include "core/func.h"
12 #include "core/insts.h"
13 #include "core/cast.h"
19 struct llvm::GraphTraits<
Block *> {
21 using ChildIteratorType = Block::succ_iterator;
24 static ChildIteratorType child_begin(
NodeRef N) {
return N->succ_begin(); }
25 static ChildIteratorType child_end(
NodeRef N) {
return N->succ_end(); }
29 struct llvm::GraphTraits<const
Block *> {
31 using ChildIteratorType = Block::const_succ_iterator;
33 static NodeRef getEntryNode(
const Block *BB) {
return BB; }
34 static ChildIteratorType child_begin(
NodeRef N) {
return N->succ_begin(); }
35 static ChildIteratorType child_end(
NodeRef N) {
return N->succ_end(); }
41 struct llvm::GraphTraits<
llvm::Inverse<Block*>> {
45 static NodeRef getEntryNode(llvm::Inverse<Block *> G) {
return G.Graph; }
51 struct llvm::GraphTraits<
llvm::Inverse<const Block*>> {
55 static NodeRef getEntryNode(llvm::Inverse<const Block *> G) {
return G.Graph; }
63 using nodes_iterator = pointer_iterator<Func::iterator>;
66 static nodes_iterator nodes_begin(
Func *F) {
67 return nodes_iterator(F->begin());
70 static nodes_iterator nodes_end(
Func *F) {
71 return nodes_iterator(F->end());
74 static size_t size(
Func *F) {
return F->
size(); }
78 struct llvm::DOTGraphTraits<
Func*> :
public llvm::DefaultDOTGraphTraits {
79 DOTGraphTraits(
bool isSimple =
false) : DefaultDOTGraphTraits(isSimple) {}
81 static std::string getNodeLabel(
const Block *block,
const Func *f)
83 return std::string(block->
getName());
86 static std::string getNodeDescription(
const Block *block,
const Func *f)
89 llvm::raw_string_ostream os(str);
91 if (
auto *call = ::cast_or_null<const CallSite>(term)) {
92 if (
auto *func = call->GetDirectCallee()) {
93 os <<
"call: " << func->getName();
95 os <<
"indirect call";
101 static std::string getNodeAttributes(
const Block *block,
const Func *f)
104 llvm::raw_string_ostream os(str);
106 if (
auto *call = ::cast_or_null<const CallSite>(term)) {
107 if (
auto *func = call->GetDirectCallee()) {
108 os <<
"color=purple";
110 os <<
"color=orange";
112 }
else if (term->Is(Inst::Kind::TRAP) || term->Is(Inst::Kind::DEBUG_TRAP)) {
114 }
else if (term->IsReturn()) {
123 using nodes_iterator = pointer_iterator<Func::const_iterator>;
126 static nodes_iterator nodes_begin(
const Func *F) {
127 return nodes_iterator(F->begin());
130 static nodes_iterator nodes_end(
const Func *F) {
131 return nodes_iterator(F->end());
134 static size_t size(
const Func *F) {
return F->
size(); }
139 struct llvm::GraphTraits<
llvm::Inverse<Func*>> :
public llvm::GraphTraits<llvm::Inverse<Block*>> {
140 static NodeRef getEntryNode(llvm::Inverse<Func *> G) {
141 return &G.Graph->getEntryBlock();
146 struct llvm::GraphTraits<
llvm::Inverse<const Func*>> :
public llvm::GraphTraits<llvm::Inverse<const Block*>> {
147 static NodeRef getEntryNode(llvm::Inverse<const Func *> G) {
148 return &G.Graph->getEntryBlock();