LLVM 23.0.0git
AArch64MCAsmInfo.cpp
Go to the documentation of this file.
1//===-- AArch64MCAsmInfo.cpp - AArch64 asm properties ---------------------===//
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 contains the declarations of the AArch64MCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "AArch64MCAsmInfo.h"
14#include "llvm/MC/MCContext.h"
15#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCStreamer.h"
17#include "llvm/MC/MCValue.h"
20using namespace llvm;
21
27
29 "aarch64-neon-syntax", cl::init(Default),
30 cl::desc("Choose style of NEON code to emit from AArch64 backend:"),
31 cl::values(clEnumValN(Generic, "generic", "Emit generic NEON assembly"),
32 clEnumValN(Apple, "apple", "Emit Apple-style NEON assembly")));
33
38
40 {AArch64::S_GOT, "GOT"},
41 {AArch64::S_GOTPCREL, "GOTPCREL"},
42 {AArch64::S_PLT, "PLT"},
43 {AArch64::S_FUNCINIT, "FUNCINIT"},
44};
45
47 {AArch64::S_MACHO_GOT, "GOT"},
48 {AArch64::S_MACHO_GOTPAGE, "GOTPAGE"},
49 {AArch64::S_MACHO_GOTPAGEOFF, "GOTPAGEOFF"},
50 {AArch64::S_MACHO_PAGE, "PAGE"},
51 {AArch64::S_MACHO_PAGEOFF, "PAGEOFF"},
52 {AArch64::S_MACHO_TLVP, "TLVP"},
53 {AArch64::S_MACHO_TLVPPAGE, "TLVPPAGE"},
54 {AArch64::S_MACHO_TLVPPAGEOFF, "TLVPPAGEOFF"},
55};
56
58 // clang-format off
59 switch (static_cast<uint32_t>(S)) {
60 case AArch64::S_CALL: return "";
61 case AArch64::S_LO12: return ":lo12:";
62 case AArch64::S_ABS_G3: return ":abs_g3:";
63 case AArch64::S_ABS_G2: return ":abs_g2:";
64 case AArch64::S_ABS_G2_S: return ":abs_g2_s:";
65 case AArch64::S_ABS_G2_NC: return ":abs_g2_nc:";
66 case AArch64::S_ABS_G1: return ":abs_g1:";
67 case AArch64::S_ABS_G1_S: return ":abs_g1_s:";
68 case AArch64::S_ABS_G1_NC: return ":abs_g1_nc:";
69 case AArch64::S_ABS_G0: return ":abs_g0:";
70 case AArch64::S_ABS_G0_S: return ":abs_g0_s:";
71 case AArch64::S_ABS_G0_NC: return ":abs_g0_nc:";
72 case AArch64::S_PREL_G3: return ":prel_g3:";
73 case AArch64::S_PREL_G2: return ":prel_g2:";
74 case AArch64::S_PREL_G2_NC: return ":prel_g2_nc:";
75 case AArch64::S_PREL_G1: return ":prel_g1:";
76 case AArch64::S_PREL_G1_NC: return ":prel_g1_nc:";
77 case AArch64::S_PREL_G0: return ":prel_g0:";
78 case AArch64::S_PREL_G0_NC: return ":prel_g0_nc:";
79 case AArch64::S_DTPREL_G2: return ":dtprel_g2:";
80 case AArch64::S_DTPREL_G1: return ":dtprel_g1:";
81 case AArch64::S_DTPREL_G1_NC: return ":dtprel_g1_nc:";
82 case AArch64::S_DTPREL_G0: return ":dtprel_g0:";
83 case AArch64::S_DTPREL_G0_NC: return ":dtprel_g0_nc:";
84 case AArch64::S_DTPREL_HI12: return ":dtprel_hi12:";
85 case AArch64::S_DTPREL_LO12: return ":dtprel_lo12:";
86 case AArch64::S_DTPREL_LO12_NC: return ":dtprel_lo12_nc:";
87 case AArch64::S_TPREL_G2: return ":tprel_g2:";
88 case AArch64::S_TPREL_G1: return ":tprel_g1:";
89 case AArch64::S_TPREL_G1_NC: return ":tprel_g1_nc:";
90 case AArch64::S_TPREL_G0: return ":tprel_g0:";
91 case AArch64::S_TPREL_G0_NC: return ":tprel_g0_nc:";
92 case AArch64::S_TPREL_HI12: return ":tprel_hi12:";
93 case AArch64::S_TPREL_LO12: return ":tprel_lo12:";
94 case AArch64::S_TPREL_LO12_NC: return ":tprel_lo12_nc:";
95 case AArch64::S_TLSDESC_LO12: return ":tlsdesc_lo12:";
96 case AArch64::S_TLSDESC_AUTH_LO12: return ":tlsdesc_auth_lo12:";
97 case AArch64::S_ABS_PAGE: return "";
98 case AArch64::S_ABS_PAGE_NC: return ":pg_hi21_nc:";
99 case AArch64::S_GOT: return ":got:";
100 case AArch64::S_GOT_PAGE: return ":got:";
101 case AArch64::S_GOT_PAGE_LO15: return ":gotpage_lo15:";
102 case AArch64::S_GOT_LO12: return ":got_lo12:";
103 case AArch64::S_GOTTPREL: return ":gottprel:";
104 case AArch64::S_GOTTPREL_PAGE: return ":gottprel:";
105 case AArch64::S_GOTTPREL_LO12_NC: return ":gottprel_lo12:";
106 case AArch64::S_GOTTPREL_G1: return ":gottprel_g1:";
107 case AArch64::S_GOTTPREL_G0_NC: return ":gottprel_g0_nc:";
108 case AArch64::S_TLSDESC: return "";
109 case AArch64::S_TLSDESC_PAGE: return ":tlsdesc:";
110 case AArch64::S_TLSDESC_AUTH: return "";
111 case AArch64::S_TLSDESC_AUTH_PAGE: return ":tlsdesc_auth:";
112 case AArch64::S_SECREL_LO12: return ":secrel_lo12:";
113 case AArch64::S_SECREL_HI12: return ":secrel_hi12:";
114 case AArch64::S_GOT_AUTH: return ":got_auth:";
115 case AArch64::S_GOT_AUTH_PAGE: return ":got_auth:";
116 case AArch64::S_GOT_AUTH_LO12: return ":got_auth_lo12:";
117
118 case AArch64::S_GOTPCREL: return "%gotpcrel";
119 case AArch64::S_PLT: return "%pltpcrel";
120 case AArch64::S_FUNCINIT: return "%funcinit";
121 default:
122 llvm_unreachable("Invalid relocation specifier");
123 }
124 // clang-format on
125}
126
134
135static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
136 const MCAssembler *Asm) {
137 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
138 return false;
139 Res.setSpecifier(Expr.getSpecifier());
140 return !Res.getSubSym();
141}
142
144 // We prefer NEON instructions to be printed in the short, Apple-specific
145 // form when targeting Darwin.
147
149 PrivateLabelPrefix = "L";
150 SeparatorString = "%%";
151 CommentString = ";";
153 CodePointerSize = IsILP32 ? 4 : 8;
154
155 AlignmentIsInBytes = false;
160
162 UseAtForSpecifier = false;
163}
164
166 const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
167 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
168 // is an indirect pc-relative reference. The default implementation
169 // won't reference using the GOT, so we need this target-specific
170 // version.
171 MCContext &Context = Streamer.getContext();
172 const MCExpr *Res =
174 MCSymbol *PCSym = Context.createTempSymbol();
175 Streamer.emitLabel(PCSym);
176 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
177 return MCBinaryExpr::createSub(Res, PC, Context);
178}
179
180void AArch64AuthMCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
181 bool WrapSubExprInParens = !isa<MCSymbolRefExpr>(getSubExpr());
182 if (WrapSubExprInParens)
183 OS << '(';
184 MAI->printExpr(OS, *getSubExpr());
185 if (WrapSubExprInParens)
186 OS << ')';
187
188 OS << "@AUTH(" << AArch64PACKeyIDToString(Key) << ',' << Discriminator;
190 OS << ",addr";
191 OS << ')';
192}
193
195 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
196 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
197 return AE->print(OS, this);
199 printExpr(OS, *Expr.getSubExpr());
200}
201
203 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
204 return evaluate(Expr, Res, Asm);
205}
206
208 if (T.getArch() == Triple::aarch64_be)
209 IsLittleEndian = false;
210
211 // We prefer NEON instructions to be printed in the generic form when
212 // targeting ELF.
214
215 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
216
217 // ".comm align is in bytes but .align is pow-2."
218 AlignmentIsInBytes = false;
219
220 CommentString = "//";
221 PrivateGlobalPrefix = ".L";
222 PrivateLabelPrefix = ".L";
223
224 Data16bitsDirective = "\t.hword\t";
225 Data32bitsDirective = "\t.word\t";
226 Data64bitsDirective = "\t.xword\t";
227
229
230 WeakRefDirective = "\t.weak\t";
231
233
234 // Exceptions handling
236
237 HasIdentDirective = true;
238
240 UseAtForSpecifier = false;
241}
242
244 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
245 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
246 return AE->print(OS, this);
247 auto Str = AArch64::getSpecifierName(Expr.getSpecifier());
248 OS << Str;
249 if (!Str.empty() && Str[0] == '%')
250 OS << '(';
251 printExpr(OS, *Expr.getSubExpr());
252 if (!Str.empty() && Str[0] == '%')
253 OS << ')';
254}
255
257 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
258 return evaluate(Expr, Res, Asm);
259}
260
279
285
287 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
288 return evaluate(Expr, Res, Asm);
289}
290
309
315
317 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
318 return evaluate(Expr, Res, Asm);
319}
const MCAsmInfo::AtSpecifier ELFAtSpecifiers[]
const MCAsmInfo::AtSpecifier COFFAtSpecifiers[]
static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm)
const MCAsmInfo::AtSpecifier MachOAtSpecifiers[]
static cl::opt< AsmWriterVariantTy > AsmWriterVariant("aarch64-neon-syntax", cl::init(Default), cl::desc("Choose style of NEON code to emit from AArch64 backend:"), cl::values(clEnumValN(Generic, "generic", "Emit generic NEON assembly"), clEnumValN(Apple, "apple", "Emit Apple-style NEON assembly")))
AsmWriterVariantTy
@ Generic
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
@ Default
#define T
static const char * name
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
const char * Data16bitsDirective
Definition MCAsmInfo.h:247
bool UseAtForSpecifier
True if target uses @ (expr@specifier) for relocation specifiers.
Definition MCAsmInfo.h:387
void initializeAtSpecifiers(ArrayRef< AtSpecifier >)
const char * Data64bitsDirective
Definition MCAsmInfo.h:249
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:361
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition MCAsmInfo.h:160
const char * Data32bitsDirective
Definition MCAsmInfo.h:248
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:368
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:327
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks. Defaults to "L".
Definition MCAsmInfo.h:163
void printExpr(raw_ostream &, const MCExpr &) const
bool UsesELFSectionDirectiveForBSS
This is true if this target uses ELF '.section' directive before the '.bss' one.
Definition MCAsmInfo.h:262
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:358
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition MCAsmInfo.h:177
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition MCAsmInfo.h:131
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition MCAsmInfo.h:316
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:272
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives.
Definition MCAsmInfo.h:211
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:94
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:87
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:91
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:135
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition MCExpr.cpp:450
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:495
const MCExpr * getSubExpr() const
Definition MCExpr.h:509
Spec getSpecifier() const
Definition MCExpr.h:508
Streaming machine code generation interface.
Definition MCStreamer.h:221
MCContext & getContext() const
Definition MCStreamer.h:322
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
void setSpecifier(uint32_t S)
Definition MCValue.h:47
const MCSymbol * getSubSym() const
Definition MCValue.h:51
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Specifier parsePercentSpecifierName(StringRef)
StringRef getSpecifierName(Specifier S)
Return the string representation of the ELF relocation specifier (e.g.
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
Definition MCAsmInfo.h:49
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:58
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
Definition DwarfDebug.h:346
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
static StringRef AArch64PACKeyIDToString(AArch64PACKey::ID KeyID)
Return 2-letter identifier string for numeric key ID.
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
AArch64MCAsmInfoELF(const Triple &T)
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override