Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp
35271 views
//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "AddressPool.h"9#include "llvm/ADT/SmallVector.h"10#include "llvm/CodeGen/AsmPrinter.h"11#include "llvm/IR/DataLayout.h"12#include "llvm/MC/MCAsmInfo.h"13#include "llvm/MC/MCStreamer.h"14#include "llvm/Target/TargetLoweringObjectFile.h"15#include <utility>1617using namespace llvm;1819unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {20resetUsedFlag(true);21auto IterBool =22Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));23return IterBool.first->second.Number;24}2526MCSymbol *AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {27static const uint8_t AddrSize = Asm.MAI->getCodePointerSize();2829MCSymbol *EndLabel =30Asm.emitDwarfUnitLength("debug_addr", "Length of contribution");31Asm.OutStreamer->AddComment("DWARF version number");32Asm.emitInt16(Asm.getDwarfVersion());33Asm.OutStreamer->AddComment("Address size");34Asm.emitInt8(AddrSize);35Asm.OutStreamer->AddComment("Segment selector size");36Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.3738return EndLabel;39}4041// Emit addresses into the section given.42void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {43if (isEmpty())44return;4546// Start the dwarf addr section.47Asm.OutStreamer->switchSection(AddrSection);4849MCSymbol *EndLabel = nullptr;5051if (Asm.getDwarfVersion() >= 5)52EndLabel = emitHeader(Asm, AddrSection);5354// Define the symbol that marks the start of the contribution.55// It is referenced via DW_AT_addr_base.56Asm.OutStreamer->emitLabel(AddressTableBaseSym);5758// Order the address pool entries by ID59SmallVector<const MCExpr *, 64> Entries(Pool.size());6061for (const auto &I : Pool)62Entries[I.second.Number] =63I.second.TLS64? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)65: MCSymbolRefExpr::create(I.first, Asm.OutContext);6667for (const MCExpr *Entry : Entries)68Asm.OutStreamer->emitValue(Entry, Asm.MAI->getCodePointerSize());6970if (EndLabel)71Asm.OutStreamer->emitLabel(EndLabel);72}737475