-///
-void StackMaps::serializeToStackMapSection() {
- // Bail out if there's no stack map data.
- if (CSInfos.empty())
- return;
-
- MCContext &OutContext = AP.OutStreamer.getContext();
- const TargetRegisterInfo *TRI = AP.TM.getRegisterInfo();
-
- // Create the section.
- const MCSection *StackMapSection =
- OutContext.getObjectFileInfo()->getStackMapSection();
- AP.OutStreamer.SwitchSection(StackMapSection);
-
- // Emit a dummy symbol to force section inclusion.
- AP.OutStreamer.EmitLabel(
- OutContext.GetOrCreateSymbol(Twine("__LLVM_StackMaps")));
-
- // Serialize data.
- const char *WSMP = "Stack Maps: ";
- (void)WSMP;
-
- DEBUG(dbgs() << "********** Stack Map Output **********\n");
-
- // Header.
- AP.OutStreamer.EmitIntValue(1, 1); // Version.
- AP.OutStreamer.EmitIntValue(0, 1); // Reserved.
- AP.OutStreamer.EmitIntValue(0, 2); // Reserved.
-
- // Num functions.
- DEBUG(dbgs() << WSMP << "#functions = " << FnStackSize.size() << '\n');
- AP.OutStreamer.EmitIntValue(FnStackSize.size(), 4);
- // Num constants.
- DEBUG(dbgs() << WSMP << "#constants = " << ConstPool.size()
- << '\n');
- AP.OutStreamer.EmitIntValue(ConstPool.size(), 4);
- // Num callsites.
- DEBUG(dbgs() << WSMP << "#callsites = " << CSInfos.size() << '\n');
- AP.OutStreamer.EmitIntValue(CSInfos.size(), 4);
-
- // Function stack size entries.
- for (FnStackSizeMap::iterator I = FnStackSize.begin(), E = FnStackSize.end();
- I != E; ++I) {
- AP.OutStreamer.EmitSymbolValue(I->first, 8);
- AP.OutStreamer.EmitIntValue(I->second, 8);
- }
-
- // Constant pool entries.
- for (auto Constant : ConstPool)
- AP.OutStreamer.EmitIntValue(Constant.second, 8);
-