LLVM 20.0.0git
RISCVTargetStreamer.cpp
Go to the documentation of this file.
1//===-- RISCVTargetStreamer.cpp - RISC-V Target Streamer Methods ----------===//
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// This file provides RISC-V specific target streamer methods.
10//
11//===----------------------------------------------------------------------===//
12
13#include "RISCVTargetStreamer.h"
14#include "RISCVBaseInfo.h"
15#include "RISCVMCTargetDesc.h"
16#include "llvm/MC/MCSymbol.h"
21
22using namespace llvm;
23
24// This option controls wether or not we emit ELF attributes for ABI features,
25// like RISC-V atomics or X3 usage.
27 "riscv-abi-attributes",
28 cl::desc("Enable emitting RISC-V ELF attributes for ABI features"),
30
32
35
52 unsigned IntValue,
53 StringRef StringValue) {}
55 assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI");
56 TargetABI = ABI;
57}
58
60 HasRVC = STI.hasFeature(RISCV::FeatureStdExtC) ||
61 STI.hasFeature(RISCV::FeatureStdExtZca);
62 HasTSO = STI.hasFeature(RISCV::FeatureStdExtZtso);
63}
64
66 bool EmitStackAlign) {
67 if (EmitStackAlign) {
68 unsigned StackAlign;
69 if (TargetABI == RISCVABI::ABI_ILP32E)
70 StackAlign = 4;
71 else if (TargetABI == RISCVABI::ABI_LP64E)
72 StackAlign = 8;
73 else
74 StackAlign = 16;
76 }
77
79 STI.hasFeature(RISCV::Feature64Bit), STI.getFeatureBits());
80 if (!ParseResult) {
82 } else {
83 auto &ISAInfo = *ParseResult;
84 emitTextAttribute(RISCVAttrs::ARCH, ISAInfo->toString());
85 }
86
87 if (RiscvAbiAttr && STI.hasFeature(RISCV::FeatureStdExtA)) {
88 unsigned AtomicABITag = static_cast<unsigned>(
89 STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence)
93 }
94}
95
96// This part is for ascii assembly output
99 : RISCVTargetStreamer(S), OS(OS) {}
100
102 OS << "\t.option\tpush\n";
103}
104
106 OS << "\t.option\tpop\n";
107}
108
110 OS << "\t.option\tpic\n";
111}
112
114 OS << "\t.option\tnopic\n";
115}
116
118 OS << "\t.option\trvc\n";
119}
120
122 OS << "\t.option\tnorvc\n";
123}
124
126 OS << "\t.option\trelax\n";
127}
128
130 OS << "\t.option\tnorelax\n";
131}
132
135 OS << "\t.option\tarch";
136 for (const auto &Arg : Args) {
137 OS << ", ";
138 switch (Arg.Type) {
140 break;
142 OS << "+";
143 break;
145 OS << "-";
146 break;
147 }
148 OS << Arg.Value;
149 }
150 OS << "\n";
151}
152
154 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
155}
156
157void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
158 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
159}
160
161void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
163 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
164}
165
166void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
167 unsigned IntValue,
168 StringRef StringValue) {}
169
170void RISCVTargetAsmStreamer::finishAttributeSection() {}
static cl::opt< bool > RiscvAbiAttr("riscv-abi-attributes", cl::desc("Enable emitting RISC-V ELF attributes for ABI features"), cl::Hidden)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Streaming machine code generation interface.
Definition: MCStreamer.h:213
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const FeatureBitset & getFeatureBits() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
Target specific streamer interface.
Definition: MCStreamer.h:94
This class represents success/failure for parsing-like operations that find it important to chain tog...
void emitDirectiveOptionArch(ArrayRef< RISCVOptionArchArg > Args) override
RISCVTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
void emitDirectiveVariantCC(MCSymbol &Symbol) override
virtual void emitDirectiveOptionNoRelax()
virtual void emitAttribute(unsigned Attribute, unsigned Value)
virtual void emitTextAttribute(unsigned Attribute, StringRef String)
virtual void emitDirectiveVariantCC(MCSymbol &Symbol)
void emitTargetAttributes(const MCSubtargetInfo &STI, bool EmitStackAlign)
void setFlagsFromFeatures(const MCSubtargetInfo &STI)
virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue, StringRef StringValue)
void setTargetABI(RISCVABI::ABI ABI)
virtual void emitDirectiveOptionArch(ArrayRef< RISCVOptionArchArg > Args)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
llvm::Expected< std::unique_ptr< RISCVISAInfo > > parseFeatureBits(bool IsRV64, const FeatureBitset &FeatureBits)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167