@@ -173,59 +173,50 @@ void PseudoProbeRewriter::updatePseudoProbes() {
173173 AddressProbesMap &Address2ProbesMap = ProbeDecoder.getAddress2ProbesMap ();
174174 const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap ();
175175
176- for (auto &AP : Address2ProbesMap) {
177- BinaryFunction *F = BC.getBinaryFunctionContainingAddress (AP.first );
176+ for (MCDecodedPseudoProbe &Probe : Address2ProbesMap) {
177+ uint64_t Address = Probe.getAddress ();
178+ BinaryFunction *F = BC.getBinaryFunctionContainingAddress (Address);
178179 // If F is removed, eliminate all probes inside it from inline tree
179180 // Setting probes' addresses as INT64_MAX means elimination
180181 if (!F) {
181- for (MCDecodedPseudoProbe &Probe : AP.second )
182- Probe.setAddress (INT64_MAX);
182+ Probe.setAddress (INT64_MAX);
183183 continue ;
184184 }
185185 // If F is not emitted, the function will remain in the same address as its
186186 // input
187187 if (!F->isEmitted ())
188188 continue ;
189189
190- uint64_t Offset = AP. first - F->getAddress ();
190+ uint64_t Offset = Address - F->getAddress ();
191191 const BinaryBasicBlock *BB = F->getBasicBlockContainingOffset (Offset);
192192 uint64_t BlkOutputAddress = BB->getOutputAddressRange ().first ;
193193 // Check if block output address is defined.
194194 // If not, such block is removed from binary. Then remove the probes from
195195 // inline tree
196196 if (BlkOutputAddress == 0 ) {
197- for (MCDecodedPseudoProbe &Probe : AP.second )
198- Probe.setAddress (INT64_MAX);
197+ Probe.setAddress (INT64_MAX);
199198 continue ;
200199 }
201200
202- unsigned ProbeTrack = AP.second .size ();
203- auto Probe = llvm::map_iterator (
204- AP.second .begin (),
205- [](auto RW) -> MCDecodedPseudoProbe & { return RW.get (); });
206- while (ProbeTrack != 0 ) {
207- if (Probe->isBlock ()) {
208- Probe->setAddress (BlkOutputAddress);
209- } else if (Probe->isCall ()) {
210- // A call probe may be duplicated due to ICP
211- // Go through output of InputOffsetToAddressMap to collect all related
212- // probes
213- auto CallOutputAddresses = BC.getIOAddressMap ().lookupAll (AP.first );
214- auto CallOutputAddress = CallOutputAddresses.first ;
215- if (CallOutputAddress == CallOutputAddresses.second ) {
216- Probe->setAddress (INT64_MAX);
217- } else {
218- Probe->setAddress (CallOutputAddress->second );
219- CallOutputAddress = std::next (CallOutputAddress);
220- }
221-
222- while (CallOutputAddress != CallOutputAddresses.second ) {
223- ProbeDecoder.addInjectedProbe (*Probe, CallOutputAddress->second );
224- CallOutputAddress = std::next (CallOutputAddress);
225- }
201+ if (Probe.isBlock ()) {
202+ Probe.setAddress (BlkOutputAddress);
203+ } else if (Probe.isCall ()) {
204+ // A call probe may be duplicated due to ICP
205+ // Go through output of InputOffsetToAddressMap to collect all related
206+ // probes
207+ auto CallOutputAddresses = BC.getIOAddressMap ().lookupAll (Address);
208+ auto CallOutputAddress = CallOutputAddresses.first ;
209+ if (CallOutputAddress == CallOutputAddresses.second ) {
210+ Probe.setAddress (INT64_MAX);
211+ } else {
212+ Probe.setAddress (CallOutputAddress->second );
213+ CallOutputAddress = std::next (CallOutputAddress);
214+ }
215+
216+ while (CallOutputAddress != CallOutputAddresses.second ) {
217+ ProbeDecoder.addInjectedProbe (Probe, CallOutputAddress->second );
218+ CallOutputAddress = std::next (CallOutputAddress);
226219 }
227- Probe = std::next (Probe);
228- ProbeTrack--;
229220 }
230221 }
231222
@@ -241,22 +232,16 @@ void PseudoProbeRewriter::updatePseudoProbes() {
241232 BinaryBlock.getName ();
242233
243234 // scan all addresses -> correlate probe to block when print out
244- std::vector<uint64_t > Addresses;
245- for (auto &Entry : Address2ProbesMap)
246- Addresses.push_back (Entry.first );
247- llvm::sort (Addresses);
248- for (uint64_t Key : Addresses) {
249- for (MCDecodedPseudoProbe &Probe : Address2ProbesMap[Key]) {
250- if (Probe.getAddress () == INT64_MAX)
251- outs () << " Deleted Probe: " ;
252- else
253- outs () << " Address: " << format_hex (Probe.getAddress (), 8 ) << " " ;
254- Probe.print (outs (), GUID2Func, true );
255- // print block name only if the probe is block type and undeleted.
256- if (Probe.isBlock () && Probe.getAddress () != INT64_MAX)
257- outs () << format_hex (Probe.getAddress (), 8 ) << " Probe is in "
258- << Addr2BlockNames[Probe.getAddress ()] << " \n " ;
259- }
235+ for (MCDecodedPseudoProbe &Probe : Address2ProbesMap) {
236+ if (Probe.getAddress () == INT64_MAX)
237+ outs () << " Deleted Probe: " ;
238+ else
239+ outs () << " Address: " << format_hex (Probe.getAddress (), 8 ) << " " ;
240+ Probe.print (outs (), GUID2Func, true );
241+ // print block name only if the probe is block type and undeleted.
242+ if (Probe.isBlock () && Probe.getAddress () != INT64_MAX)
243+ outs () << format_hex (Probe.getAddress (), 8 ) << " Probe is in "
244+ << Addr2BlockNames[Probe.getAddress ()] << " \n " ;
260245 }
261246 outs () << " =======================================\n " ;
262247 }
0 commit comments