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"
24
25using namespace llvm;
26
29 CLOpts(RISCV_MC::getCLOpts(S.getContext().getTargetOptions())) {}
30
33
52 unsigned IntValue,
53 StringRef StringValue) {}
54
56 assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI");
57 TargetABI = ABI;
58}
59
61 HasRVC = 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 if (!ParseResult) {
81 } else {
82 auto &ISAInfo = *ParseResult;
83 std::string Arch = ISAInfo->toString();
85 setArchString(Arch);
86 }
87
88 if (CLOpts.abi_attributes && STI.hasFeature(RISCV::FeatureStdExtA)) {
89 unsigned AtomicABITag;
90 if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
91 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
92 else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
93 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
94 else
95 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
97 }
98}
99
100// This part is for ascii assembly output
104
106 OS << "\t.option\tpush\n";
107}
108
110 OS << "\t.option\tpop\n";
111}
112
114 OS << "\t.option\tpic\n";
115}
116
118 OS << "\t.option\tnopic\n";
119}
120
122 OS << "\t.option\trvc\n";
123}
124
126 OS << "\t.option\tnorvc\n";
127}
128
130 OS << "\t.option\texact\n";
131}
132
134 OS << "\t.option\tnoexact\n";
135}
136
138 OS << "\t.option\trelax\n";
139}
140
142 OS << "\t.option\tnorelax\n";
143}
144
147 OS << "\t.option\tarch";
148 for (const auto &Arg : Args) {
149 OS << ", ";
150 switch (Arg.Type) {
152 break;
154 OS << "+";
155 break;
157 OS << "-";
158 break;
159 }
160 OS << Arg.Value;
161 }
162 OS << "\n";
163}
164
166 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
167}
168
169void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
170 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
171}
172
173void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
175 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
176}
177
178void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
179 unsigned IntValue,
180 StringRef StringValue) {}
181
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
MCContext & getContext()
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