LLVM 24.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/MCContext.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCSymbol.h"
25
26using namespace llvm;
27
28// This option controls whether or not we emit ELF attributes for ABI features,
29// like RISC-V atomics or X3 usage.
31 "riscv-abi-attributes",
32 cl::desc("Enable emitting RISC-V ELF attributes for ABI features"),
34
36
39
58 unsigned IntValue,
59 StringRef StringValue) {}
60
62 assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI");
63 TargetABI = ABI;
64}
65
67 HasRVC = STI.hasFeature(RISCV::FeatureStdExtZca);
68 HasTSO = STI.hasFeature(RISCV::FeatureStdExtZtso);
69}
70
72 bool EmitStackAlign) {
73 if (EmitStackAlign) {
74 unsigned StackAlign;
75 if (TargetABI == RISCVABI::ABI_ILP32E)
76 StackAlign = 4;
77 else if (TargetABI == RISCVABI::ABI_LP64E)
78 StackAlign = 8;
79 else
80 StackAlign = 16;
82 }
83
85 if (!ParseResult) {
87 } else {
88 auto &ISAInfo = *ParseResult;
89 emitTextAttribute(RISCVAttrs::ARCH, ISAInfo->toString());
90 }
91
92 if (RiscvAbiAttr && STI.hasFeature(RISCV::FeatureStdExtA)) {
93 unsigned AtomicABITag;
94 if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
95 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
96 else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
97 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
98 else
99 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
101 }
102}
103
104// This part is for ascii assembly output
108
110 OS << "\t.option\tpush\n";
111}
112
114 OS << "\t.option\tpop\n";
115}
116
118 OS << "\t.option\tpic\n";
119}
120
122 OS << "\t.option\tnopic\n";
123}
124
126 OS << "\t.option\trvc\n";
127}
128
130 OS << "\t.option\tnorvc\n";
131}
132
134 OS << "\t.option\texact\n";
135}
136
138 OS << "\t.option\tnoexact\n";
139}
140
142 OS << "\t.option\trelax\n";
143}
144
146 OS << "\t.option\tnorelax\n";
147}
148
151 OS << "\t.option\tarch";
152 for (const auto &Arg : Args) {
153 OS << ", ";
154 switch (Arg.Type) {
156 break;
158 OS << "+";
159 break;
161 OS << "-";
162 break;
163 }
164 OS << Arg.Value;
165 }
166 OS << "\n";
167}
168
170 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
171}
172
173void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
174 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
175}
176
177void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
179 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
180}
181
182void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
183 unsigned IntValue,
184 StringRef StringValue) {}
185
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > RiscvAbiAttr("riscv-abi-attributes", cl::desc("Enable emitting RISC-V ELF attributes for ABI features"), cl::Hidden)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
Streaming machine code generation interface.
Definition MCStreamer.h:222
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
MCTargetStreamer(MCStreamer &S)
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 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)
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
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(const MCSubtargetInfo &STI)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163