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 std::string Arch = ISAInfo->toString();
91 setArchString(Arch);
92 }
93
94 if (RiscvAbiAttr && STI.hasFeature(RISCV::FeatureStdExtA)) {
95 unsigned AtomicABITag;
96 if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
97 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
98 else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
99 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
100 else
101 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
103 }
104}
105
106// This part is for ascii assembly output
110
112 OS << "\t.option\tpush\n";
113}
114
116 OS << "\t.option\tpop\n";
117}
118
120 OS << "\t.option\tpic\n";
121}
122
124 OS << "\t.option\tnopic\n";
125}
126
128 OS << "\t.option\trvc\n";
129}
130
132 OS << "\t.option\tnorvc\n";
133}
134
136 OS << "\t.option\texact\n";
137}
138
140 OS << "\t.option\tnoexact\n";
141}
142
144 OS << "\t.option\trelax\n";
145}
146
148 OS << "\t.option\tnorelax\n";
149}
150
153 OS << "\t.option\tarch";
154 for (const auto &Arg : Args) {
155 OS << ", ";
156 switch (Arg.Type) {
158 break;
160 OS << "+";
161 break;
163 OS << "-";
164 break;
165 }
166 OS << Arg.Value;
167 }
168 OS << "\n";
169}
170
172 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
173}
174
175void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
176 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
177}
178
179void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
181 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
182}
183
184void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
185 unsigned IntValue,
186 StringRef StringValue) {}
187
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:106
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 setArchString(StringRef Arch)
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)
virtual 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