ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Dot.h
Go to the documentation of this file.
1 
52 #ifndef ETISS_INTERFACES_DOT_H
53 #define ETISS_INTERFACES_DOT_H
54 
55 #include "etiss/FixedSizeHashMap.h"
56 #include "etiss/Misc.h"
57 #include "etiss/ObjectPool.h"
58 #include "etiss/RefCountedObject.h"
59 
60 #include <fstream>
61 #include <functional>
62 #include <limits>
63 #include <list>
64 #include <unordered_map>
65 #include <unordered_set>
66 #include <vector>
67 
68 namespace std
69 {
70 template <>
71 struct hash<std::pair<void const *, void const *>>
72 {
73  std::hash<intptr_t> mh;
74  inline size_t operator()(const std::pair<void const *, void const *> &x) const
75  {
77  // create a pseudo pointer
78  intptr_t ret = ((intptr_t)x.first * 13) ^ ((intptr_t)x.second * 23) ^ (((intptr_t)x.first >> 15) * 19) ^
79  (((intptr_t)x.second >> 15) * 29);
80 
81  return ret;
82  }
83 };
84 } // namespace std
85 
86 namespace etiss
87 {
88 namespace interfaces
89 {
90 
95 class Dot
96 {
97  public:
98  class AttrList
99  {
101 
102  public:
103  std::string label_;
104  std::string color_;
105 
106  public:
107  void print(std::ostream &out, const std::string &appendedattr);
108  };
109  class Link;
110  class Graph;
111  class Node : public AttrList
112  {
114 
115  private:
116  inline Node(Dot *dot, Graph *parent, const std::string &id)
117  : dot_(dot), parent_(parent), id_(id.empty() ? (std::string("p_") + etiss::toString((size_t)this)) : id)
118  {
119  if (parent)
120  parent->nodes_.insert(this);
121  if (dot)
122  dot->idmap_.insert(std::make_pair(id_, this));
123  }
124 
125  public:
126  virtual inline ~Node()
127  {
128  while (!links_.empty())
129  delete *links_.begin();
130  if (parent_)
131  parent_->nodes_.erase(this);
132  if (dot_)
133  dot_->idmap_.erase(id_);
134  }
135 
136  public:
137  Dot *const dot_;
138  Graph *const parent_;
139  const std::string id_;
140 
141  private:
142  std::unordered_set<Link *> links_;
143 
144  public:
145  inline const std::unordered_set<Link *> &links() { return links_; }
146 
147  public:
148  virtual inline Graph *asGraph() { return nullptr; }
149 
150  public:
151  virtual void print(std::ostream &out, std::unordered_set<Link *> &icl);
152  };
153  class Link : public AttrList
154  {
156 
157  private:
158  Link(Node *src, Node *dst) : src_(src), dst_(dst)
159  {
160  if (src)
161  src->links_.insert(this);
162  if (dst)
163  dst->links_.insert(this);
164  }
165 
166  public:
167  virtual inline ~Link()
168  {
169  if (src_)
170  src_->links_.erase(this);
171  if (dst_)
172  dst_->links_.erase(this);
173  }
174 
175  public:
176  Node *const src_;
177  Node *const dst_;
178 
179  public:
180  void print(std::ostream &out);
181  };
182  class Graph : public Node
183  {
185 
186  private:
187  inline Graph(Dot *dot, Graph *parent) : Node(dot, parent, "") {}
188 
189  public:
190  virtual inline ~Graph()
191  {
192  while (!nodes_.empty())
193  delete (*nodes_.begin());
194  for (auto iter = dot_->graphs_.begin(); iter != dot_->graphs_.end(); ++iter)
195  {
196  if (*iter == this)
197  {
198  dot_->graphs_.erase(iter);
199  break;
200  }
201  }
202  }
203 
204  public:
205  inline Graph *asGraph() override { return this; }
206 
207  private:
208  std::unordered_set<Node *> nodes_;
209 
210  public:
211  inline const std::unordered_set<Node *> &nodes() { return nodes_; }
212 
213  public:
214  void print(std::ostream &out, std::unordered_set<Link *> &icl) override;
215  };
216 
217  private:
218  std::list<Graph *> graphs_;
219  std::unordered_map<std::string, Node *> idmap_;
220 
221  public:
222  ~Dot();
223  inline const std::list<Graph *> graphs() { return graphs_; }
224 
225  Graph *createG(std::string name = "");
226  Graph *createG(Graph *parent, std::string name = "");
227  Node *createN(Graph *, const std::string &id, std::string name = "");
228  inline Node *pcreateN(Graph *g, const void *id, std::string name = "")
229  {
230  return createN(g, id ? (std::string("p_") + etiss::toString((size_t)this)) : "", name);
231  }
232  Link *createE(Node *src, Node *dst, std::string name = "");
233 
234  Node *find(const std::string &id);
235 
241  Node *lopenN(const std::list<std::string> &labelpath);
242 
243  public:
244  virtual void print(std::ostream &out);
245 };
246 
247 namespace dot
248 {
249 
251 {
252  public:
253  class Link;
254  class Node
255  {
256  public:
257  inline Node() : id(0) {}
258  const void *id;
259  std::list<Link *> links;
260  };
261  class Link
262  {
263  public:
264  inline Link() : dst(0) {}
265  std::string color;
266  std::string label;
268  };
269 
270  public:
271  void defineNode(const void *id, const std::string &name);
272  void undefineNode(const void *id);
273 
274  Link *link(const void *src, const void *dst);
275 
276  void flush(std::ofstream &out, const std::string &graph);
277 
278  private:
279  void filterTmp(Node *start, Node *tmp, bool hideedge, const std::string &alabels, std::ofstream &out,
280  std::unordered_set<Node *> &nnl,
281  std::unordered_set<std::pair<const void *, const void *>> &dependencies,
282  std::unordered_set<Node *> &declared);
283 
285  std::unordered_map<const void *, Node *> currentnodes_;
286  std::unordered_map<const void *, Node *> currentdstnodes_;
287  std::unordered_map<const void *, std::string> nodes_;
288 };
289 
291 {
292  public:
293  class Link;
294  class Node //: public etiss::RefCountedObject<etiss::ObjectPool<Node> >
295  {
296  friend class Link;
298 
299  public:
300  static const double Nan;
301 
302  public:
303  inline Node(const void *id)
304  : id(id)
305  , color(0)
306  , cluster(0)
307  , time(Nan)
308  , weight(Nan)
311  , attrMap(0)
312  {
313  }
314  ~Node();
315  const void *const id;
316  const char *color;
317  const char *cluster;
318  double time;
319  double weight;
320  // std::name name; // name is stored in nodes_ map to prevent unneccessary copies;
321  void attrToString(std::ostream &out);
322  const std::unordered_set<Link *> &links_in_;
323  const std::unordered_set<Link *> &links_out_;
324  void setAttr(const std::string &name, const std::string &value);
325 
326  private:
327  std::unordered_set<Link *> links_in;
328  std::unordered_set<Link *> links_out;
329  std::map<std::string, std::string> *attrMap;
330  };
331  class Link
332  {
333  public:
334  static const size_t label_size = 256;
335  inline Link(Node *src, Node *dst) : color(""), taken(true), src(src), dst(dst)
336  {
337  if ((src == 0) || (dst == 0))
338  throw "error";
339  if (src == dst)
340  throw "loop error";
341  label[0] = 0;
342  }
343  const char *color;
345  void setLabel(const char *);
346  bool taken;
347  void attrToString(std::ostream &out);
348  Node *const src;
349  Node *const dst;
350  };
351 
352  public:
353  ValueOperationTraceGraphStreamer(const std::string &file, const std::string &depfile);
355  void defineNode(const void *id, const std::string &name);
356  void undefineNode(const void *id);
357 
358  void link(const void *dst, std::initializer_list<const void *> sources, const char *label = 0);
359 
360  void close();
361 
362  void flush();
363 
364  const std::unordered_set<std::pair<const void *, const void *>> &staticDependencies() const;
365 
369 
370  private:
371  void writePath();
372  void traverse(Node *n); //,std::unordered_set<Node*> & nodes); // debug loop detection
374 
375  Node *openDestNode(const void *const dst, Node *&cleanup);
376  Node *openSourceNode(const void *const src);
377 
381  // std::unordered_map<const void*,Node*,std::hash<const void*>, std::equal_to<const
382  // void*>,etiss::ObjectPool<std::pair<const void * const,Node*> > > currentnodes_;
384 
385  std::unordered_set<std::pair<const void *, const void *>> dependencies_;
386 
387  std::ofstream out;
388  std::ofstream depout;
389 
390  public:
391  std::function<void(Node *)> setCurrentNodeAttr;
392  std::function<void(Link *, Node * /*dst*/, Node *const * /*sources*/, size_t /*sources_count*/,
393  std::initializer_list<const void *> & /*raw sources*/, const char * /*op*/)>
398 
399  private:
402 
403  char out_buf[256 * 256];
404  char depout_buf[256 * 256];
405 
406  bool closed_;
407 };
408 
410 {
411  private:
412  std::unordered_map<const void *, std::unordered_set<const void *>, std::hash<const void *>,
413  std::equal_to<const void *>,
416 
417  std::unordered_map<const void *, std::string, std::hash<const void *>, std::equal_to<const void *>,
420 
421  std::unordered_set<std::pair<const void *, const void *>, std::hash<std::pair<const void *, const void *>>,
422  std::equal_to<std::pair<const void *, const void *>>,
425 
426  public:
428  inline void declare(const void *const id, const std::string &name)
429  {
430  names_.insert(std::make_pair(id, name));
431  tmp_.erase(id);
432  }
433  inline void deleted(const void *const id)
434  {
435  tmp_.erase(id);
436  names_.erase(id);
437  }
438  void link(const void *dst, const std::initializer_list<const void *> &sources);
439 
440  void write(std::ostream &out, const std::string &graphname,
441  std::function<bool(const void * /*src*/, const void * /*dst*/, std::string & /*color*/)> filterOutCon =
442  [](const void *, const void *, std::string &) { return false; },
443  std::function<void(const void * /*id*/, std::string & /*color*/)> nodeattr = [](const void *,
444  std::string &) {});
445 
446  public:
447 #ifdef TRACEABLEFIED_H_
449  void tf_write(const std::string &filename);
450 #endif
451 };
452 
453 } // namespace dot
454 
455 } // namespace interfaces
456 } // namespace etiss
457 
458 #endif // ETISS_INTERFACES_DOT_H
general configuration and logging
static __inline__ uint64_t
Definition: arm_cde.h:31
implements a stack that may only grow (if needed) and can only contain native types since no destruct...
Definition: ObjectPool.h:242
prealloc_inc defines the number of objects that is availabe within ObjectPools memory; default: 100
Definition: ObjectPool.h:98
void print(std::ostream &out, const std::string &appendedattr)
Definition: Dot.cpp:858
Graph * asGraph() override
Definition: Dot.h:205
const std::unordered_set< Node * > & nodes()
Definition: Dot.h:211
std::unordered_set< Node * > nodes_
Definition: Dot.h:208
void print(std::ostream &out, std::unordered_set< Link * > &icl) override
Definition: Dot.cpp:934
Graph(Dot *dot, Graph *parent)
Definition: Dot.h:187
std::unordered_set< Link * > links_
Definition: Dot.h:142
virtual void print(std::ostream &out, std::unordered_set< Link * > &icl)
Definition: Dot.cpp:899
virtual Graph * asGraph()
Definition: Dot.h:148
Graph *const parent_
Definition: Dot.h:138
Node(Dot *dot, Graph *parent, const std::string &id)
Definition: Dot.h:116
const std::string id_
Definition: Dot.h:139
const std::unordered_set< Link * > & links()
Definition: Dot.h:145
Node * pcreateN(Graph *g, const void *id, std::string name="")
Definition: Dot.h:228
const std::list< Graph * > graphs()
Definition: Dot.h:223
Node * createN(Graph *, const std::string &id, std::string name="")
Definition: Dot.cpp:1014
std::unordered_map< std::string, Node * > idmap_
Definition: Dot.h:219
virtual void print(std::ostream &out)
Definition: Dot.cpp:978
Graph * createG(std::string name="")
Definition: Dot.cpp:999
Node * lopenN(const std::list< std::string > &labelpath)
travel/creates sub graphs with the given labels until i find/creates a node for the lase label.
Definition: Dot.cpp:1041
std::list< Graph * > graphs_
Definition: Dot.h:218
Link * createE(Node *src, Node *dst, std::string name="")
Definition: Dot.cpp:1024
Node * find(const std::string &id)
Definition: Dot.cpp:1033
const std::unordered_set< Link * > & links_out_
Definition: Dot.h:323
const std::unordered_set< Link * > & links_in_
Definition: Dot.h:322
void setAttr(const std::string &name, const std::string &value)
Definition: Dot.cpp:308
std::map< std::string, std::string > * attrMap
Definition: Dot.h:329
const std::unordered_set< std::pair< const void *, const void * > > & staticDependencies() const
Definition: Dot.cpp:718
Node * openSourceNode(const void *const src)
Definition: Dot.cpp:391
bool enable_default_graph_streaming_
set to false to disable the streaming of variable dependencies over time.
Definition: Dot.h:366
std::function< void(Link *, const etiss::ExpandingNativeStack< Link *, 1000 > &)> setMetaLinkAttr
Definition: Dot.h:395
etiss::FixedSizeHashMap< const void *, Node *, etiss::pointerHash< const void > > currentnodes_
Definition: Dot.h:380
std::function< void(Node *)> setCurrentNodeAttr
Definition: Dot.h:391
std::function< void(const etiss::ExpandingNativeStack< Link *, 1000 > &)> custWritePath
Definition: Dot.h:396
std::unordered_set< std::pair< const void *, const void * > > dependencies_
Definition: Dot.h:385
ValueOperationTraceGraphStreamer(const std::string &file, const std::string &depfile)
Definition: Dot.cpp:331
void link(const void *dst, std::initializer_list< const void * > sources, const char *label=0)
Definition: Dot.cpp:444
etiss::ExpandingNativeStack< Link *, 1000 > path
Definition: Dot.h:373
std::function< bool(const etiss::ExpandingNativeStack< Link *, 1000 > &)> hidePath
Definition: Dot.h:397
std::function< void(Link *, Node *, Node *const *, size_t, std::initializer_list< const void * > &, const char *)> setCurrentLinkAttr
Definition: Dot.h:394
Node * openDestNode(const void *const dst, Node *&cleanup)
Definition: Dot.cpp:410
etiss::FixedSizeHashMap< Node *, uint64_t, etiss::pointerHash< const void > > nodeToTmpId_
Definition: Dot.h:379
void defineNode(const void *id, const std::string &name)
Definition: Dot.cpp:363
etiss::FixedSizeHashMap< const void *, std::string, etiss::pointerHash< const void > > nodes_
Definition: Dot.h:383
Link * link(const void *src, const void *dst)
Definition: Dot.cpp:71
void filterTmp(Node *start, Node *tmp, bool hideedge, const std::string &alabels, std::ofstream &out, std::unordered_set< Node * > &nnl, std::unordered_set< std::pair< const void *, const void * >> &dependencies, std::unordered_set< Node * > &declared)
Definition: Dot.cpp:129
std::unordered_map< const void *, Node * > currentdstnodes_
Definition: Dot.h:286
void defineNode(const void *id, const std::string &name)
Definition: Dot.cpp:59
std::unordered_map< const void *, Node * > currentnodes_
Definition: Dot.h:285
std::unordered_map< const void *, std::string > nodes_
Definition: Dot.h:287
void flush(std::ofstream &out, const std::string &graph)
Definition: Dot.cpp:187
std::unordered_map< const void *, std::unordered_set< const void * >, std::hash< const void * >, std::equal_to< const void * >, etiss::ObjectPool< std::pair< const void *const, std::unordered_set< const void * > > > > tmp_
Definition: Dot.h:415
void link(const void *dst, const std::initializer_list< const void * > &sources)
Definition: Dot.cpp:732
void declare(const void *const id, const std::string &name)
Definition: Dot.h:428
std::unordered_set< std::pair< const void *, const void * >, std::hash< std::pair< const void *, const void * > >, std::equal_to< std::pair< const void *, const void * > >, etiss::ObjectPool< std::pair< const void *, const void * > > > deps_
Definition: Dot.h:424
void deleted(const void *const id)
Definition: Dot.h:433
std::unordered_map< const void *, std::string, std::hash< const void * >, std::equal_to< const void * >, etiss::ObjectPool< std::pair< const void *const, std::string > > > names_
Definition: Dot.h:419
void write(std::ostream &out, const std::string &graphname, std::function< bool(const void *, const void *, std::string &)> filterOutCon=[](const void *, const void *, std::string &) { return false;}, std::function< void(const void *, std::string &)> nodeattr=[](const void *, std::string &) {})
Definition: Dot.cpp:776
std::set< Instruction * > Node
Holding unique instruction sets code chunks after permutation.
Definition: Instruction.h:155
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
std::string toString(const T &val)
conversion of type T to std::string.
Definition: Misc.h:174
__INTPTR_TYPE__ intptr_t
A signed integer type with the property that any valid pointer to void can be converted to this type,...
Definition: opencl-c-base.h:55
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:40
float __ovld __cnfn dot(float p0, float p1)
Compute dot product.
#define true
Definition: stdbool.h:16
#define bool
Definition: stdbool.h:15
size_t operator()(const std::pair< void const *, void const * > &x) const
Definition: Dot.h:74