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 && TargetABI != RISCVABI::ABI::Unknown)
69 RISCVABI::getStackAlignment(TargetABI).value());
70
72 if (!ParseResult) {
74 } else {
75 auto &ISAInfo = *ParseResult;
76 std::string Arch = ISAInfo->toString();
78 setArchString(Arch);
79 }
80
81 if (CLOpts.abi_attributes && STI.hasFeature(RISCV::FeatureStdExtA)) {
82 unsigned AtomicABITag;
83 if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
84 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
85 else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
86 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
87 else
88 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
90 }
91}
92
93// This part is for ascii assembly output
97
99 OS << "\t.option\tpush\n";
100}
101
103 OS << "\t.option\tpop\n";
104}
105
107 OS << "\t.option\tpic\n";
108}
109
111 OS << "\t.option\tnopic\n";
112}
113
115 OS << "\t.option\trvc\n";
116}
117
119 OS << "\t.option\tnorvc\n";
120}
121
123 OS << "\t.option\texact\n";
124}
125
127 OS << "\t.option\tnoexact\n";
128}
129
131 OS << "\t.option\trelax\n";
132}
133
135 OS << "\t.option\tnorelax\n";
136}
137
140 OS << "\t.option\tarch";
141 for (const auto &Arg : Args) {
142 OS << ", ";
143 switch (Arg.Type) {
145 break;
147 OS << "+";
148 break;
150 OS << "-";
151 break;
152 }
153 OS << Arg.Value;
154 }
155 OS << "\n";
156}
157
159 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
160}
161
162void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
163 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
164}
165
166void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
168 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
169}
170
171void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
172 unsigned IntValue,
173 StringRef StringValue) {}
174
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...
Align getStackAlignment(ABI TargetABI)
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