HPCToolkit
LoadMap.cpp
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 //************************* System Include Files ****************************
61 
62 //*************************** User Include Files ****************************
63 
64 #include "LoadMap.hpp"
65 
66 #include "Struct-Tree.hpp" // TODO: Prof::Struct::Tree::UnknownLMNm
67 
68 #include <lib/binutils/LM.hpp>
69 
71 
72 
73 //*************************** Forward Declarations ***************************
74 
75 //****************************************************************************
76 
77 
78 //****************************************************************************
79 // LoadMap
80 //****************************************************************************
81 
82 namespace Prof {
83 
84 
86 {
87  m_lm_byId.reserve(sz);
88 
89  LM* nullLM = new LM(Prof::Struct::Tree::UnknownLMNm);
90  lm_insert(nullLM);
91  DIAG_Assert(nullLM->id() == LoadMap::LMId_NULL, "LoadMap::LoadMap");
92 }
93 
94 
96 {
97  for (LMId_t i = LoadMap::LMId_NULL; i <= size(); ++i) {
98  LoadMap::LM* lm = this->lm(i);
99  delete lm;
100  }
101  m_lm_byId.clear();
102  m_lm_byName.clear();
103 }
104 
105 
106 void
108 {
109  m_lm_byId.push_back(x);
110  x->id(m_lm_byId.size() - 1); // id is the last slot used
111 
112  std::pair<LMSet_nm::iterator, bool> ret = m_lm_byName.insert(x);
113  DIAG_Assert(ret.second, "LoadMap::lm_insert(): conflict inserting: "
114  << x->toString());
115 }
116 
117 
118 LoadMap::LMSet_nm::iterator
119 LoadMap::lm_find(const std::string& nm) const
120 {
121  static LoadMap::LM key;
122  key.name(nm);
123 
124  LMSet_nm::iterator fnd = m_lm_byName.find(&key);
125  return fnd;
126 }
127 
128 
129 std::vector<LoadMap::MergeEffect>*
131 {
132  std::vector<LoadMap::MergeEffect>* mrgEffect =
133  new std::vector<LoadMap::MergeEffect>;
134 
135  LoadMap& x = *this;
136 
137  for (LMId_t i = LoadMap::LMId_NULL; i <= y.size(); ++i) {
138  LoadMap::LM* y_lm = y.lm(i);
139 
140  LMSet_nm::iterator x_fnd = x.lm_find(y_lm->name());
141  LoadMap::LM* x_lm = (x_fnd != x.lm_end_nm()) ? *x_fnd : NULL;
142 
143  // Post-INVARIANT: A corresponding x_lm exists
144  if (!x_lm) {
145  // Create x_lm for y_lm.
146  x_lm = new LoadMap::LM(y_lm->name());
147  lm_insert(x_lm);
148  }
149 
150  if (x_lm->id() != y_lm->id()) {
151  // y_lm->id() is replaced by x_lm->id()
152  mrgEffect->push_back(LoadMap::MergeEffect(y_lm->id(), x_lm->id()));
153  }
154 
155  x_lm->isUsedMrg(y_lm->isUsed());
156  }
157 
158  return mrgEffect;
159 }
160 
161 
162 std::string
164 {
165  std::ostringstream os;
166  dump(os);
167  return os.str();
168 }
169 
170 
171 void
172 LoadMap::dump(std::ostream& os) const
173 {
174  std::string pre = " ";
175 
176  os << "{ Prof::LoadMap\n";
177  for (LMId_t i = LoadMap::LMId_NULL; i <= size(); ++i) {
178  LoadMap::LM* lm = this->lm(i);
179  os << pre << i << " : " << lm->toString() << std::endl;
180  }
181  os << "}\n";
182 }
183 
184 
185 void
187 {
188  dump(std::cerr);
189 }
190 
191 
192 //****************************************************************************
193 // LoadMap::LM
194 //****************************************************************************
195 
196 LoadMap::LM::LM(const std::string& name)
197  : m_id(LMId_NULL), m_name(name), m_isUsed(false)
198 {
199 }
200 
201 
203 {
204 }
205 
206 
207 std::string
209 {
210  std::ostringstream os;
211  dump(os);
212  return os.str();
213 }
214 
215 
216 void
217 LoadMap::LM::dump(std::ostream& os) const
218 {
219  os << m_id << ": " << m_name;
220 }
221 
222 
223 void
225 {
226  dump(std::cerr);
227 }
228 
229 
230 } // namespace Prof
LM(const std::string &name="")
Definition: LoadMap.cpp:196
virtual ~LM()
Definition: LoadMap.cpp:202
LM * lm(LMId_t id) const
Definition: LoadMap.hpp:230
LMSet_nm::iterator lm_end_nm()
Definition: LoadMap.hpp:249
LMId_t id() const
Definition: LoadMap.hpp:123
LMVec m_lm_byId
Definition: LoadMap.hpp:283
std::string toString() const
Definition: LoadMap.cpp:163
const std::string & name() const
Definition: LoadMap.hpp:128
LMSet_nm::iterator lm_find(const std::string &nm) const
Definition: LoadMap.cpp:119
void lm_insert(LoadMap::LM *x)
Definition: LoadMap.cpp:107
unsigned int uint
Definition: uint.h:124
static const std::string UnknownLMNm
static const LMId_t LMId_NULL
Definition: LoadMap.hpp:108
LMSet_nm m_lm_byName
Definition: LoadMap.hpp:284
LMId_t size() const
Definition: LoadMap.hpp:225
void dump(std::ostream &os=std::cerr) const
Definition: LoadMap.cpp:172
void ddump() const
Definition: LoadMap.cpp:224
LoadMap(const uint i=32)
Definition: LoadMap.cpp:85
void dump(std::ostream &os=std::cerr) const
Definition: LoadMap.cpp:217
void ddump() const
Definition: LoadMap.cpp:186
void isUsedMrg(bool x)
Definition: LoadMap.hpp:150
bool isUsed() const
Definition: LoadMap.hpp:142
#define NULL
Definition: ElfHelper.cpp:85
std::vector< LoadMap::MergeEffect > * merge(const LoadMap &y)
Definition: LoadMap.cpp:130
std::string m_name
Definition: LoadMap.hpp:173
std::string toString() const
Definition: LoadMap.cpp:208