@@ -70,7 +70,7 @@ class BinaryFunction;
7070class BoltAddressTranslation {
7171public:
7272 // In-memory representation of the address translation table
73- using MapTy = std::map <uint32_t , uint32_t >;
73+ using MapTy = std::multimap <uint32_t , uint32_t >;
7474
7575 // List of taken fall-throughs
7676 using FallthroughListTy = SmallVector<std::pair<uint64_t , uint64_t >, 16 >;
@@ -90,7 +90,7 @@ class BoltAddressTranslation {
9090 std::error_code parse (raw_ostream &OS, StringRef Buf);
9191
9292 // / Dump the parsed address translation tables
93- void dump (raw_ostream &OS);
93+ void dump (raw_ostream &OS) const ;
9494
9595 // / If the maps are loaded in memory, perform the lookup to translate LBR
9696 // / addresses in function located at \p FuncAddress.
@@ -107,7 +107,12 @@ class BoltAddressTranslation {
107107
108108 // / If available, fetch the address of the hot part linked to the cold part
109109 // / at \p Address. Return 0 otherwise.
110- uint64_t fetchParentAddress (uint64_t Address) const ;
110+ uint64_t fetchParentAddress (uint64_t Address) const {
111+ auto Iter = ColdPartSource.find (Address);
112+ if (Iter == ColdPartSource.end ())
113+ return 0 ;
114+ return Iter->second ;
115+ }
111116
112117 // / True if the input binary has a translation table we can use to convert
113118 // / addresses when aggregating profile
@@ -132,7 +137,8 @@ class BoltAddressTranslation {
132137 // / emitted for the start of the BB. More entries may be emitted to cover
133138 // / the location of calls or any instruction that may change control flow.
134139 void writeEntriesForBB (MapTy &Map, const BinaryBasicBlock &BB,
135- uint64_t FuncInputAddress, uint64_t FuncOutputAddress);
140+ uint64_t FuncInputAddress,
141+ uint64_t FuncOutputAddress) const ;
136142
137143 // / Write the serialized address translation table for a function.
138144 template <bool Cold>
@@ -147,7 +153,7 @@ class BoltAddressTranslation {
147153
148154 // / Returns the bitmask with set bits corresponding to indices of BRANCHENTRY
149155 // / entries in function address translation map.
150- APInt calculateBranchEntriesBitMask (MapTy &Map, size_t EqualElems);
156+ APInt calculateBranchEntriesBitMask (MapTy &Map, size_t EqualElems) const ;
151157
152158 // / Calculate the number of equal offsets (output = input - skew) in the
153159 // / beginning of the function.
@@ -178,14 +184,9 @@ class BoltAddressTranslation {
178184public:
179185 // / Map basic block input offset to a basic block index and hash pair.
180186 class BBHashMapTy {
181- class EntryTy {
187+ struct EntryTy {
182188 unsigned Index;
183189 size_t Hash;
184-
185- public:
186- unsigned getBBIndex () const { return Index; }
187- size_t getBBHash () const { return Hash; }
188- EntryTy (unsigned Index, size_t Hash) : Index(Index), Hash(Hash) {}
189190 };
190191
191192 std::map<uint32_t , EntryTy> Map;
@@ -201,34 +202,30 @@ class BoltAddressTranslation {
201202 }
202203
203204 unsigned getBBIndex (uint32_t BBInputOffset) const {
204- return getEntry (BBInputOffset).getBBIndex () ;
205+ return getEntry (BBInputOffset).Index ;
205206 }
206207
207208 size_t getBBHash (uint32_t BBInputOffset) const {
208- return getEntry (BBInputOffset).getBBHash () ;
209+ return getEntry (BBInputOffset).Hash ;
209210 }
210211
211212 void addEntry (uint32_t BBInputOffset, unsigned BBIndex, size_t BBHash) {
212- Map.emplace (BBInputOffset, EntryTy ( BBIndex, BBHash) );
213+ Map.emplace (BBInputOffset, EntryTy{ BBIndex, BBHash} );
213214 }
214215
215216 size_t getNumBasicBlocks () const { return Map.size (); }
216217
217218 auto begin () const { return Map.begin (); }
218219 auto end () const { return Map.end (); }
219220 auto upper_bound (uint32_t Offset) const { return Map.upper_bound (Offset); }
221+ auto size () const { return Map.size (); }
220222 };
221223
222224 // / Map function output address to its hash and basic blocks hash map.
223225 class FuncHashesTy {
224- class EntryTy {
226+ struct EntryTy {
225227 size_t Hash;
226228 BBHashMapTy BBHashMap;
227-
228- public:
229- size_t getBFHash () const { return Hash; }
230- const BBHashMapTy &getBBHashMap () const { return BBHashMap; }
231- EntryTy (size_t Hash) : Hash(Hash) {}
232229 };
233230
234231 std::unordered_map<uint64_t , EntryTy> Map;
@@ -240,23 +237,23 @@ class BoltAddressTranslation {
240237
241238 public:
242239 size_t getBFHash (uint64_t FuncOutputAddress) const {
243- return getEntry (FuncOutputAddress).getBFHash () ;
240+ return getEntry (FuncOutputAddress).Hash ;
244241 }
245242
246243 const BBHashMapTy &getBBHashMap (uint64_t FuncOutputAddress) const {
247- return getEntry (FuncOutputAddress).getBBHashMap () ;
244+ return getEntry (FuncOutputAddress).BBHashMap ;
248245 }
249246
250247 void addEntry (uint64_t FuncOutputAddress, size_t BFHash) {
251- Map.emplace (FuncOutputAddress, EntryTy ( BFHash) );
248+ Map.emplace (FuncOutputAddress, EntryTy{ BFHash, BBHashMapTy ()} );
252249 }
253250
254251 size_t getNumFunctions () const { return Map.size (); };
255252
256253 size_t getNumBasicBlocks () const {
257254 size_t NumBasicBlocks{0 };
258255 for (auto &I : Map)
259- NumBasicBlocks += I.second .getBBHashMap () .getNumBasicBlocks ();
256+ NumBasicBlocks += I.second .BBHashMap .getNumBasicBlocks ();
260257 return NumBasicBlocks;
261258 }
262259 };
@@ -278,7 +275,9 @@ class BoltAddressTranslation {
278275
279276 // / Returns the number of basic blocks in a function.
280277 size_t getNumBasicBlocks (uint64_t OutputAddress) const {
281- return NumBasicBlocksMap.at (OutputAddress);
278+ auto It = NumBasicBlocksMap.find (OutputAddress);
279+ assert (It != NumBasicBlocksMap.end ());
280+ return It->second ;
282281 }
283282
284283private:
0 commit comments