HPCToolkit
CCT-Merge.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #ifndef prof_Prof_CCT_Merge_hpp
61 #define prof_Prof_CCT_Merge_hpp
62 
63 //************************* System Include Files ****************************
64 
65 #include <iostream>
66 
67 #include <string>
68 #include <vector>
69 #include <list>
70 #include <set>
71 
72 //*************************** User Include Files ****************************
73 
74 #include <include/uint.h>
75 
77 
79 
80 
81 //*************************** Forward Declarations ***************************
82 
83 
84 //***************************************************************************
85 // MergeEffect, MergeEffectList
86 //***************************************************************************
87 
88 namespace Prof {
89 
90 namespace CCT {
91 
92 struct MergeEffect {
95  { }
96 
97  MergeEffect(uint old_, uint new_) : old_cpId(old_), new_cpId(new_)
98  { }
99 
100  bool
102  {
103  return (old_cpId == HPCRUN_FMT_CCTNodeId_NULL &&
105  }
106 
107  std::string
108  toString(const char* pfx = "") const;
109 
110  std::ostream&
111  dump(std::ostream& os = std::cerr, const char* pfx = "") const;
112 
113 
114  static std::string
115  toString(const std::list<MergeEffect>& effctLst,
116  const char* pfx = "");
117 
118  static std::ostream&
119  dump(const std::list<CCT::MergeEffect>& effctLst,
120  std::ostream& os, const char* pfx = "");
121 
122  uint old_cpId /*within y*/, new_cpId /*within y*/;
123 };
124 
125 
126 typedef std::list<MergeEffect> MergeEffectList;
127 
128 
129 } // namespace CCT
130 
131 } // namespace Prof
132 
133 
134 //***************************************************************************
135 // MergeContext
136 //***************************************************************************
137 
138 namespace Prof {
139 
140 namespace CCT {
141 
142 class Tree;
143 
144 enum {
145  // -------------------------------------------------------
146  // CCT Merge flags
147  // -------------------------------------------------------
149 
150  // Instruct a merge function to only perform tree merges; tree
151  // inserts are simply skipped and considered benign operations.
153 
154  // Instruct a merge function to only perform tree merges; tree
155  // inserts are considered errors and throw an exception.
157 
158  // -------------------------------------------------------
159  // *Private* CCT Merge flags
160  // -------------------------------------------------------
162 };
163 
164 
166 public:
167  typedef std::set<uint> CPIdSet;
168 
169 public:
170  MergeContext(Tree* cct, bool doTrackCPIds);
171 
172  // -------------------------------------------------------
173  //
174  // -------------------------------------------------------
175  void
176  flags(uint mrgFlag)
177  { m_mrgFlag = mrgFlag; }
178 
179  uint
180  flags() const
181  { return m_mrgFlag; }
182 
183  bool
185  { return (m_mrgFlag & MrgFlg_PropagateEffects); }
186 
187 
188  // -------------------------------------------------------
189  //
190  // -------------------------------------------------------
191  bool
193  { return m_isTrackingCPIds; }
194 
195 
196  bool
197  isConflict_cpId(uint cpId) const
198  {
199  return (cpId != HPCRUN_FMT_CCTNodeId_NULL
200  && m_cpIdSet.find(cpId) != m_cpIdSet.end());
201  }
202 
203 
204  struct pair {
205  pair(uint cpId_, MergeEffect effect_)
206  : cpId(cpId_), effect(effect_)
207  { }
208 
211  };
212 
213 
214  // returns the (possibly) new CPId and a MergeEffect
217  {
218  uint newId = curId;
219  MergeEffect effct;
220 
221  if (isConflict_cpId(curId)) {
222  newId = makeCPId();
223 
224  if (doPropagateEffects()) {
225  effct.old_cpId = curId;
226  effct.new_cpId = newId;
227  }
228  }
229  else {
230  noteCPId(curId);
231  }
232 
233  return MergeContext::pair(newId, effct);
234  }
235 
236 
237  void
239  {
240  if (cpId != HPCRUN_FMT_CCTNodeId_NULL) {
241  std::pair<CPIdSet::iterator, bool> ret = m_cpIdSet.insert(cpId);
242  DIAG_Assert(ret.second, "MergeContext::noteCPId: conflicting cp-ids!");
243  }
244  }
245 
246 
247  uint
249  {
250  uint newId = *(m_cpIdSet.rbegin()) + 2;
251  std::pair<CPIdSet::iterator, bool> ret = m_cpIdSet.insert(newId);
252  DIAG_Assert(hpcrun_fmt_doRetainId(newId) && ret.second,
253  "MergeContext::makeCPId: error!");
254  return newId;
255  }
256 
257 private:
258  void
259  fillCPIdSet(Tree* cct);
260 
261 private:
262  const Tree* m_cct;
263 
265 
267  CPIdSet m_cpIdSet;
268 };
269 
270 } // namespace CCT
271 
272 } // namespace Prof
273 
274 
275 //***************************************************************************
276 
277 #endif /* prof_Prof_CCT_Merge_hpp */
pair(uint cpId_, MergeEffect effect_)
Definition: CCT-Merge.hpp:205
static bool hpcrun_fmt_doRetainId(uint32_t id)
Definition: hpcrun-fmt.h:502
bool isConflict_cpId(uint cpId) const
Definition: CCT-Merge.hpp:197
std::list< MergeEffect > MergeEffectList
Definition: CCT-Merge.hpp:126
std::ostream & dump(std::ostream &os=std::cerr, const char *pfx="") const
MergeContext::pair ensureUniqueCPId(uint curId)
Definition: CCT-Merge.hpp:216
unsigned int uint
Definition: uint.h:124
std::string toString(const char *pfx="") const
Definition: CCT-Merge.cpp:121
std::set< uint > CPIdSet
Definition: CCT-Merge.hpp:167
MergeEffect(uint old_, uint new_)
Definition: CCT-Merge.hpp:97
void flags(uint mrgFlag)
Definition: CCT-Merge.hpp:176
void noteCPId(uint cpId)
Definition: CCT-Merge.hpp:238
#define HPCRUN_FMT_CCTNodeId_NULL
Definition: hpcrun-fmt.h:497
bool isTrackingCPIds() const
Definition: CCT-Merge.hpp:192