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 "AArch64MCOptions.h"
15#include "llvm/ADT/Enum.h"
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCExpr.h"
18#include "llvm/MC/MCStreamer.h"
19#include "llvm/MC/MCValue.h"
21using namespace llvm;
22
28
33
35 {{"GOT"}, AArch64::S_MACHO_GOT},
36 {{"GOTPAGE"}, AArch64::S_MACHO_GOTPAGE},
37 {{"GOTPAGEOFF"}, AArch64::S_MACHO_GOTPAGEOFF},
38 {{"PAGE"}, AArch64::S_MACHO_PAGE},
39 {{"PAGEOFF"}, AArch64::S_MACHO_PAGEOFF},
40 {{"TLVP"}, AArch64::S_MACHO_TLVP},
41 {{"TLVPPAGE"}, AArch64::S_MACHO_TLVPPAGE},
42 {{"TLVPPAGEOFF"}, AArch64::S_MACHO_TLVPPAGEOFF},
43};
45
47 // clang-format off
48 switch (static_cast<uint32_t>(S)) {
49 case AArch64::S_CALL: return "";
50 case AArch64::S_LO12: return ":lo12:";
51 case AArch64::S_ABS_G3: return ":abs_g3:";
52 case AArch64::S_ABS_G2: return ":abs_g2:";
53 case AArch64::S_ABS_G2_S: return ":abs_g2_s:";
54 case AArch64::S_ABS_G2_NC: return ":abs_g2_nc:";
55 case AArch64::S_ABS_G1: return ":abs_g1:";
56 case AArch64::S_ABS_G1_S: return ":abs_g1_s:";
57 case AArch64::S_ABS_G1_NC: return ":abs_g1_nc:";
58 case AArch64::S_ABS_G0: return ":abs_g0:";
59 case AArch64::S_ABS_G0_S: return ":abs_g0_s:";
60 case AArch64::S_ABS_G0_NC: return ":abs_g0_nc:";
61 case AArch64::S_PREL_G3: return ":prel_g3:";
62 case AArch64::S_PREL_G2: return ":prel_g2:";
63 case AArch64::S_PREL_G2_NC: return ":prel_g2_nc:";
64 case AArch64::S_PREL_G1: return ":prel_g1:";
65 case AArch64::S_PREL_G1_NC: return ":prel_g1_nc:";
66 case AArch64::S_PREL_G0: return ":prel_g0:";
67 case AArch64::S_PREL_G0_NC: return ":prel_g0_nc:";
68 case AArch64::S_DTPREL_G2: return ":dtprel_g2:";
69 case AArch64::S_DTPREL_G1: return ":dtprel_g1:";
70 case AArch64::S_DTPREL_G1_NC: return ":dtprel_g1_nc:";
71 case AArch64::S_DTPREL_G0: return ":dtprel_g0:";
72 case AArch64::S_DTPREL_G0_NC: return ":dtprel_g0_nc:";
73 case AArch64::S_DTPREL_HI12: return ":dtprel_hi12:";
74 case AArch64::S_DTPREL_LO12: return ":dtprel_lo12:";
75 case AArch64::S_DTPREL_LO12_NC: return ":dtprel_lo12_nc:";
76 case AArch64::S_TPREL_G2: return ":tprel_g2:";
77 case AArch64::S_TPREL_G1: return ":tprel_g1:";
78 case AArch64::S_TPREL_G1_NC: return ":tprel_g1_nc:";
79 case AArch64::S_TPREL_G0: return ":tprel_g0:";
80 case AArch64::S_TPREL_G0_NC: return ":tprel_g0_nc:";
81 case AArch64::S_TPREL_HI12: return ":tprel_hi12:";
82 case AArch64::S_TPREL_LO12: return ":tprel_lo12:";
83 case AArch64::S_TPREL_LO12_NC: return ":tprel_lo12_nc:";
84 case AArch64::S_TLSDESC_LO12: return ":tlsdesc_lo12:";
85 case AArch64::S_TLSDESC_AUTH_LO12: return ":tlsdesc_auth_lo12:";
86 case AArch64::S_ABS_PAGE: return "";
87 case AArch64::S_ABS_PAGE_NC: return ":pg_hi21_nc:";
88 case AArch64::S_GOT: return ":got:";
89 case AArch64::S_GOT_PAGE: return ":got:";
90 case AArch64::S_GOT_PAGE_LO15: return ":gotpage_lo15:";
91 case AArch64::S_GOT_LO12: return ":got_lo12:";
92 case AArch64::S_GOTTPREL: return ":gottprel:";
93 case AArch64::S_GOTTPREL_PAGE: return ":gottprel:";
94 case AArch64::S_GOTTPREL_LO12_NC: return ":gottprel_lo12:";
95 case AArch64::S_GOTTPREL_G1: return ":gottprel_g1:";
96 case AArch64::S_GOTTPREL_G0_NC: return ":gottprel_g0_nc:";
97 case AArch64::S_TLSDESC: return "";
98 case AArch64::S_TLSDESC_PAGE: return ":tlsdesc:";
99 case AArch64::S_TLSDESC_AUTH: return "";
100 case AArch64::S_TLSDESC_AUTH_PAGE: return ":tlsdesc_auth:";
101 case AArch64::S_SECREL_LO12: return ":secrel_lo12:";
102 case AArch64::S_SECREL_HI12: return ":secrel_hi12:";
103 case AArch64::S_GOT_AUTH: return ":got_auth:";
104 case AArch64::S_GOT_AUTH_PAGE: return ":got_auth:";
105 case AArch64::S_GOT_AUTH_LO12: return ":got_auth_lo12:";
106
107 case AArch64::S_GOTPCREL: return "%gotpcrel";
108 case AArch64::S_PLT: return "%pltpcrel";
109 case AArch64::S_DTPREL: return "%dtprel";
110 case AArch64::S_FUNCINIT: return "%funcinit";
111 default:
112 llvm_unreachable("Invalid relocation specifier");
113 }
114 // clang-format on
115}
116
125
126static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
127 const MCAssembler *Asm) {
128 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
129 return false;
130 Res.setSpecifier(Expr.getSpecifier());
131 return !Res.getSubSym();
132}
133
137 // We prefer NEON instructions to be printed in the short, Apple-specific
138 // form when targeting Darwin.
140 AArch64_MC::getCLOpts(Options).neon_syntax.value_or(AArch64::Apple);
141
143 SeparatorString = "%%";
144 CommentString = ";";
146 CodePointerSize = IsILP32 ? 4 : 8;
147
148 AlignmentIsInBytes = false;
151
152 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
153 // is an indirect pc-relative reference. The default implementation
154 // won't reference using the GOT, so we need this target-specific
155 // version.
157
159 UseAtForSpecifier = false;
160
161 SpecifierExprPrintFn = [](const MCAsmInfo &MAI, raw_ostream &OS,
162 const MCSpecifierExpr &Expr) {
163 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
164 return AE->print(OS, &MAI);
165 OS << AArch64::getSpecifierName(Expr.getSpecifier());
166 MAI.printExpr(OS, *Expr.getSubExpr());
167 };
169}
170
171void AArch64AuthMCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
172 bool WrapSubExprInParens = !isa<MCSymbolRefExpr>(getSubExpr());
173 if (WrapSubExprInParens)
174 OS << '(';
175 MAI->printExpr(OS, *getSubExpr());
176 if (WrapSubExprInParens)
177 OS << ')';
178
179 OS << "@AUTH(" << AArch64PACKeyIDToString(Key) << ',' << Discriminator;
181 OS << ",addr";
182 OS << ')';
183}
184
188 if (T.getArch() == Triple::aarch64_be)
189 IsLittleEndian = false;
190
191 // We prefer NEON instructions to be printed in the generic form when
192 // targeting ELF.
194 AArch64_MC::getCLOpts(Options).neon_syntax.value_or(AArch64::Generic);
195
196 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
197
198 // ".comm align is in bytes but .align is pow-2."
199 AlignmentIsInBytes = false;
200
201 CommentString = "//";
203
204 Data16bitsDirective = "\t.hword\t";
205 Data32bitsDirective = "\t.word\t";
206 Data64bitsDirective = "\t.xword\t";
207
209
210 WeakRefDirective = "\t.weak\t";
211
213
214 HasIdentDirective = true;
215
217 UseAtForSpecifier = false;
218
219 // .bss is supported without .section.
220 SectionDirectives.insert(".bss");
221
222 SpecifierExprPrintFn = [](const MCAsmInfo &MAI, raw_ostream &OS,
223 const MCSpecifierExpr &Expr) {
224 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
225 return AE->print(OS, &MAI);
226 auto Str = AArch64::getSpecifierName(Expr.getSpecifier());
227 OS << Str;
228 if (!Str.empty() && Str[0] == '%')
229 OS << '(';
230 MAI.printExpr(OS, *Expr.getSubExpr());
231 if (!Str.empty() && Str[0] == '%')
232 OS << ')';
233 };
235}
236
241
242 Data16bitsDirective = "\t.hword\t";
243 Data32bitsDirective = "\t.word\t";
244 Data64bitsDirective = "\t.xword\t";
245
246 AlignmentIsInBytes = false;
248 CodePointerSize = 8;
249
250 CommentString = "//";
252
254
255 SpecifierExprPrintFn = [](const MCAsmInfo &MAI, raw_ostream &OS,
256 const MCSpecifierExpr &Expr) {
257 OS << AArch64::getSpecifierName(Expr.getSpecifier());
258 MAI.printExpr(OS, *Expr.getSubExpr());
259 };
261}
262
266
267 Data16bitsDirective = "\t.hword\t";
268 Data32bitsDirective = "\t.word\t";
269 Data64bitsDirective = "\t.xword\t";
270
271 AlignmentIsInBytes = false;
273 CodePointerSize = 8;
274
275 CommentString = "//";
277
279
280 SpecifierExprPrintFn = [](const MCAsmInfo &MAI, raw_ostream &OS,
281 const MCSpecifierExpr &Expr) {
282 OS << AArch64::getSpecifierName(Expr.getSpecifier());
283 MAI.printExpr(OS, *Expr.getSubExpr());
284 };
286}
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)
constexpr auto MachOAtSpecifiers
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > MachOAtSpecifierDefs[]
#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 Triple &TT, 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:69
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:169
const char * Data16bitsDirective
Definition MCAsmInfo.h:262
bool(* SpecifierExprEvaluateFn)(const MCSpecifierExpr &E, MCValue &Res, const MCAssembler *Asm)
Definition MCAsmInfo.h:231
bool UseAtForSpecifier
True if target uses @ (expr@specifier) for relocation specifiers.
Definition MCAsmInfo.h:411
const char * Data64bitsDirective
Definition MCAsmInfo.h:264
const char * Data32bitsDirective
Definition MCAsmInfo.h:263
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:380
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:341
void printExpr(raw_ostream &, const MCExpr &) const
SmallDenseSet< StringRef, 8 > SectionDirectives
Sections whose name also is supported as a directive without an explicit ".section" directive.
Definition MCAsmInfo.h:475
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:372
void(* SpecifierExprPrintFn)(const MCAsmInfo &, raw_ostream &, const MCSpecifierExpr &)
Definition MCAsmInfo.h:228
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition MCAsmInfo.h:183
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition MCAsmInfo.h:140
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition MCAsmInfo.h:330
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:286
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:217
uint16_t DwarfPersonalitySymbolSpec
The optional specifier to use for the personality symbol references.
Definition MCAsmInfo.h:388
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:95
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:88
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:92
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:144
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:491
const MCExpr * getSubExpr() const
Definition MCExpr.h:505
Spec getSpecifier() const
Definition MCExpr.h:504
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.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
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
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
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.
AArch64MCAsmInfoDarwin(bool IsILP32, const MCTargetOptions &Options)
AArch64MCAsmInfoELF(const Triple &T, const MCTargetOptions &Options)
AArch64MCAsmInfoGNUCOFF(const MCTargetOptions &Options)
AArch64MCAsmInfoMicrosoftCOFF(const MCTargetOptions &Options)
Compile-time data representation of enum entries.
Definition Enum.h:47