@@ -1326,16 +1326,24 @@ static unsigned getBBAddrMapMetadata(const MachineBasicBlock &MBB) {
1326
1326
(const_cast <MachineBasicBlock &>(MBB).canFallThrough () << 3 );
1327
1327
}
1328
1328
1329
- void emitYkBBAddrMapSymbol (const MachineFunction &MF, MCStreamer &OutStreamer,
1329
+ // / Emit a start (or stop) marker symbol into the `.llvm_bb_addr_map` section
1330
+ // / so that we can find the extent of the section at runtime.
1331
+ // /
1332
+ // / The `MCStreamer` should be primed to output to the `.llvm_bb_addr_map`
1333
+ // / section prior to calling this function.
1334
+ // /
1335
+ // / This assumes that LTO is being used (as is required for the Yk JIT), and
1336
+ // / thus that there is only a single `Module` in play, and in turn that no
1337
+ // / symbol clashes can occur.
1338
+ void emitYkBBAddrMapSymbol (MCContext &MCtxt, MCStreamer &OutStreamer,
1330
1339
bool Start) {
1331
- std::string SymName (" ykllvm.bbaddrmap." );
1332
- SymName.append (MF.getName ().str ());
1340
+ std::string SymName (" ykllvm.bbaddrmaps" );
1333
1341
if (Start)
1334
1342
SymName.append (" .start" );
1335
1343
else
1336
- SymName.append (" .end " );
1344
+ SymName.append (" .stop " );
1337
1345
1338
- MCSymbol *Sym = MF. getContext () .getOrCreateSymbol (SymName);
1346
+ MCSymbol *Sym = MCtxt .getOrCreateSymbol (SymName);
1339
1347
OutStreamer.emitSymbolAttribute (Sym, llvm::MCSA_Global);
1340
1348
OutStreamer.emitLabel (Sym);
1341
1349
}
@@ -1350,9 +1358,16 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1350
1358
OutStreamer->pushSection ();
1351
1359
OutStreamer->switchSection (BBAddrMapSection);
1352
1360
1353
- // Add the `ykllvm.bbaddrmap.<func>.start` symbol.
1354
- if (YkAllocLLVMBBAddrMapSection)
1355
- emitYkBBAddrMapSymbol (MF, *OutStreamer, true );
1361
+ if (YkAllocLLVMBBAddrMapSection) {
1362
+ if (!YkEmittedFirstBBAddrMap) {
1363
+ // Add the `ykllvm.bbaddrmaps.start` symbol.
1364
+ emitYkBBAddrMapSymbol (MF.getContext (), *OutStreamer, true );
1365
+ YkEmittedFirstBBAddrMap = true ;
1366
+ }
1367
+ // We cache the last seen bbaddrmap section fragment so that we can insert
1368
+ // the stop symbol when the asmprinter is finalising.
1369
+ YkLastBBAddrMapSection = BBAddrMapSection;
1370
+ }
1356
1371
1357
1372
OutStreamer->AddComment (" version" );
1358
1373
OutStreamer->emitInt8 (OutStreamer->getContext ().getBBAddrMapVersion ());
@@ -1443,10 +1458,6 @@ void AsmPrinter::emitBBAddrMapSection(const MachineFunction &MF) {
1443
1458
}
1444
1459
}
1445
1460
1446
- // Add the `ykllvm.bbaddrmap.<func>.end` symbol.
1447
- if (YkAllocLLVMBBAddrMapSection)
1448
- emitYkBBAddrMapSymbol (MF, *OutStreamer, false );
1449
-
1450
1461
OutStreamer->popSection ();
1451
1462
}
1452
1463
@@ -2030,6 +2041,14 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
2030
2041
}
2031
2042
2032
2043
bool AsmPrinter::doFinalization (Module &M) {
2044
+ if (YkAllocLLVMBBAddrMapSection && YkEmittedFirstBBAddrMap) {
2045
+ // Add the `ykllvm.bbaddrmaps.stop` symbol.
2046
+ OutStreamer->pushSection ();
2047
+ OutStreamer->switchSection (YkLastBBAddrMapSection);
2048
+ emitYkBBAddrMapSymbol (OutContext, *OutStreamer, false );
2049
+ OutStreamer->popSection ();
2050
+ }
2051
+
2033
2052
// The `embed-bitcode` flag serialises the IR after only architecture
2034
2053
// agnostic optimisations have been run, but then proceeds to apply other
2035
2054
// optimisations and transformations afterwards. Sometimes this final version
0 commit comments