LLVM 19.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/MCSymbol.h"
20
21using namespace llvm;
22
24
27
44 unsigned IntValue,
45 StringRef StringValue) {}
47 assert(ABI != RISCVABI::ABI_Unknown && "Improperly initialized target ABI");
48 TargetABI = ABI;
49}
50
52 HasRVC = STI.hasFeature(RISCV::FeatureStdExtC) ||
53 STI.hasFeature(RISCV::FeatureStdExtZca);
54 HasTSO = STI.hasFeature(RISCV::FeatureStdExtZtso);
55}
56
58 bool EmitStackAlign) {
59 if (EmitStackAlign) {
60 unsigned StackAlign;
61 if (TargetABI == RISCVABI::ABI_ILP32E)
62 StackAlign = 4;
63 else if (TargetABI == RISCVABI::ABI_LP64E)
64 StackAlign = 8;
65 else
66 StackAlign = 16;
68 }
69
70 auto ParseResult = RISCVFeatures::parseFeatureBits(
71 STI.hasFeature(RISCV::Feature64Bit), STI.getFeatureBits());
72 if (!ParseResult) {
73 report_fatal_error(ParseResult.takeError());
74 } else {
75 auto &ISAInfo = *ParseResult;
76 emitTextAttribute(RISCVAttrs::ARCH, ISAInfo->toString());
77 }
78
79 if (STI.hasFeature(RISCV::FeatureStdExtA)) {
80 unsigned AtomicABITag = STI.hasFeature(RISCV::FeatureNoTrailingSeqCstFence)
84 }
85}
86
87// This part is for ascii assembly output
90 : RISCVTargetStreamer(S), OS(OS) {}
91
93 OS << "\t.option\tpush\n";
94}
95
97 OS << "\t.option\tpop\n";
98}
99
101 OS << "\t.option\tpic\n";
102}
103
105 OS << "\t.option\tnopic\n";
106}
107
109 OS << "\t.option\trvc\n";
110}
111
113 OS << "\t.option\tnorvc\n";
114}
115
117 OS << "\t.option\trelax\n";
118}
119
121 OS << "\t.option\tnorelax\n";
122}
123
126 OS << "\t.option\tarch";
127 for (const auto &Arg : Args) {
128 OS << ", ";
129 switch (Arg.Type) {
131 break;
133 OS << "+";
134 break;
136 OS << "-";
137 break;
138 }
139 OS << Arg.Value;
140 }
141 OS << "\n";
142}
143
145 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
146}
147
148void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
149 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
150}
151
152void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
154 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
155}
156
157void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
158 unsigned IntValue,
159 StringRef StringValue) {}
160
161void RISCVTargetAsmStreamer::finishAttributeSection() {}
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Streaming machine code generation interface.
Definition: MCStreamer.h:212
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:40
Target specific streamer interface.
Definition: MCStreamer.h:93
void emitDirectiveOptionArch(ArrayRef< RISCVOptionArchArg > Args) override
RISCVTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
void emitDirectiveVariantCC(MCSymbol &Symbol) override
virtual void emitDirectiveOptionNoRelax()
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:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
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: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156