LLVM 24.0.0git
RISCVELFStreamer.h
Go to the documentation of this file.
1//===-- RISCVELFStreamer.h - RISC-V ELF Target Streamer ---------*- 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_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
10#define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
11
12#include "RISCVTargetStreamer.h"
15
16namespace llvm {
17
19 void reset() override;
20 void emitDataMappingSymbol();
21 void emitInstructionsMappingSymbol();
22 void emitMappingSymbol(StringRef Name);
23
24 enum ElfMappingSymbol { EMS_None, EMS_Instructions, EMS_Data };
25
27 ElfMappingSymbol LastEMS = EMS_None;
28
29 // Active ISA string propagated from RISCVTargetELFStreamer. When non-empty,
30 // it is used as the suffix for "$x<ISA>" mapping symbols.
31 std::string MappingSymbolArch;
32
33 // ISA suffix last emitted via "$x<ISA>" in the current section, and the
34 // per-section history preserved across changeSection. A new mapping symbol
35 // is emitted whenever LastEMS != EMS_Instructions or
36 // LastEmittedArch != MappingSymbolArch, so the ISA in effect at each
37 // instruction run is always recorded.
38 std::string LastEmittedArch;
39 DenseMap<const MCSection *, std::string> LastEmittedArchInSection;
40
41public:
42 RISCVELFStreamer(MCContext &C, std::unique_ptr<MCAsmBackend> MAB,
43 std::unique_ptr<MCObjectWriter> MOW,
44 std::unique_ptr<MCCodeEmitter> MCE);
45
46 void changeSection(MCSection *Section, uint32_t Subsection) override;
47 void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
48 void emitBytes(StringRef Data) override;
49 void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override;
50 void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
51
53};
54
56private:
57 StringRef CurrentVendor;
58
59 // Initial ISA string derived from the subtarget features in the constructor.
60 // Used to re-establish state on reset().
61 std::string InitialArchString;
62
63 // Current ISA string, kept in sync with each .option arch/rvc/norvc/pop
64 // and .attribute arch directive. Used to avoid propagating redundant ISA
65 // updates to the streamer when the ISA does not actually change (e.g.,
66 // .option rvc when C is already enabled).
67 std::string ArchString;
68 SmallVector<std::string, 4> ArchStringStack;
69
70 MCSection *AttributeSection = nullptr;
71
72 void emitAttribute(unsigned Attribute, unsigned Value) override;
73 void emitTextAttribute(unsigned Attribute, StringRef String) override;
74 void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
75 StringRef StringValue) override;
76 void finishAttributeSection() override;
77
78 void reset() override;
79
80public:
83
84 // Update ArchString and propagate the change to the streamer so the next
85 // instruction-run emits an ISA-specific mapping symbol. A no-op when
86 // Arch == ArchString (deduplication).
87 void setArchString(StringRef Arch) override;
88 void emitDirectiveOptionExact() override;
89 void emitDirectiveOptionNoExact() override;
90 void emitDirectiveOptionPIC() override;
91 void emitDirectiveOptionNoPIC() override;
92 void emitDirectiveOptionPop() override;
93 void emitDirectiveOptionPush() override;
94 void emitDirectiveOptionRelax() override;
95 void emitDirectiveOptionNoRelax() override;
96 void emitDirectiveOptionRVC() override;
97 void emitDirectiveOptionNoRVC() override;
98 void emitDirectiveVariantCC(MCSymbol &Symbol) override;
99
100 void emitNoteGnuPropertySection(const uint32_t Feature1And);
101 void finish() override;
102};
103
105 std::unique_ptr<MCAsmBackend> &&MAB,
106 std::unique_ptr<MCObjectWriter> &&MOW,
107 std::unique_ptr<MCCodeEmitter> &&MCE);
108} // namespace llvm
109
110#endif // LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVELFSTREAMER_H
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file defines the SmallVector class.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
Context object for machine code objects.
Definition MCContext.h:83
void reset() override
state management
MCELFStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
Streaming machine code generation interface.
Definition MCStreamer.h:222
Generic base class for all target subtargets.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
void setMappingSymbolArch(StringRef Arch)
void changeSection(MCSection *Section, uint32_t Subsection) override
This is called by popSection and switchSection, if the current section changes.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
RISCVELFStreamer(MCContext &C, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > MOW, std::unique_ptr< MCCodeEmitter > MCE)
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc) override
Emit Size bytes worth of the value specified by FillValue.
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void setArchString(StringRef Arch) override
void emitNoteGnuPropertySection(const uint32_t Feature1And)
void emitDirectiveOptionNoExact() override
RISCVTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
void emitDirectiveVariantCC(MCSymbol &Symbol) override
RISCVELFStreamer & getStreamer()
void emitDirectiveOptionNoRelax() override
Represents a location in source code.
Definition SMLoc.h:22
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
MCStreamer * createRISCVELFStreamer(const Triple &, MCContext &C, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&MOW, std::unique_ptr< MCCodeEmitter > &&MCE)