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 AArch64MCOptions::Global.neon_syntax.value_or(AArch64::Apple);
141
143 SeparatorString = "%%";
144 CommentString = ";";
146 CodePointerSize = IsILP32 ? 4 : 8;
147
148 AlignmentIsInBytes = false;
153
155 UseAtForSpecifier = false;
156}
157
159 const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
160 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
161 // is an indirect pc-relative reference. The default implementation
162 // won't reference using the GOT, so we need this target-specific
163 // version.
164 MCContext &Context = Streamer.getContext();
165 const MCExpr *Res =
167 MCSymbol *PCSym = Context.createTempSymbol();
168 Streamer.emitLabel(PCSym);
169 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
170 return MCBinaryExpr::createSub(Res, PC, Context);
171}
172
173void AArch64AuthMCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
174 bool WrapSubExprInParens = !isa<MCSymbolRefExpr>(getSubExpr());
175 if (WrapSubExprInParens)
176 OS << '(';
177 MAI->printExpr(OS, *getSubExpr());
178 if (WrapSubExprInParens)
179 OS << ')';
180
181 OS << "@AUTH(" << AArch64PACKeyIDToString(Key) << ',' << Discriminator;
183 OS << ",addr";
184 OS << ')';
185}
186
188 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
189 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
190 return AE->print(OS, this);
192 printExpr(OS, *Expr.getSubExpr());
193}
194
196 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
197 return evaluate(Expr, Res, Asm);
198}
199
203 if (T.getArch() == Triple::aarch64_be)
204 IsLittleEndian = false;
205
206 // We prefer NEON instructions to be printed in the generic form when
207 // targeting ELF.
209 AArch64MCOptions::Global.neon_syntax.value_or(AArch64::Generic);
210
211 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
212
213 // ".comm align is in bytes but .align is pow-2."
214 AlignmentIsInBytes = false;
215
216 CommentString = "//";
218
219 Data16bitsDirective = "\t.hword\t";
220 Data32bitsDirective = "\t.word\t";
221 Data64bitsDirective = "\t.xword\t";
222
224
225 WeakRefDirective = "\t.weak\t";
226
228
229 // Exceptions handling
231
232 HasIdentDirective = true;
233
235 UseAtForSpecifier = false;
236}
237
239 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
240 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
241 return AE->print(OS, this);
242 auto Str = AArch64::getSpecifierName(Expr.getSpecifier());
243 OS << Str;
244 if (!Str.empty() && Str[0] == '%')
245 OS << '(';
246 printExpr(OS, *Expr.getSubExpr());
247 if (!Str.empty() && Str[0] == '%')
248 OS << ')';
249}
250
252 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
253 return evaluate(Expr, Res, Asm);
254}
255
275
281
283 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
284 return evaluate(Expr, Res, Asm);
285}
286
305
311
313 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
314 return evaluate(Expr, Res, Asm);
315}
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
std::unique_ptr< MCStreamer > && Streamer
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
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
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
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:57
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:60
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
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