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
42
44 {AArch64::S_MACHO_GOT, "GOT"},
45 {AArch64::S_MACHO_GOTPAGE, "GOTPAGE"},
46 {AArch64::S_MACHO_GOTPAGEOFF, "GOTPAGEOFF"},
47 {AArch64::S_MACHO_PAGE, "PAGE"},
48 {AArch64::S_MACHO_PAGEOFF, "PAGEOFF"},
49 {AArch64::S_MACHO_TLVP, "TLVP"},
50 {AArch64::S_MACHO_TLVPPAGE, "TLVPPAGE"},
51 {AArch64::S_MACHO_TLVPPAGEOFF, "TLVPPAGEOFF"},
52};
53
55 // clang-format off
56 switch (static_cast<uint32_t>(S)) {
57 case AArch64::S_CALL: return "";
58 case AArch64::S_LO12: return ":lo12:";
59 case AArch64::S_ABS_G3: return ":abs_g3:";
60 case AArch64::S_ABS_G2: return ":abs_g2:";
61 case AArch64::S_ABS_G2_S: return ":abs_g2_s:";
62 case AArch64::S_ABS_G2_NC: return ":abs_g2_nc:";
63 case AArch64::S_ABS_G1: return ":abs_g1:";
64 case AArch64::S_ABS_G1_S: return ":abs_g1_s:";
65 case AArch64::S_ABS_G1_NC: return ":abs_g1_nc:";
66 case AArch64::S_ABS_G0: return ":abs_g0:";
67 case AArch64::S_ABS_G0_S: return ":abs_g0_s:";
68 case AArch64::S_ABS_G0_NC: return ":abs_g0_nc:";
69 case AArch64::S_PREL_G3: return ":prel_g3:";
70 case AArch64::S_PREL_G2: return ":prel_g2:";
71 case AArch64::S_PREL_G2_NC: return ":prel_g2_nc:";
72 case AArch64::S_PREL_G1: return ":prel_g1:";
73 case AArch64::S_PREL_G1_NC: return ":prel_g1_nc:";
74 case AArch64::S_PREL_G0: return ":prel_g0:";
75 case AArch64::S_PREL_G0_NC: return ":prel_g0_nc:";
76 case AArch64::S_DTPREL_G2: return ":dtprel_g2:";
77 case AArch64::S_DTPREL_G1: return ":dtprel_g1:";
78 case AArch64::S_DTPREL_G1_NC: return ":dtprel_g1_nc:";
79 case AArch64::S_DTPREL_G0: return ":dtprel_g0:";
80 case AArch64::S_DTPREL_G0_NC: return ":dtprel_g0_nc:";
81 case AArch64::S_DTPREL_HI12: return ":dtprel_hi12:";
82 case AArch64::S_DTPREL_LO12: return ":dtprel_lo12:";
83 case AArch64::S_DTPREL_LO12_NC: return ":dtprel_lo12_nc:";
84 case AArch64::S_TPREL_G2: return ":tprel_g2:";
85 case AArch64::S_TPREL_G1: return ":tprel_g1:";
86 case AArch64::S_TPREL_G1_NC: return ":tprel_g1_nc:";
87 case AArch64::S_TPREL_G0: return ":tprel_g0:";
88 case AArch64::S_TPREL_G0_NC: return ":tprel_g0_nc:";
89 case AArch64::S_TPREL_HI12: return ":tprel_hi12:";
90 case AArch64::S_TPREL_LO12: return ":tprel_lo12:";
91 case AArch64::S_TPREL_LO12_NC: return ":tprel_lo12_nc:";
92 case AArch64::S_TLSDESC_LO12: return ":tlsdesc_lo12:";
93 case AArch64::S_TLSDESC_AUTH_LO12: return ":tlsdesc_auth_lo12:";
94 case AArch64::S_ABS_PAGE: return "";
95 case AArch64::S_ABS_PAGE_NC: return ":pg_hi21_nc:";
96 case AArch64::S_GOT: return ":got:";
97 case AArch64::S_GOT_PAGE: return ":got:";
98 case AArch64::S_GOT_PAGE_LO15: return ":gotpage_lo15:";
99 case AArch64::S_GOT_LO12: return ":got_lo12:";
100 case AArch64::S_GOTTPREL: return ":gottprel:";
101 case AArch64::S_GOTTPREL_PAGE: return ":gottprel:";
102 case AArch64::S_GOTTPREL_LO12_NC: return ":gottprel_lo12:";
103 case AArch64::S_GOTTPREL_G1: return ":gottprel_g1:";
104 case AArch64::S_GOTTPREL_G0_NC: return ":gottprel_g0_nc:";
105 case AArch64::S_TLSDESC: return "";
106 case AArch64::S_TLSDESC_PAGE: return ":tlsdesc:";
107 case AArch64::S_TLSDESC_AUTH: return "";
108 case AArch64::S_TLSDESC_AUTH_PAGE: return ":tlsdesc_auth:";
109 case AArch64::S_SECREL_LO12: return ":secrel_lo12:";
110 case AArch64::S_SECREL_HI12: return ":secrel_hi12:";
111 case AArch64::S_GOT_AUTH: return ":got_auth:";
112 case AArch64::S_GOT_AUTH_PAGE: return ":got_auth:";
113 case AArch64::S_GOT_AUTH_LO12: return ":got_auth_lo12:";
114
115 case AArch64::S_GOTPCREL: return "%gotpcrel";
116 case AArch64::S_PLT: return "%pltpcrel";
117 case AArch64::S_FUNCINIT: return "%funcinit";
118 default:
119 llvm_unreachable("Invalid relocation specifier");
120 }
121 // clang-format on
122}
123
131
132static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
133 const MCAssembler *Asm) {
134 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
135 return false;
136 Res.setSpecifier(Expr.getSpecifier());
137 return !Res.getSubSym();
138}
139
141 // We prefer NEON instructions to be printed in the short, Apple-specific
142 // form when targeting Darwin.
144
146 PrivateLabelPrefix = "L";
147 SeparatorString = "%%";
148 CommentString = ";";
150 CodePointerSize = IsILP32 ? 4 : 8;
151
152 AlignmentIsInBytes = false;
157
159 UseAtForSpecifier = false;
160}
161
163 const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
164 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
165 // is an indirect pc-relative reference. The default implementation
166 // won't reference using the GOT, so we need this target-specific
167 // version.
168 MCContext &Context = Streamer.getContext();
169 const MCExpr *Res =
171 MCSymbol *PCSym = Context.createTempSymbol();
172 Streamer.emitLabel(PCSym);
173 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
174 return MCBinaryExpr::createSub(Res, PC, Context);
175}
176
177void AArch64AuthMCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
178 bool WrapSubExprInParens = !isa<MCSymbolRefExpr>(getSubExpr());
179 if (WrapSubExprInParens)
180 OS << '(';
181 MAI->printExpr(OS, *getSubExpr());
182 if (WrapSubExprInParens)
183 OS << ')';
184
185 OS << "@AUTH(" << AArch64PACKeyIDToString(Key) << ',' << Discriminator;
187 OS << ",addr";
188 OS << ')';
189}
190
192 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
193 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
194 return AE->print(OS, this);
196 printExpr(OS, *Expr.getSubExpr());
197}
198
200 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
201 return evaluate(Expr, Res, Asm);
202}
203
205 if (T.getArch() == Triple::aarch64_be)
206 IsLittleEndian = false;
207
208 // We prefer NEON instructions to be printed in the generic form when
209 // targeting ELF.
211
212 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
213
214 // ".comm align is in bytes but .align is pow-2."
215 AlignmentIsInBytes = false;
216
217 CommentString = "//";
219 PrivateLabelPrefix = ".L";
220
221 Data16bitsDirective = "\t.hword\t";
222 Data32bitsDirective = "\t.word\t";
223 Data64bitsDirective = "\t.xword\t";
224
226
227 WeakRefDirective = "\t.weak\t";
228
230
231 // Exceptions handling
233
234 HasIdentDirective = true;
235
237 UseAtForSpecifier = false;
238}
239
241 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
242 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
243 return AE->print(OS, this);
244 auto Str = AArch64::getSpecifierName(Expr.getSpecifier());
245 OS << Str;
246 if (!Str.empty() && Str[0] == '%')
247 OS << '(';
248 printExpr(OS, *Expr.getSubExpr());
249 if (!Str.empty() && Str[0] == '%')
250 OS << ')';
251}
252
254 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
255 return evaluate(Expr, Res, Asm);
256}
257
276
282
284 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
285 return evaluate(Expr, Res, Asm);
286}
287
306
312
314 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
315 return evaluate(Expr, Res, Asm);
316}
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
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:160
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
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:347
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