[llvm-exegesis][NFC] Pass Instruction instead of bare Opcode
[llvm-core.git] / lib / Object / RecordStreamer.h
blob3d5ae59b58fe71d4ecac2aa56cef335a21b11fb1
1 //===- RecordStreamer.h - Record asm defined and used symbols ---*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_OBJECT_RECORDSTREAMER_H
11 #define LLVM_LIB_OBJECT_RECORDSTREAMER_H
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/MC/MCDirectives.h"
16 #include "llvm/MC/MCStreamer.h"
17 #include "llvm/MC/MCSymbol.h"
18 #include "llvm/Support/SMLoc.h"
19 #include <vector>
21 namespace llvm {
23 class GlobalValue;
24 class Module;
26 class RecordStreamer : public MCStreamer {
27 public:
28 enum State { NeverSeen, Global, Defined, DefinedGlobal, DefinedWeak, Used,
29 UndefinedWeak};
31 private:
32 const Module &M;
33 StringMap<State> Symbols;
34 // Map of aliases created by .symver directives, saved so we can update
35 // their symbol binding after parsing complete. This maps from each
36 // aliasee to its list of aliases.
37 DenseMap<const MCSymbol *, std::vector<StringRef>> SymverAliasMap;
39 /// Get the state recorded for the given symbol.
40 State getSymbolState(const MCSymbol *Sym);
42 void markDefined(const MCSymbol &Symbol);
43 void markGlobal(const MCSymbol &Symbol, MCSymbolAttr Attribute);
44 void markUsed(const MCSymbol &Symbol);
45 void visitUsedSymbol(const MCSymbol &Sym) override;
47 public:
48 RecordStreamer(MCContext &Context, const Module &M);
50 void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
51 bool) override;
52 void EmitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
53 void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
54 bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override;
55 void EmitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size,
56 unsigned ByteAlignment, SMLoc Loc = SMLoc()) override;
57 void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
58 unsigned ByteAlignment) override;
59 /// Record .symver aliases for later processing.
60 void emitELFSymverDirective(StringRef AliasName,
61 const MCSymbol *Aliasee) override;
63 // Emit ELF .symver aliases and ensure they have the same binding as the
64 // defined symbol they alias with.
65 void flushSymverDirectives();
67 // Symbols iterators
68 using const_iterator = StringMap<State>::const_iterator;
69 const_iterator begin();
70 const_iterator end();
72 // SymverAliasMap iterators
73 using const_symver_iterator = decltype(SymverAliasMap)::const_iterator;
74 iterator_range<const_symver_iterator> symverAliases();
77 } // end namespace llvm
79 #endif // LLVM_LIB_OBJECT_RECORDSTREAMER_H