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
32
51 unsigned IntValue,
52 StringRef StringValue) {}
53
55 assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI");
56 TargetABI = ABI;
57}
58
60 HasRVC = STI.hasFeature(RISCV::FeatureStdExtZca);
61 HasTSO = STI.hasFeature(RISCV::FeatureStdExtZtso);
62}
63
65 bool EmitStackAlign) {
66 if (EmitStackAlign) {
67 unsigned StackAlign;
68 if (TargetABI == RISCVABI::ABI_ILP32E)
69 StackAlign = 4;
70 else if (TargetABI == RISCVABI::ABI_LP64E)
71 StackAlign = 8;
72 else
73 StackAlign = 16;
75 }
76
78 if (!ParseResult) {
80 } else {
81 auto &ISAInfo = *ParseResult;
82 std::string Arch = ISAInfo->toString();
84 setArchString(Arch);
85 }
86
87 if (CLOpts.abi_attributes && STI.hasFeature(RISCV::FeatureStdExtA)) {
88 unsigned AtomicABITag;
89 if (STI.hasFeature(RISCV::FeatureStdExtZalasr))
90 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A7);
91 else if (STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence))
92 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6C);
93 else
94 AtomicABITag = static_cast<unsigned>(RISCVAttrs::RISCVAtomicAbiTag::A6S);
96 }
97}
98
99// This part is for ascii assembly output
103
105 OS << "\t.option\tpush\n";
106}
107
109 OS << "\t.option\tpop\n";
110}
111
113 OS << "\t.option\tpic\n";
114}
115
117 OS << "\t.option\tnopic\n";
118}
119
121 OS << "\t.option\trvc\n";
122}
123
125 OS << "\t.option\tnorvc\n";
126}
127
129 OS << "\t.option\texact\n";
130}
131
133 OS << "\t.option\tnoexact\n";
134}
135
137 OS << "\t.option\trelax\n";
138}
139
141 OS << "\t.option\tnorelax\n";
142}
143
146 OS << "\t.option\tarch";
147 for (const auto &Arg : Args) {
148 OS << ", ";
149 switch (Arg.Type) {
151 break;
153 OS << "+";
154 break;
156 OS << "-";
157 break;
158 }
159 OS << Arg.Value;
160 }
161 OS << "\n";
162}
163
165 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
166}
167
168void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
169 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
170}
171
172void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
174 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
175}
176
177void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
178 unsigned IntValue,
179 StringRef StringValue) {}
180
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
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
@ Global
Append to llvm.global_dtors.