LLVM  14.0.0git
RecordStreamer.h
Go to the documentation of this file.
1 //===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
10 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
11 
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/MC/MCDirectives.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/Support/SMLoc.h"
17 #include <vector>
18 
19 namespace llvm {
20 
21 class MCSymbol;
22 class Module;
23 
24 class RecordStreamer : public MCStreamer {
25 public:
28 
29 private:
30  const Module &M;
31  StringMap<State> Symbols;
32  // Map of aliases created by .symver directives, saved so we can update
33  // their symbol binding after parsing complete. This maps from each
34  // aliasee to its list of aliases.
36 
37  /// Get the state recorded for the given symbol.
38  State getSymbolState(const MCSymbol *Sym);
39 
40  void markDefined(const MCSymbol &Symbol);
41  void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
42  void markUsed(const MCSymbol &Symbol);
43  void visitUsedSymbol(const MCSymbol &Sym) override;
44 
45 public:
46  RecordStreamer(MCContext &Context, const Module &M);
47 
48  void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
49  void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
50  void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
53  unsigned ByteAlignment, SMLoc Loc = SMLoc()) override;
55  unsigned ByteAlignment) override;
56 
57  // Ignore COFF-specific directives; we do not need any information from them,
58  // but the default implementation of these methods crashes, so we override
59  // them with versions that do nothing.
60  void BeginCOFFSymbolDef(const MCSymbol *Symbol) override {}
62  void EmitCOFFSymbolType(int Type) override {}
63  void EndCOFFSymbolDef() override {}
64 
65  /// Record .symver aliases for later processing.
66  void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name,
67  bool KeepOriginalSym) override;
68 
69  // Emit ELF .symver aliases and ensure they have the same binding as the
70  // defined symbol they alias with.
71  void flushSymverDirectives();
72 
73  // Symbols iterators
77 
78  // SymverAliasMap iterators
79  using const_symver_iterator = decltype(SymverAliasMap)::const_iterator;
81 };
82 
83 } // end namespace llvm
84 
85 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::RecordStreamer::const_symver_iterator
decltype(SymverAliasMap)::const_iterator const_symver_iterator
Definition: RecordStreamer.h:79
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::RecordStreamer::emitLabel
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
Definition: RecordStreamer.cpp:89
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::Attribute
Definition: Attributes.h:52
MCDirectives.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::RecordStreamer::State
State
Definition: RecordStreamer.h:26
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::RecordStreamer::DefinedGlobal
@ DefinedGlobal
Definition: RecordStreamer.h:26
llvm::RecordStreamer::Defined
@ Defined
Definition: RecordStreamer.h:26
llvm::MCSymbolAttr
MCSymbolAttr
Definition: MCDirectives.h:18
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::RecordStreamer::EndCOFFSymbolDef
void EndCOFFSymbolDef() override
Marks the end of the symbol definition.
Definition: RecordStreamer.h:63
llvm::RecordStreamer::emitZerofill
void emitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment, SMLoc Loc=SMLoc()) override
Emit the zerofill section and an optional symbol.
Definition: RecordStreamer.cpp:108
SMLoc.h
llvm::RecordStreamer::begin
const_iterator begin()
Definition: RecordStreamer.cpp:78
llvm::RecordStreamer::emitCommonSymbol
void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override
Emit a common symbol.
Definition: RecordStreamer.cpp:114
StringMap.h
llvm::StringMap< State >
llvm::RecordStreamer::symverAliases
iterator_range< const_symver_iterator > symverAliases()
Definition: RecordStreamer.cpp:133
llvm::XCOFF::StorageClass
StorageClass
Definition: XCOFF.h:113
llvm::RecordStreamer::RecordStreamer
RecordStreamer(MCContext &Context, const Module &M)
Definition: RecordStreamer.cpp:75
uint64_t
llvm::DenseMap
Definition: DenseMap.h:714
llvm::RecordStreamer::BeginCOFFSymbolDef
void BeginCOFFSymbolDef(const MCSymbol *Symbol) override
Start emitting COFF symbol definition.
Definition: RecordStreamer.h:60
llvm::RecordStreamer::DefinedWeak
@ DefinedWeak
Definition: RecordStreamer.h:26
llvm::RecordStreamer::emitSymbolAttribute
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
Definition: RecordStreamer.cpp:99
llvm::RecordStreamer
Definition: RecordStreamer.h:24
llvm::RecordStreamer::EmitCOFFSymbolStorageClass
void EmitCOFFSymbolStorageClass(int StorageClass) override
Emit the storage class of the symbol.
Definition: RecordStreamer.h:61
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
llvm::RecordStreamer::UndefinedWeak
@ UndefinedWeak
Definition: RecordStreamer.h:27
llvm::RecordStreamer::const_iterator
StringMap< State >::const_iterator const_iterator
Definition: RecordStreamer.h:74
llvm::RecordStreamer::end
const_iterator end()
Definition: RecordStreamer.cpp:82
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::RecordStreamer::emitAssignment
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
Definition: RecordStreamer.cpp:94
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::RecordStreamer::Global
@ Global
Definition: RecordStreamer.h:26
llvm::LCOMM::ByteAlignment
@ ByteAlignment
Definition: MCAsmInfo.h:50
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::RecordStreamer::emitELFSymverDirective
void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, bool KeepOriginalSym) override
Record .symver aliases for later processing.
Definition: RecordStreamer.cpp:126
MCStreamer.h
llvm::RecordStreamer::Used
@ Used
Definition: RecordStreamer.h:26
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::RecordStreamer::NeverSeen
@ NeverSeen
Definition: RecordStreamer.h:26
llvm::RecordStreamer::flushSymverDirectives
void flushSymverDirectives()
Definition: RecordStreamer.cpp:137
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::RecordStreamer::EmitCOFFSymbolType
void EmitCOFFSymbolType(int Type) override
Emit the type of the symbol.
Definition: RecordStreamer.h:62
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::RecordStreamer::emitInstruction
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
Definition: RecordStreamer.cpp:84