LLVM 24.0.0git
SparcTargetStreamer.cpp
Go to the documentation of this file.
1//===-- SparcTargetStreamer.cpp - Sparc 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 Sparc specific target streamer methods.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SparcTargetStreamer.h"
14#include "SparcInstPrinter.h"
15#include "SparcMCTargetDesc.h"
17#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCRegister.h"
23#include "llvm/MC/MCSymbolELF.h"
25
26using namespace llvm;
27
28static unsigned getEFlagsForFeatureSet(const MCSubtargetInfo &STI) {
29 unsigned EFlags = 0;
30
31 if (STI.hasFeature(Sparc::FeatureV8Plus))
32 EFlags |= ELF::EF_SPARC_32PLUS;
33
34 if (STI.hasFeature(Sparc::FeatureVIS))
35 EFlags |= ELF::EF_SPARC_SUN_US1;
36
37 if (STI.hasFeature(Sparc::FeatureVIS2))
38 EFlags |= ELF::EF_SPARC_SUN_US3;
39
40 // VIS 3 and other ISA extensions doesn't set any flags.
41
42 return EFlags;
43}
44
45// pin vtable to this file
47
48void SparcTargetStreamer::anchor() {}
49
52 StringRef Name) const {
53 assert(RegNo < 8 && "not a global register");
54 const GlobalRegDecl &Decl = GlobalRegDecls[RegNo];
55 if (!Decl.Declared)
57 if (Decl.Ignore == Ignore && Decl.Name == Name)
60}
61
63 StringRef Name) {
64 assert(RegNo < 8 && "not a global register");
65 GlobalRegDecl &Decl = GlobalRegDecls[RegNo];
66 Decl.Declared = true;
67 Decl.Ignore = Ignore;
68 Decl.Name = Name.str();
69}
70
74
76 OS << "\t.register "
78 << ", #ignore\n";
79}
80
82 OS << "\t.register "
84 << ", #scratch\n";
85}
86
88 StringRef Name) {
89 OS << "\t.register %"
91 << Name << '\n';
92}
93
95 const MCSubtargetInfo &STI)
96 : SparcTargetStreamer(S), Is64Bit(STI.getTargetTriple().isArch64Bit()) {
98 unsigned EFlags = W.getELFHeaderEFlags();
99
100 EFlags |= getEFlagsForFeatureSet(STI);
101
102 W.setELFHeaderEFlags(EFlags);
103}
104
108
109// Like GNU as, record a 64-bit application register declared as scratch or
110// with a name in an STT_SPARC_REGISTER symbol, so that the linker can check
111// that its uses agree. The symbol is undefined and its value is the register
112// number. A scratch register's symbol has an empty name. 32-bit objects get no
113// such symbols, and neither does a register declared #ignore.
114void SparcTargetELFStreamer::emitRegisterSymbol(unsigned reg, StringRef Name) {
115 if (!Is64Bit)
116 return;
117
119 unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(reg);
120 assert(RegNo < 8 && "not a global register");
121 // A function using the register declares it again, so emit it once.
122 if (HasRegisterSymbol[RegNo])
123 return;
124 HasRegisterSymbol[RegNo] = true;
125
126 auto *Sym = static_cast<MCSymbolELF *>(
127 Name.empty() ? Ctx.createLocalSymbol(Name) : Ctx.getOrCreateSymbol(Name));
130 Sym->setType(ELF::STT_SPARC_REGISTER);
131}
132
134 emitRegisterSymbol(reg, "");
135}
136
138 StringRef Name) {
139 emitRegisterSymbol(reg, Name);
140}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:84
const MCRegisterInfo * getRegisterInfo() const
Definition MCContext.h:411
ELFObjectWriter & getWriter()
bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override
Add the given Attribute to Symbol.
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
Streaming machine code generation interface.
Definition MCStreamer.h:221
MCContext & getContext() const
Definition MCStreamer.h:329
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
MCStreamer & Streamer
Definition MCStreamer.h:96
MCTargetStreamer(MCStreamer &S)
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=SP::NoRegAltName)
void emitSparcRegisterIgnore(unsigned reg) override
Emit ".register <reg>, #ignore".
SparcTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
void emitSparcRegisterScratch(unsigned reg) override
Emit ".register <reg>, #scratch".
void emitSparcRegisterName(unsigned reg, StringRef Name) override
Emit ".register <reg>, <name>".
void emitSparcRegisterName(unsigned reg, StringRef Name) override
Emit ".register <reg>, <name>".
void emitSparcRegisterScratch(unsigned reg) override
Emit ".register <reg>, #scratch".
SparcTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
void declareRegister(unsigned RegNo, bool Ignore, StringRef Name)
Record the first .register declaration of global register number RegNo in 64-bit code.
RegisterDeclKind getRegisterDeclKind(unsigned RegNo, bool Ignore, StringRef Name) const
Compare a .register declaration of global register number RegNo in 64-bit code with an earlier one.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM_ABI std::string lower() const
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
@ STT_SPARC_REGISTER
Definition ELF.h:1289
@ EF_SPARC_32PLUS
Definition ELF.h:558
@ EF_SPARC_SUN_US1
Definition ELF.h:559
@ EF_SPARC_SUN_US3
Definition ELF.h:561
This is an optimization pass for GlobalISel generic memory operations.
static unsigned getEFlagsForFeatureSet(const FeatureBitset &Features)
@ MCSA_Global
.type _foo, @gnu_unique_object