@@ -87,13 +87,28 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
8787 continue ;
8888
8989 uint32_t NumSecondaryEntryPoints = 0 ;
90- Function.forEachEntryPoint ([&](uint64_t Offset, const MCSymbol *) {
91- if (!Offset)
92- return true ;
90+ for (const BinaryBasicBlock &BB : llvm::drop_begin (Function)) {
91+ if (BB.isEntryPoint ()) {
92+ ++NumSecondaryEntryPoints;
93+ SecondaryEntryPointsMap[OutputAddress].push_back (BB.getOffset ());
94+ continue ;
95+ }
96+ // Add call continuation landing pads, offset by function size
97+ if (!BB.isLandingPad ())
98+ continue ;
99+ const BinaryBasicBlock *PrevBB =
100+ Function.getLayout ().getBlock (BB.getIndex () - 1 );
101+ if (!PrevBB->isSuccessor (&BB))
102+ continue ;
103+ const MCInst *Instr = PrevBB->getLastNonPseudoInstr ();
104+ if (!Instr || !BC.MIB ->isCall (*Instr))
105+ continue ;
93106 ++NumSecondaryEntryPoints;
94- SecondaryEntryPointsMap[OutputAddress].push_back (Offset);
95- return true ;
96- });
107+ SecondaryEntryPointsMap[OutputAddress].push_back (
108+ Function.getOutputSize () + BB.getOffset ());
109+ }
110+ if (NumSecondaryEntryPoints)
111+ llvm::sort (SecondaryEntryPointsMap[OutputAddress]);
97112
98113 LLVM_DEBUG (dbgs () << " Function name: " << Function.getPrintName () << " \n " );
99114 LLVM_DEBUG (dbgs () << " Address reference: 0x"
@@ -145,7 +160,6 @@ void BoltAddressTranslation::write(const BinaryContext &BC, raw_ostream &OS) {
145160 uint64_t PrevAddress = 0 ;
146161 writeMaps</* Cold=*/ false >(PrevAddress, OS);
147162 writeMaps</* Cold=*/ true >(PrevAddress, OS);
148- writeCallContLandingPads (OS);
149163
150164 BC.outs () << " BOLT-INFO: Wrote " << Maps.size () << " BAT maps\n " ;
151165 BC.outs () << " BOLT-INFO: Wrote " << FuncHashes.getNumFunctions ()
@@ -292,15 +306,6 @@ void BoltAddressTranslation::writeMaps(uint64_t &PrevAddress, raw_ostream &OS) {
292306 }
293307}
294308
295- void BoltAddressTranslation::writeCallContLandingPads (raw_ostream &OS) {
296- encodeULEB128 (CallContLandingPadAddrs.size (), OS);
297- uint64_t PrevAddress = 0 ;
298- for (const uint64_t Address : CallContLandingPadAddrs) {
299- encodeULEB128 (Address - PrevAddress, OS);
300- PrevAddress = Address;
301- }
302- }
303-
304309std::error_code BoltAddressTranslation::parse (raw_ostream &OS, StringRef Buf) {
305310 DataExtractor DE = DataExtractor (Buf, true , 8 );
306311 uint64_t Offset = 0 ;
@@ -325,8 +330,6 @@ std::error_code BoltAddressTranslation::parse(raw_ostream &OS, StringRef Buf) {
325330 parseMaps</* Cold=*/ false >(PrevAddress, DE, Offset, Err);
326331 parseMaps</* Cold=*/ true >(PrevAddress, DE, Offset, Err);
327332 OS << " BOLT-INFO: Parsed " << Maps.size () << " BAT entries\n " ;
328- if (Offset < Buf.size ())
329- parseCallContLandingPads (DE, Offset, Err);
330333 return errorToErrorCode (std::move (Err));
331334}
332335
@@ -446,21 +449,6 @@ void BoltAddressTranslation::parseMaps(uint64_t &PrevAddress, DataExtractor &DE,
446449 }
447450}
448451
449- void BoltAddressTranslation::parseCallContLandingPads (DataExtractor &DE,
450- uint64_t &Offset,
451- Error &Err) {
452- const uint32_t NumEntries = DE.getULEB128 (&Offset, &Err);
453- LLVM_DEBUG (dbgs () << " Parsing " << NumEntries
454- << " call continuation landing pad entries\n " );
455- CallContLandingPadAddrs.reserve (NumEntries);
456- uint64_t PrevAddress = 0 ;
457- for (uint32_t I = 0 ; I < NumEntries; ++I) {
458- const uint64_t Address = PrevAddress + DE.getULEB128 (&Offset, &Err);
459- CallContLandingPadAddrs.emplace_back (Address);
460- PrevAddress = Address;
461- }
462- }
463-
464452void BoltAddressTranslation::dump (raw_ostream &OS) const {
465453 const size_t NumTables = Maps.size ();
466454 OS << " BAT tables for " << NumTables << " functions:\n " ;
@@ -609,25 +597,14 @@ void BoltAddressTranslation::saveMetadata(BinaryContext &BC) {
609597 // changed
610598 if (BF.isIgnored () || (!BC.HasRelocations && !BF.isSimple ()))
611599 continue ;
612- const uint64_t FuncAddress = BF.getAddress ();
613600 // Prepare function and block hashes
614- FuncHashes.addEntry (FuncAddress , BF.computeHash ());
601+ FuncHashes.addEntry (BF. getAddress () , BF.computeHash ());
615602 BF.computeBlockHashes ();
616- BBHashMapTy &BBHashMap = getBBHashMap (FuncAddress );
603+ BBHashMapTy &BBHashMap = getBBHashMap (BF. getAddress () );
617604 // Set BF/BB metadata
618- for (const BinaryBasicBlock &BB : BF) {
619- const uint32_t BlockOffset = BB.getInputOffset ();
620- BBHashMap.addEntry (BlockOffset, BB.getIndex (), BB.getHash ());
621- // Set CallContLandingPads
622- if (!BB.isEntryPoint () && BB.isLandingPad ()) {
623- const BinaryBasicBlock *PrevBB =
624- BF.getLayout ().getBlock (BB.getIndex () - 1 );
625- const MCInst *Instr = PrevBB->getLastNonPseudoInstr ();
626- if (Instr && BC.MIB ->isCall (*Instr))
627- CallContLandingPadAddrs.emplace_back (FuncAddress + BlockOffset);
628- }
629- }
630- NumBasicBlocksMap.emplace (FuncAddress, BF.size ());
605+ for (const BinaryBasicBlock &BB : BF)
606+ BBHashMap.addEntry (BB.getInputOffset (), BB.getIndex (), BB.getHash ());
607+ NumBasicBlocksMap.emplace (BF.getAddress (), BF.size ());
631608 }
632609}
633610
@@ -638,8 +615,8 @@ BoltAddressTranslation::getSecondaryEntryPointId(uint64_t Address,
638615 if (FunctionIt == SecondaryEntryPointsMap.end ())
639616 return 0 ;
640617 const std::vector<uint32_t > &Offsets = FunctionIt->second ;
641- auto OffsetIt = std::find (Offsets. begin (), Offsets. end () , Offset);
642- if (OffsetIt == Offsets.end ())
618+ auto OffsetIt = llvm::lower_bound (FunctionIt-> second , Offset);
619+ if (OffsetIt == Offsets.end () || *OffsetIt != Offset )
643620 return 0 ;
644621 // Adding one here because main entry point is not stored in BAT, and
645622 // enumeration for secondary entry points starts with 1.
@@ -675,30 +652,5 @@ BoltAddressTranslation::translateSymbol(const BinaryContext &BC,
675652 return std::pair (ParentBF, SecondaryEntryId);
676653}
677654
678- bool BoltAddressTranslation::isSecondaryEntry (uint64_t OutputAddress,
679- uint32_t Offset) const {
680- const uint64_t InputOffset =
681- translate (OutputAddress, Offset, /* IsBranchSrc*/ false );
682-
683- const uint64_t HotAddress = fetchParentAddress (OutputAddress);
684- auto MapsIter = Maps.find (HotAddress ? HotAddress : OutputAddress);
685- if (MapsIter == Maps.end ())
686- return false ;
687-
688- const uint64_t InputAddress = MapsIter->second .begin ()->second ;
689-
690- auto FunctionIt = SecondaryEntryPointsMap.find (Address);
691- if (FunctionIt == SecondaryEntryPointsMap.end ())
692- return false ;
693- const std::vector<uint32_t > &Offsets = FunctionIt->second ;
694- uint64_t InputOffset = translate (OutputAddress, Offset, /* IsBranchSrc*/ false );
695- auto OffsetIt = llvm::lower_bound (Offsets, InputOffset << 1 );
696- return OffsetIt != Offsets.end () && *OffsetIt >> 1 == InputOffset;
697- }
698-
699- bool BoltAddressTranslation::isCallContinuationLandingPad (
700- uint64_t Address, uint32_t Offset) const {
701- }
702-
703655} // namespace bolt
704656} // namespace llvm
0 commit comments