LLVM 24.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/ADT/Enum.h"
15#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCExpr.h"
17#include "llvm/MC/MCStreamer.h"
18#include "llvm/MC/MCValue.h"
21using namespace llvm;
22
28
30 "aarch64-neon-syntax", cl::init(Default),
31 cl::desc("Choose style of NEON code to emit from AArch64 backend:"),
32 cl::values(clEnumValN(Generic, "generic", "Emit generic NEON assembly"),
33 clEnumValN(Apple, "apple", "Emit Apple-style NEON assembly")));
34
40
45
47 {{"GOT"}, AArch64::S_MACHO_GOT},
48 {{"GOTPAGE"}, AArch64::S_MACHO_GOTPAGE},
49 {{"GOTPAGEOFF"}, AArch64::S_MACHO_GOTPAGEOFF},
50 {{"PAGE"}, AArch64::S_MACHO_PAGE},
51 {{"PAGEOFF"}, AArch64::S_MACHO_PAGEOFF},
52 {{"TLVP"}, AArch64::S_MACHO_TLVP},
53 {{"TLVPPAGE"}, AArch64::S_MACHO_TLVPPAGE},
54 {{"TLVPPAGEOFF"}, AArch64::S_MACHO_TLVPPAGEOFF},
55};
57
59 // clang-format off
60 switch (static_cast<uint32_t>(S)) {
61 case AArch64::S_CALL: return "";
62 case AArch64::S_LO12: return ":lo12:";
63 case AArch64::S_ABS_G3: return ":abs_g3:";
64 case AArch64::S_ABS_G2: return ":abs_g2:";
65 case AArch64::S_ABS_G2_S: return ":abs_g2_s:";
66 case AArch64::S_ABS_G2_NC: return ":abs_g2_nc:";
67 case AArch64::S_ABS_G1: return ":abs_g1:";
68 case AArch64::S_ABS_G1_S: return ":abs_g1_s:";
69 case AArch64::S_ABS_G1_NC: return ":abs_g1_nc:";
70 case AArch64::S_ABS_G0: return ":abs_g0:";
71 case AArch64::S_ABS_G0_S: return ":abs_g0_s:";
72 case AArch64::S_ABS_G0_NC: return ":abs_g0_nc:";
73 case AArch64::S_PREL_G3: return ":prel_g3:";
74 case AArch64::S_PREL_G2: return ":prel_g2:";
75 case AArch64::S_PREL_G2_NC: return ":prel_g2_nc:";
76 case AArch64::S_PREL_G1: return ":prel_g1:";
77 case AArch64::S_PREL_G1_NC: return ":prel_g1_nc:";
78 case AArch64::S_PREL_G0: return ":prel_g0:";
79 case AArch64::S_PREL_G0_NC: return ":prel_g0_nc:";
80 case AArch64::S_DTPREL_G2: return ":dtprel_g2:";
81 case AArch64::S_DTPREL_G1: return ":dtprel_g1:";
82 case AArch64::S_DTPREL_G1_NC: return ":dtprel_g1_nc:";
83 case AArch64::S_DTPREL_G0: return ":dtprel_g0:";
84 case AArch64::S_DTPREL_G0_NC: return ":dtprel_g0_nc:";
85 case AArch64::S_DTPREL_HI12: return ":dtprel_hi12:";
86 case AArch64::S_DTPREL_LO12: return ":dtprel_lo12:";
87 case AArch64::S_DTPREL_LO12_NC: return ":dtprel_lo12_nc:";
88 case AArch64::S_TPREL_G2: return ":tprel_g2:";
89 case AArch64::S_TPREL_G1: return ":tprel_g1:";
90 case AArch64::S_TPREL_G1_NC: return ":tprel_g1_nc:";
91 case AArch64::S_TPREL_G0: return ":tprel_g0:";
92 case AArch64::S_TPREL_G0_NC: return ":tprel_g0_nc:";
93 case AArch64::S_TPREL_HI12: return ":tprel_hi12:";
94 case AArch64::S_TPREL_LO12: return ":tprel_lo12:";
95 case AArch64::S_TPREL_LO12_NC: return ":tprel_lo12_nc:";
96 case AArch64::S_TLSDESC_LO12: return ":tlsdesc_lo12:";
97 case AArch64::S_TLSDESC_AUTH_LO12: return ":tlsdesc_auth_lo12:";
98 case AArch64::S_ABS_PAGE: return "";
99 case AArch64::S_ABS_PAGE_NC: return ":pg_hi21_nc:";
100 case AArch64::S_GOT: return ":got:";
101 case AArch64::S_GOT_PAGE: return ":got:";
102 case AArch64::S_GOT_PAGE_LO15: return ":gotpage_lo15:";
103 case AArch64::S_GOT_LO12: return ":got_lo12:";
104 case AArch64::S_GOTTPREL: return ":gottprel:";
105 case AArch64::S_GOTTPREL_PAGE: return ":gottprel:";
106 case AArch64::S_GOTTPREL_LO12_NC: return ":gottprel_lo12:";
107 case AArch64::S_GOTTPREL_G1: return ":gottprel_g1:";
108 case AArch64::S_GOTTPREL_G0_NC: return ":gottprel_g0_nc:";
109 case AArch64::S_TLSDESC: return "";
110 case AArch64::S_TLSDESC_PAGE: return ":tlsdesc:";
111 case AArch64::S_TLSDESC_AUTH: return "";
112 case AArch64::S_TLSDESC_AUTH_PAGE: return ":tlsdesc_auth:";
113 case AArch64::S_SECREL_LO12: return ":secrel_lo12:";
114 case AArch64::S_SECREL_HI12: return ":secrel_hi12:";
115 case AArch64::S_GOT_AUTH: return ":got_auth:";
116 case AArch64::S_GOT_AUTH_PAGE: return ":got_auth:";
117 case AArch64::S_GOT_AUTH_LO12: return ":got_auth_lo12:";
118
119 case AArch64::S_GOTPCREL: return "%gotpcrel";
120 case AArch64::S_PLT: return "%pltpcrel";
121 case AArch64::S_DTPREL: return "%dtprel";
122 case AArch64::S_FUNCINIT: return "%funcinit";
123 default:
124 llvm_unreachable("Invalid relocation specifier");
125 }
126 // clang-format on
127}
128
137
138static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
139 const MCAssembler *Asm) {
140 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
141 return false;
142 Res.setSpecifier(Expr.getSpecifier());
143 return !Res.getSubSym();
144}
145
149 // We prefer NEON instructions to be printed in the short, Apple-specific
150 // form when targeting Darwin.
152
154 SeparatorString = "%%";
155 CommentString = ";";
157 CodePointerSize = IsILP32 ? 4 : 8;
158
159 AlignmentIsInBytes = false;
164
166 UseAtForSpecifier = false;
167}
168
170 const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
171 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
172 // is an indirect pc-relative reference. The default implementation
173 // won't reference using the GOT, so we need this target-specific
174 // version.
175 MCContext &Context = Streamer.getContext();
176 const MCExpr *Res =
178 MCSymbol *PCSym = Context.createTempSymbol();
179 Streamer.emitLabel(PCSym);
180 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
181 return MCBinaryExpr::createSub(Res, PC, Context);
182}
183
184void AArch64AuthMCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
185 bool WrapSubExprInParens = !isa<MCSymbolRefExpr>(getSubExpr());
186 if (WrapSubExprInParens)
187 OS << '(';
188 MAI->printExpr(OS, *getSubExpr());
189 if (WrapSubExprInParens)
190 OS << ')';
191
192 OS << "@AUTH(" << AArch64PACKeyIDToString(Key) << ',' << Discriminator;
194 OS << ",addr";
195 OS << ')';
196}
197
199 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
200 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
201 return AE->print(OS, this);
203 printExpr(OS, *Expr.getSubExpr());
204}
205
207 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
208 return evaluate(Expr, Res, Asm);
209}
210
214 if (T.getArch() == Triple::aarch64_be)
215 IsLittleEndian = false;
216
217 // We prefer NEON instructions to be printed in the generic form when
218 // targeting ELF.
220
221 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
222
223 // ".comm align is in bytes but .align is pow-2."
224 AlignmentIsInBytes = false;
225
226 CommentString = "//";
228
229 Data16bitsDirective = "\t.hword\t";
230 Data32bitsDirective = "\t.word\t";
231 Data64bitsDirective = "\t.xword\t";
232
234
235 WeakRefDirective = "\t.weak\t";
236
238
239 // Exceptions handling
241
242 HasIdentDirective = true;
243
245 UseAtForSpecifier = false;
246}
247
249 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
250 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
251 return AE->print(OS, this);
252 auto Str = AArch64::getSpecifierName(Expr.getSpecifier());
253 OS << Str;
254 if (!Str.empty() && Str[0] == '%')
255 OS << '(';
256 printExpr(OS, *Expr.getSubExpr());
257 if (!Str.empty() && Str[0] == '%')
258 OS << ')';
259}
260
262 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
263 return evaluate(Expr, Res, Asm);
264}
265
285
291
293 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
294 return evaluate(Expr, Res, Asm);
295}
296
315
321
323 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
324 return evaluate(Expr, Res, Asm);
325}
constexpr auto COFFAtSpecifiers
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > COFFAtSpecifierDefs[]
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > ELFAtSpecifierDefs[]
constexpr auto ELFAtSpecifiers
static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm)
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")))
constexpr auto MachOAtSpecifiers
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > MachOAtSpecifierDefs[]
AsmWriterVariantTy
@ Generic
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
@ Default
#define BUILD_ENUM_STRINGS(Tab)
Definition Enum.h:120
static LVOptions Options
Definition LVOptions.cpp:25
#define T
static const char * name
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
MCAsmInfoDarwin(const MCTargetOptions &Options)
MCAsmInfoELF(const MCTargetOptions &Options)
MCAsmInfoGNUCOFF(const MCTargetOptions &Options)
MCAsmInfoMicrosoft(const MCTargetOptions &Options)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:159
const char * Data16bitsDirective
Definition MCAsmInfo.h:243
bool UseAtForSpecifier
True if target uses @ (expr@specifier) for relocation specifiers.
Definition MCAsmInfo.h:386
const char * Data64bitsDirective
Definition MCAsmInfo.h:245
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:357
const char * Data32bitsDirective
Definition MCAsmInfo.h:244
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:364
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:323
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:258
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:354
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition MCAsmInfo.h:173
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition MCAsmInfo.h:130
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition MCAsmInfo.h:312
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:268
void initializeAtSpecifiers(EnumStrings< AtSpecifierKind, 1 >)
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives.
Definition MCAsmInfo.h:207
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:93
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:86
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:90
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:134
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
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:494
const MCExpr * getSubExpr() const
Definition MCExpr.h:508
Spec getSpecifier() const
Definition MCExpr.h:507
Streaming machine code generation interface.
Definition MCStreamer.h:222
MCContext & getContext() const
Definition MCStreamer.h:326
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:213
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:48
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:52
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.
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
static StringRef AArch64PACKeyIDToString(AArch64PACKey::ID KeyID)
Return 2-letter identifier string for numeric key ID.
@ Default
The result value is uniform if and only if all operands are uniform.
Definition Uniformity.h:20
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const override
AArch64MCAsmInfoDarwin(bool IsILP32, const MCTargetOptions &Options)
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, const MCTargetOptions &Options)
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
AArch64MCAsmInfoGNUCOFF(const MCTargetOptions &Options)
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
AArch64MCAsmInfoMicrosoftCOFF(const MCTargetOptions &Options)
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
void printSpecifierExpr(raw_ostream &OS, const MCSpecifierExpr &Expr) const override
Compile-time data representation of enum entries.
Definition Enum.h:47