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
80// This part is for ascii assembly output
83 : RISCVTargetStreamer(S), OS(OS) {}
84
86 OS << "\t.option\tpush\n";
87}
88
90 OS << "\t.option\tpop\n";
91}
92
94 OS << "\t.option\tpic\n";
95}
96
98 OS << "\t.option\tnopic\n";
99}
100
102 OS << "\t.option\trvc\n";
103}
104
106 OS << "\t.option\tnorvc\n";
107}
108
110 OS << "\t.option\trelax\n";
111}
112
114 OS << "\t.option\tnorelax\n";
115}
116
119 OS << "\t.option\tarch";
120 for (const auto &Arg : Args) {
121 OS << ", ";
122 switch (Arg.Type) {
124 break;
126 OS << "+";
127 break;
129 OS << "-";
130 break;
131 }
132 OS << Arg.Value;
133 }
134 OS << "\n";
135}
136
138 OS << "\t.variant_cc\t" << Symbol.getName() << "\n";
139}
140
141void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
142 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n";
143}
144
145void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute,
147 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n";
148}
149
150void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute,
151 unsigned IntValue,
152 StringRef StringValue) {}
153
154void 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