• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===---------------------------- StackMaps.cpp ---------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/CodeGen/StackMaps.h"
11 #include "llvm/CodeGen/AsmPrinter.h"
12 #include "llvm/CodeGen/MachineFrameInfo.h"
13 #include "llvm/CodeGen/MachineFunction.h"
14 #include "llvm/CodeGen/MachineInstr.h"
15 #include "llvm/IR/DataLayout.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCObjectFileInfo.h"
19 #include "llvm/MC/MCSectionMachO.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Target/TargetMachine.h"
23 #include "llvm/Target/TargetOpcodes.h"
24 #include "llvm/Target/TargetRegisterInfo.h"
25 #include "llvm/Target/TargetSubtargetInfo.h"
26 #include <iterator>
27 
28 using namespace llvm;
29 
30 #define DEBUG_TYPE "stackmaps"
31 
32 static cl::opt<int> StackMapVersion("stackmap-version", cl::init(1),
33   cl::desc("Specify the stackmap encoding version (default = 1)"));
34 
35 const char *StackMaps::WSMP = "Stack Maps: ";
36 
PatchPointOpers(const MachineInstr * MI)37 PatchPointOpers::PatchPointOpers(const MachineInstr *MI)
38   : MI(MI),
39     HasDef(MI->getOperand(0).isReg() && MI->getOperand(0).isDef() &&
40            !MI->getOperand(0).isImplicit()),
41     IsAnyReg(MI->getOperand(getMetaIdx(CCPos)).getImm() == CallingConv::AnyReg)
42 {
43 #ifndef NDEBUG
44   unsigned CheckStartIdx = 0, e = MI->getNumOperands();
45   while (CheckStartIdx < e && MI->getOperand(CheckStartIdx).isReg() &&
46          MI->getOperand(CheckStartIdx).isDef() &&
47          !MI->getOperand(CheckStartIdx).isImplicit())
48     ++CheckStartIdx;
49 
50   assert(getMetaIdx() == CheckStartIdx &&
51          "Unexpected additional definition in Patchpoint intrinsic.");
52 #endif
53 }
54 
getNextScratchIdx(unsigned StartIdx) const55 unsigned PatchPointOpers::getNextScratchIdx(unsigned StartIdx) const {
56   if (!StartIdx)
57     StartIdx = getVarIdx();
58 
59   // Find the next scratch register (implicit def and early clobber)
60   unsigned ScratchIdx = StartIdx, e = MI->getNumOperands();
61   while (ScratchIdx < e &&
62          !(MI->getOperand(ScratchIdx).isReg() &&
63            MI->getOperand(ScratchIdx).isDef() &&
64            MI->getOperand(ScratchIdx).isImplicit() &&
65            MI->getOperand(ScratchIdx).isEarlyClobber()))
66     ++ScratchIdx;
67 
68   assert(ScratchIdx != e && "No scratch register available");
69   return ScratchIdx;
70 }
71 
StackMaps(AsmPrinter & AP)72 StackMaps::StackMaps(AsmPrinter &AP) : AP(AP) {
73   if (StackMapVersion != 1)
74     llvm_unreachable("Unsupported stackmap version!");
75 }
76 
77 /// Go up the super-register chain until we hit a valid dwarf register number.
getDwarfRegNum(unsigned Reg,const TargetRegisterInfo * TRI)78 static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
79   int RegNo = TRI->getDwarfRegNum(Reg, false);
80   for (MCSuperRegIterator SR(Reg, TRI); SR.isValid() && RegNo < 0; ++SR)
81     RegNo = TRI->getDwarfRegNum(*SR, false);
82 
83   assert(RegNo >= 0 && "Invalid Dwarf register number.");
84   return (unsigned) RegNo;
85 }
86 
87 MachineInstr::const_mop_iterator
parseOperand(MachineInstr::const_mop_iterator MOI,MachineInstr::const_mop_iterator MOE,LocationVec & Locs,LiveOutVec & LiveOuts) const88 StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
89                         MachineInstr::const_mop_iterator MOE,
90                         LocationVec &Locs, LiveOutVec &LiveOuts) const {
91   const TargetRegisterInfo *TRI = AP.MF->getSubtarget().getRegisterInfo();
92   if (MOI->isImm()) {
93     switch (MOI->getImm()) {
94     default: llvm_unreachable("Unrecognized operand type.");
95     case StackMaps::DirectMemRefOp: {
96       unsigned Size = AP.TM.getDataLayout()->getPointerSizeInBits();
97       assert((Size % 8) == 0 && "Need pointer size in bytes.");
98       Size /= 8;
99       unsigned Reg = (++MOI)->getReg();
100       int64_t Imm = (++MOI)->getImm();
101       Locs.push_back(Location(StackMaps::Location::Direct, Size,
102                               getDwarfRegNum(Reg, TRI), Imm));
103       break;
104     }
105     case StackMaps::IndirectMemRefOp: {
106       int64_t Size = (++MOI)->getImm();
107       assert(Size > 0 && "Need a valid size for indirect memory locations.");
108       unsigned Reg = (++MOI)->getReg();
109       int64_t Imm = (++MOI)->getImm();
110       Locs.push_back(Location(StackMaps::Location::Indirect, Size,
111                               getDwarfRegNum(Reg, TRI), Imm));
112       break;
113     }
114     case StackMaps::ConstantOp: {
115       ++MOI;
116       assert(MOI->isImm() && "Expected constant operand.");
117       int64_t Imm = MOI->getImm();
118       Locs.push_back(Location(Location::Constant, sizeof(int64_t), 0, Imm));
119       break;
120     }
121     }
122     return ++MOI;
123   }
124 
125   // The physical register number will ultimately be encoded as a DWARF regno.
126   // The stack map also records the size of a spill slot that can hold the
127   // register content. (The runtime can track the actual size of the data type
128   // if it needs to.)
129   if (MOI->isReg()) {
130     // Skip implicit registers (this includes our scratch registers)
131     if (MOI->isImplicit())
132       return ++MOI;
133 
134     assert(TargetRegisterInfo::isPhysicalRegister(MOI->getReg()) &&
135            "Virtreg operands should have been rewritten before now.");
136     const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(MOI->getReg());
137     assert(!MOI->getSubReg() && "Physical subreg still around.");
138 
139     unsigned Offset = 0;
140     unsigned RegNo = getDwarfRegNum(MOI->getReg(), TRI);
141     unsigned LLVMRegNo = TRI->getLLVMRegNum(RegNo, false);
142     unsigned SubRegIdx = TRI->getSubRegIndex(LLVMRegNo, MOI->getReg());
143     if (SubRegIdx)
144       Offset = TRI->getSubRegIdxOffset(SubRegIdx);
145 
146     Locs.push_back(
147       Location(Location::Register, RC->getSize(), RegNo, Offset));
148     return ++MOI;
149   }
150 
151   if (MOI->isRegLiveOut())
152     LiveOuts = parseRegisterLiveOutMask(MOI->getRegLiveOut());
153 
154   return ++MOI;
155 }
156 
print(raw_ostream & OS)157 void StackMaps::print(raw_ostream &OS) {
158   const TargetRegisterInfo *TRI =
159       AP.MF ? AP.MF->getSubtarget().getRegisterInfo() : nullptr;
160   OS << WSMP << "callsites:\n";
161   for (const auto &CSI : CSInfos) {
162     const LocationVec &CSLocs = CSI.Locations;
163     const LiveOutVec &LiveOuts = CSI.LiveOuts;
164 
165     OS << WSMP << "callsite " << CSI.ID << "\n";
166     OS << WSMP << "  has " << CSLocs.size() << " locations\n";
167 
168     unsigned OperIdx = 0;
169     for (const auto &Loc : CSLocs) {
170       OS << WSMP << "  Loc " << OperIdx << ": ";
171       switch (Loc.LocType) {
172       case Location::Unprocessed:
173         OS << "<Unprocessed operand>";
174         break;
175       case Location::Register:
176         OS << "Register ";
177 	if (TRI)
178 	  OS << TRI->getName(Loc.Reg);
179 	else
180 	  OS << Loc.Reg;
181         break;
182       case Location::Direct:
183         OS << "Direct ";
184         if (TRI)
185           OS << TRI->getName(Loc.Reg);
186         else
187           OS << Loc.Reg;
188         if (Loc.Offset)
189           OS << " + " << Loc.Offset;
190         break;
191       case Location::Indirect:
192         OS << "Indirect ";
193         if (TRI)
194           OS << TRI->getName(Loc.Reg);
195         else
196           OS << Loc.Reg;
197         OS << "+" << Loc.Offset;
198         break;
199       case Location::Constant:
200         OS << "Constant " << Loc.Offset;
201         break;
202       case Location::ConstantIndex:
203         OS << "Constant Index " << Loc.Offset;
204         break;
205       }
206       OS << "     [encoding: .byte " << Loc.LocType << ", .byte " << Loc.Size
207          << ", .short " << Loc.Reg << ", .int " << Loc.Offset << "]\n";
208       OperIdx++;
209     }
210 
211     OS << WSMP << "  has " << LiveOuts.size() << " live-out registers\n";
212 
213     OperIdx = 0;
214     for (const auto &LO : LiveOuts) {
215       OS << WSMP << "  LO " << OperIdx << ": ";
216       if (TRI)
217         OS << TRI->getName(LO.Reg);
218       else
219         OS << LO.Reg;
220       OS << "      [encoding: .short " << LO.RegNo << ", .byte 0, .byte "
221          << LO.Size << "]\n";
222       OperIdx++;
223     }
224   }
225 }
226 
227 /// Create a live-out register record for the given register Reg.
228 StackMaps::LiveOutReg
createLiveOutReg(unsigned Reg,const TargetRegisterInfo * TRI) const229 StackMaps::createLiveOutReg(unsigned Reg, const TargetRegisterInfo *TRI) const {
230   unsigned RegNo = getDwarfRegNum(Reg, TRI);
231   unsigned Size = TRI->getMinimalPhysRegClass(Reg)->getSize();
232   return LiveOutReg(Reg, RegNo, Size);
233 }
234 
235 /// Parse the register live-out mask and return a vector of live-out registers
236 /// that need to be recorded in the stackmap.
237 StackMaps::LiveOutVec
parseRegisterLiveOutMask(const uint32_t * Mask) const238 StackMaps::parseRegisterLiveOutMask(const uint32_t *Mask) const {
239   assert(Mask && "No register mask specified");
240   const TargetRegisterInfo *TRI = AP.MF->getSubtarget().getRegisterInfo();
241   LiveOutVec LiveOuts;
242 
243   // Create a LiveOutReg for each bit that is set in the register mask.
244   for (unsigned Reg = 0, NumRegs = TRI->getNumRegs(); Reg != NumRegs; ++Reg)
245     if ((Mask[Reg / 32] >> Reg % 32) & 1)
246       LiveOuts.push_back(createLiveOutReg(Reg, TRI));
247 
248   // We don't need to keep track of a register if its super-register is already
249   // in the list. Merge entries that refer to the same dwarf register and use
250   // the maximum size that needs to be spilled.
251   std::sort(LiveOuts.begin(), LiveOuts.end());
252   for (LiveOutVec::iterator I = LiveOuts.begin(), E = LiveOuts.end();
253        I != E; ++I) {
254     for (LiveOutVec::iterator II = std::next(I); II != E; ++II) {
255       if (I->RegNo != II->RegNo) {
256         // Skip all the now invalid entries.
257         I = --II;
258         break;
259       }
260       I->Size = std::max(I->Size, II->Size);
261       if (TRI->isSuperRegister(I->Reg, II->Reg))
262         I->Reg = II->Reg;
263       II->MarkInvalid();
264     }
265   }
266   LiveOuts.erase(std::remove_if(LiveOuts.begin(), LiveOuts.end(),
267                                 LiveOutReg::IsInvalid), LiveOuts.end());
268   return LiveOuts;
269 }
270 
recordStackMapOpers(const MachineInstr & MI,uint64_t ID,MachineInstr::const_mop_iterator MOI,MachineInstr::const_mop_iterator MOE,bool recordResult)271 void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
272                                     MachineInstr::const_mop_iterator MOI,
273                                     MachineInstr::const_mop_iterator MOE,
274                                     bool recordResult) {
275 
276   MCContext &OutContext = AP.OutStreamer.getContext();
277   MCSymbol *MILabel = OutContext.CreateTempSymbol();
278   AP.OutStreamer.EmitLabel(MILabel);
279 
280   LocationVec Locations;
281   LiveOutVec LiveOuts;
282 
283   if (recordResult) {
284     assert(PatchPointOpers(&MI).hasDef() && "Stackmap has no return value.");
285     parseOperand(MI.operands_begin(), std::next(MI.operands_begin()),
286                  Locations, LiveOuts);
287   }
288 
289   // Parse operands.
290   while (MOI != MOE) {
291     MOI = parseOperand(MOI, MOE, Locations, LiveOuts);
292   }
293 
294   // Move large constants into the constant pool.
295   for (LocationVec::iterator I = Locations.begin(), E = Locations.end();
296        I != E; ++I) {
297     // Constants are encoded as sign-extended integers.
298     // -1 is directly encoded as .long 0xFFFFFFFF with no constant pool.
299     if (I->LocType == Location::Constant && !isInt<32>(I->Offset)) {
300       I->LocType = Location::ConstantIndex;
301       // ConstPool is intentionally a MapVector of 'uint64_t's (as
302       // opposed to 'int64_t's).  We should never be in a situation
303       // where we have to insert either the tombstone or the empty
304       // keys into a map, and for a DenseMap<uint64_t, T> these are
305       // (uint64_t)0 and (uint64_t)-1.  They can be and are
306       // represented using 32 bit integers.
307 
308       assert((uint64_t)I->Offset != DenseMapInfo<uint64_t>::getEmptyKey() &&
309              (uint64_t)I->Offset != DenseMapInfo<uint64_t>::getTombstoneKey() &&
310              "empty and tombstone keys should fit in 32 bits!");
311       auto Result = ConstPool.insert(std::make_pair(I->Offset, I->Offset));
312       I->Offset = Result.first - ConstPool.begin();
313     }
314   }
315 
316   // Create an expression to calculate the offset of the callsite from function
317   // entry.
318   const MCExpr *CSOffsetExpr = MCBinaryExpr::CreateSub(
319     MCSymbolRefExpr::Create(MILabel, OutContext),
320     MCSymbolRefExpr::Create(AP.CurrentFnSymForSize, OutContext),
321     OutContext);
322 
323   CSInfos.emplace_back(CSOffsetExpr, ID, std::move(Locations),
324                        std::move(LiveOuts));
325 
326   // Record the stack size of the current function.
327   const MachineFrameInfo *MFI = AP.MF->getFrameInfo();
328   const TargetRegisterInfo *RegInfo = AP.MF->getSubtarget().getRegisterInfo();
329   const bool DynamicFrameSize = MFI->hasVarSizedObjects() ||
330     RegInfo->needsStackRealignment(*(AP.MF));
331   FnStackSize[AP.CurrentFnSym] =
332     DynamicFrameSize ? UINT64_MAX : MFI->getStackSize();
333 }
334 
recordStackMap(const MachineInstr & MI)335 void StackMaps::recordStackMap(const MachineInstr &MI) {
336   assert(MI.getOpcode() == TargetOpcode::STACKMAP && "expected stackmap");
337 
338   int64_t ID = MI.getOperand(0).getImm();
339   recordStackMapOpers(MI, ID, std::next(MI.operands_begin(), 2),
340                       MI.operands_end());
341 }
342 
recordPatchPoint(const MachineInstr & MI)343 void StackMaps::recordPatchPoint(const MachineInstr &MI) {
344   assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint");
345 
346   PatchPointOpers opers(&MI);
347   int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm();
348 
349   MachineInstr::const_mop_iterator MOI =
350     std::next(MI.operands_begin(), opers.getStackMapStartIdx());
351   recordStackMapOpers(MI, ID, MOI, MI.operands_end(),
352                       opers.isAnyReg() && opers.hasDef());
353 
354 #ifndef NDEBUG
355   // verify anyregcc
356   LocationVec &Locations = CSInfos.back().Locations;
357   if (opers.isAnyReg()) {
358     unsigned NArgs = opers.getMetaOper(PatchPointOpers::NArgPos).getImm();
359     for (unsigned i = 0, e = (opers.hasDef() ? NArgs+1 : NArgs); i != e; ++i)
360       assert(Locations[i].LocType == Location::Register &&
361              "anyreg arg must be in reg.");
362   }
363 #endif
364 }
recordStatepoint(const MachineInstr & MI)365 void StackMaps::recordStatepoint(const MachineInstr &MI) {
366   assert(MI.getOpcode() == TargetOpcode::STATEPOINT &&
367          "expected statepoint");
368 
369   StatepointOpers opers(&MI);
370   // Record all the deopt and gc operands (they're contiguous and run from the
371   // initial index to the end of the operand list)
372   const unsigned StartIdx = opers.getVarIdx();
373   recordStackMapOpers(MI, 0xABCDEF00,
374                       MI.operands_begin() + StartIdx, MI.operands_end(),
375                       false);
376 }
377 
378 /// Emit the stackmap header.
379 ///
380 /// Header {
381 ///   uint8  : Stack Map Version (currently 1)
382 ///   uint8  : Reserved (expected to be 0)
383 ///   uint16 : Reserved (expected to be 0)
384 /// }
385 /// uint32 : NumFunctions
386 /// uint32 : NumConstants
387 /// uint32 : NumRecords
emitStackmapHeader(MCStreamer & OS)388 void StackMaps::emitStackmapHeader(MCStreamer &OS) {
389   // Header.
390   OS.EmitIntValue(StackMapVersion, 1); // Version.
391   OS.EmitIntValue(0, 1); // Reserved.
392   OS.EmitIntValue(0, 2); // Reserved.
393 
394   // Num functions.
395   DEBUG(dbgs() << WSMP << "#functions = " << FnStackSize.size() << '\n');
396   OS.EmitIntValue(FnStackSize.size(), 4);
397   // Num constants.
398   DEBUG(dbgs() << WSMP << "#constants = " << ConstPool.size() << '\n');
399   OS.EmitIntValue(ConstPool.size(), 4);
400   // Num callsites.
401   DEBUG(dbgs() << WSMP << "#callsites = " << CSInfos.size() << '\n');
402   OS.EmitIntValue(CSInfos.size(), 4);
403 }
404 
405 /// Emit the function frame record for each function.
406 ///
407 /// StkSizeRecord[NumFunctions] {
408 ///   uint64 : Function Address
409 ///   uint64 : Stack Size
410 /// }
emitFunctionFrameRecords(MCStreamer & OS)411 void StackMaps::emitFunctionFrameRecords(MCStreamer &OS) {
412   // Function Frame records.
413   DEBUG(dbgs() << WSMP << "functions:\n");
414   for (auto const &FR : FnStackSize) {
415     DEBUG(dbgs() << WSMP << "function addr: " << FR.first
416                          << " frame size: " << FR.second);
417     OS.EmitSymbolValue(FR.first, 8);
418     OS.EmitIntValue(FR.second, 8);
419   }
420 }
421 
422 /// Emit the constant pool.
423 ///
424 /// int64  : Constants[NumConstants]
emitConstantPoolEntries(MCStreamer & OS)425 void StackMaps::emitConstantPoolEntries(MCStreamer &OS) {
426   // Constant pool entries.
427   DEBUG(dbgs() << WSMP << "constants:\n");
428   for (auto ConstEntry : ConstPool) {
429     DEBUG(dbgs() << WSMP << ConstEntry.second << '\n');
430     OS.EmitIntValue(ConstEntry.second, 8);
431   }
432 }
433 
434 /// Emit the callsite info for each callsite.
435 ///
436 /// StkMapRecord[NumRecords] {
437 ///   uint64 : PatchPoint ID
438 ///   uint32 : Instruction Offset
439 ///   uint16 : Reserved (record flags)
440 ///   uint16 : NumLocations
441 ///   Location[NumLocations] {
442 ///     uint8  : Register | Direct | Indirect | Constant | ConstantIndex
443 ///     uint8  : Size in Bytes
444 ///     uint16 : Dwarf RegNum
445 ///     int32  : Offset
446 ///   }
447 ///   uint16 : Padding
448 ///   uint16 : NumLiveOuts
449 ///   LiveOuts[NumLiveOuts] {
450 ///     uint16 : Dwarf RegNum
451 ///     uint8  : Reserved
452 ///     uint8  : Size in Bytes
453 ///   }
454 ///   uint32 : Padding (only if required to align to 8 byte)
455 /// }
456 ///
457 /// Location Encoding, Type, Value:
458 ///   0x1, Register, Reg                 (value in register)
459 ///   0x2, Direct, Reg + Offset          (frame index)
460 ///   0x3, Indirect, [Reg + Offset]      (spilled value)
461 ///   0x4, Constant, Offset              (small constant)
462 ///   0x5, ConstIndex, Constants[Offset] (large constant)
emitCallsiteEntries(MCStreamer & OS)463 void StackMaps::emitCallsiteEntries(MCStreamer &OS) {
464   DEBUG(print(dbgs()));
465   // Callsite entries.
466   for (const auto &CSI : CSInfos) {
467     const LocationVec &CSLocs = CSI.Locations;
468     const LiveOutVec &LiveOuts = CSI.LiveOuts;
469 
470     // Verify stack map entry. It's better to communicate a problem to the
471     // runtime than crash in case of in-process compilation. Currently, we do
472     // simple overflow checks, but we may eventually communicate other
473     // compilation errors this way.
474     if (CSLocs.size() > UINT16_MAX || LiveOuts.size() > UINT16_MAX) {
475       OS.EmitIntValue(UINT64_MAX, 8); // Invalid ID.
476       OS.EmitValue(CSI.CSOffsetExpr, 4);
477       OS.EmitIntValue(0, 2); // Reserved.
478       OS.EmitIntValue(0, 2); // 0 locations.
479       OS.EmitIntValue(0, 2); // padding.
480       OS.EmitIntValue(0, 2); // 0 live-out registers.
481       OS.EmitIntValue(0, 4); // padding.
482       continue;
483     }
484 
485     OS.EmitIntValue(CSI.ID, 8);
486     OS.EmitValue(CSI.CSOffsetExpr, 4);
487 
488     // Reserved for flags.
489     OS.EmitIntValue(0, 2);
490     OS.EmitIntValue(CSLocs.size(), 2);
491 
492     for (const auto &Loc : CSLocs) {
493       OS.EmitIntValue(Loc.LocType, 1);
494       OS.EmitIntValue(Loc.Size, 1);
495       OS.EmitIntValue(Loc.Reg, 2);
496       OS.EmitIntValue(Loc.Offset, 4);
497     }
498 
499     // Num live-out registers and padding to align to 4 byte.
500     OS.EmitIntValue(0, 2);
501     OS.EmitIntValue(LiveOuts.size(), 2);
502 
503     for (const auto &LO : LiveOuts) {
504       OS.EmitIntValue(LO.RegNo, 2);
505       OS.EmitIntValue(0, 1);
506       OS.EmitIntValue(LO.Size, 1);
507     }
508     // Emit alignment to 8 byte.
509     OS.EmitValueToAlignment(8);
510   }
511 }
512 
513 /// Serialize the stackmap data.
serializeToStackMapSection()514 void StackMaps::serializeToStackMapSection() {
515   (void) WSMP;
516   // Bail out if there's no stack map data.
517   assert((!CSInfos.empty() || (CSInfos.empty() && ConstPool.empty())) &&
518          "Expected empty constant pool too!");
519   assert((!CSInfos.empty() || (CSInfos.empty() && FnStackSize.empty())) &&
520          "Expected empty function record too!");
521   if (CSInfos.empty())
522     return;
523 
524   MCContext &OutContext = AP.OutStreamer.getContext();
525   MCStreamer &OS = AP.OutStreamer;
526 
527   // Create the section.
528   const MCSection *StackMapSection =
529     OutContext.getObjectFileInfo()->getStackMapSection();
530   OS.SwitchSection(StackMapSection);
531 
532   // Emit a dummy symbol to force section inclusion.
533   OS.EmitLabel(OutContext.GetOrCreateSymbol(Twine("__LLVM_StackMaps")));
534 
535   // Serialize data.
536   DEBUG(dbgs() << "********** Stack Map Output **********\n");
537   emitStackmapHeader(OS);
538   emitFunctionFrameRecords(OS);
539   emitConstantPoolEntries(OS);
540   emitCallsiteEntries(OS);
541   OS.AddBlankLine();
542 
543   // Clean up.
544   CSInfos.clear();
545   ConstPool.clear();
546 }
547