LLVM 22.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"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCStreamer.h"
21#include "llvm/MC/MCSymbol.h"
28
29using namespace llvm;
30
31// This option controls whether or not we emit ELF attributes for ABI features,
32// like RISC-V atomics or X3 usage.
34 "riscv-abi-attributes",
35 cl::desc("Enable emitting RISC-V ELF attributes for ABI features"),
37
39
42
61 unsigned IntValue,
62 StringRef StringValue) {}
63
65 assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI");
66 TargetABI = ABI;
67}
68
70 HasRVC = STI.hasFeature(RISCV::FeatureStdExtZca);
71 HasTSO = STI.hasFeature(RISCV::FeatureStdExtZtso);
72}
73
75 bool EmitStackAlign) {
76 if (EmitStackAlign) {
77 unsigned StackAlign;
78 if (TargetABI == RISCVABI::ABI_ILP32E)
79 StackAlign = 4;
80 else if (TargetABI == RISCVABI::ABI_LP64E)
81 StackAlign = 8;
82 else
83 StackAlign = 16;
85 }
86
88 STI.hasFeature(RISCV::Feature64Bit), STI.getFeatureBits());
89 if (!ParseResult) {
91 } else {
92 auto &ISAInfo = *ParseResult;
93 emitTextAttribute(RISCVAttrs::ARCH, ISAInfo->toString());
94 }
95
96 if (RiscvAbiAttr && STI.hasFeature(RISCV::FeatureStdExtA)) {
97 unsigned AtomicABITag;
98 if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
99 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
100 else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
101 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
102 else
103 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
105 }
106}
107
108// This part is for ascii assembly output
112
114 OS << "\t.option\tpush\n";
115}
116
118 OS << "\t.option\tpop\n";
119}
120
122 OS << "\t.option\tpic\n";
123}
124
126 OS << "\t.option\tnopic\n";
127}
128
130 OS << "\t.option\trvc\n";
131}
132
134 OS << "\t.option\tnorvc\n";
135}
136
138 OS << "\t.option\texact\n";
139}
140
142 OS << "\t.option\tnoexact\n";
143}
144
146 OS << "\t.option\trelax\n";
147}
148
150 OS << "\t.option\tnorelax\n";
151}
152
155 OS << "\t.option\tarch";
156 for (const auto &Arg : Args) {
157 OS << ", ";
158 switch (Arg.Type) {
160 break;
162 OS << "+";
163 break;
165 OS << "-";
166 break;
167 }
168 OS << Arg.Value;
169 }
170 OS << "\n";
171}
172
174 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
175}
176
177void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
178 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
179}
180
181void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
183 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
184}
185
186void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
187 unsigned IntValue,
188 StringRef StringValue) {}
189
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)
ArrayRef - 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:69
Streaming machine code generation interface.
Definition MCStreamer.h:220
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: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)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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(bool IsRV64, const FeatureBitset &FeatureBits)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167