LLVM 22.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};
44
46 {AArch64::S_MACHO_GOT, "GOT"},
47 {AArch64::S_MACHO_GOTPAGE, "GOTPAGE"},
48 {AArch64::S_MACHO_GOTPAGEOFF, "GOTPAGEOFF"},
49 {AArch64::S_MACHO_PAGE, "PAGE"},
50 {AArch64::S_MACHO_PAGEOFF, "PAGEOFF"},
51 {AArch64::S_MACHO_TLVP, "TLVP"},
52 {AArch64::S_MACHO_TLVPPAGE, "TLVPPAGE"},
53 {AArch64::S_MACHO_TLVPPAGEOFF, "TLVPPAGEOFF"},
54};
55
57 // clang-format off
58 switch (static_cast<uint32_t>(S)) {
59 case AArch64::S_CALL: return "";
60 case AArch64::S_LO12: return ":lo12:";
61 case AArch64::S_ABS_G3: return ":abs_g3:";
62 case AArch64::S_ABS_G2: return ":abs_g2:";
63 case AArch64::S_ABS_G2_S: return ":abs_g2_s:";
64 case AArch64::S_ABS_G2_NC: return ":abs_g2_nc:";
65 case AArch64::S_ABS_G1: return ":abs_g1:";
66 case AArch64::S_ABS_G1_S: return ":abs_g1_s:";
67 case AArch64::S_ABS_G1_NC: return ":abs_g1_nc:";
68 case AArch64::S_ABS_G0: return ":abs_g0:";
69 case AArch64::S_ABS_G0_S: return ":abs_g0_s:";
70 case AArch64::S_ABS_G0_NC: return ":abs_g0_nc:";
71 case AArch64::S_PREL_G3: return ":prel_g3:";
72 case AArch64::S_PREL_G2: return ":prel_g2:";
73 case AArch64::S_PREL_G2_NC: return ":prel_g2_nc:";
74 case AArch64::S_PREL_G1: return ":prel_g1:";
75 case AArch64::S_PREL_G1_NC: return ":prel_g1_nc:";
76 case AArch64::S_PREL_G0: return ":prel_g0:";
77 case AArch64::S_PREL_G0_NC: return ":prel_g0_nc:";
78 case AArch64::S_DTPREL_G2: return ":dtprel_g2:";
79 case AArch64::S_DTPREL_G1: return ":dtprel_g1:";
80 case AArch64::S_DTPREL_G1_NC: return ":dtprel_g1_nc:";
81 case AArch64::S_DTPREL_G0: return ":dtprel_g0:";
82 case AArch64::S_DTPREL_G0_NC: return ":dtprel_g0_nc:";
83 case AArch64::S_DTPREL_HI12: return ":dtprel_hi12:";
84 case AArch64::S_DTPREL_LO12: return ":dtprel_lo12:";
85 case AArch64::S_DTPREL_LO12_NC: return ":dtprel_lo12_nc:";
86 case AArch64::S_TPREL_G2: return ":tprel_g2:";
87 case AArch64::S_TPREL_G1: return ":tprel_g1:";
88 case AArch64::S_TPREL_G1_NC: return ":tprel_g1_nc:";
89 case AArch64::S_TPREL_G0: return ":tprel_g0:";
90 case AArch64::S_TPREL_G0_NC: return ":tprel_g0_nc:";
91 case AArch64::S_TPREL_HI12: return ":tprel_hi12:";
92 case AArch64::S_TPREL_LO12: return ":tprel_lo12:";
93 case AArch64::S_TPREL_LO12_NC: return ":tprel_lo12_nc:";
94 case AArch64::S_TLSDESC_LO12: return ":tlsdesc_lo12:";
95 case AArch64::S_TLSDESC_AUTH_LO12: return ":tlsdesc_auth_lo12:";
96 case AArch64::S_ABS_PAGE: return "";
97 case AArch64::S_ABS_PAGE_NC: return ":pg_hi21_nc:";
98 case AArch64::S_GOT: return ":got:";
99 case AArch64::S_GOT_PAGE: return ":got:";
100 case AArch64::S_GOT_PAGE_LO15: return ":gotpage_lo15:";
101 case AArch64::S_GOT_LO12: return ":got_lo12:";
102 case AArch64::S_GOTTPREL: return ":gottprel:";
103 case AArch64::S_GOTTPREL_PAGE: return ":gottprel:";
104 case AArch64::S_GOTTPREL_LO12_NC: return ":gottprel_lo12:";
105 case AArch64::S_GOTTPREL_G1: return ":gottprel_g1:";
106 case AArch64::S_GOTTPREL_G0_NC: return ":gottprel_g0_nc:";
107 case AArch64::S_TLSDESC: return "";
108 case AArch64::S_TLSDESC_PAGE: return ":tlsdesc:";
109 case AArch64::S_TLSDESC_AUTH: return "";
110 case AArch64::S_TLSDESC_AUTH_PAGE: return ":tlsdesc_auth:";
111 case AArch64::S_SECREL_LO12: return ":secrel_lo12:";
112 case AArch64::S_SECREL_HI12: return ":secrel_hi12:";
113 case AArch64::S_GOT_AUTH: return ":got_auth:";
114 case AArch64::S_GOT_AUTH_PAGE: return ":got_auth:";
115 case AArch64::S_GOT_AUTH_LO12: return ":got_auth_lo12:";
116 default:
117 llvm_unreachable("Invalid relocation specifier");
118 }
119 // clang-format on
120}
121
122static bool evaluate(const MCSpecifierExpr &Expr, MCValue &Res,
123 const MCAssembler *Asm) {
124 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
125 return false;
126 Res.setSpecifier(Expr.getSpecifier());
127 return !Res.getSubSym();
128}
129
131 // We prefer NEON instructions to be printed in the short, Apple-specific
132 // form when targeting Darwin.
134
136 PrivateLabelPrefix = "L";
137 SeparatorString = "%%";
138 CommentString = ";";
140 CodePointerSize = IsILP32 ? 4 : 8;
141
142 AlignmentIsInBytes = false;
146 UseAtForSpecifier = false;
147
149
151}
152
154 const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const {
155 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
156 // is an indirect pc-relative reference. The default implementation
157 // won't reference using the GOT, so we need this target-specific
158 // version.
159 MCContext &Context = Streamer.getContext();
160 const MCExpr *Res =
162 MCSymbol *PCSym = Context.createTempSymbol();
163 Streamer.emitLabel(PCSym);
164 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
165 return MCBinaryExpr::createSub(Res, PC, Context);
166}
167
168void AArch64AuthMCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
169 bool WrapSubExprInParens = !isa<MCSymbolRefExpr>(getSubExpr());
170 if (WrapSubExprInParens)
171 OS << '(';
172 MAI->printExpr(OS, *getSubExpr());
173 if (WrapSubExprInParens)
174 OS << ')';
175
176 OS << "@AUTH(" << AArch64PACKeyIDToString(Key) << ',' << Discriminator;
178 OS << ",addr";
179 OS << ')';
180}
181
183 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
184 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
185 return AE->print(OS, this);
187 printExpr(OS, *Expr.getSubExpr());
188}
189
191 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
192 return evaluate(Expr, Res, Asm);
193}
194
196 if (T.getArch() == Triple::aarch64_be)
197 IsLittleEndian = false;
198
199 // We prefer NEON instructions to be printed in the generic form when
200 // targeting ELF.
202
203 CodePointerSize = T.getEnvironment() == Triple::GNUILP32 ? 4 : 8;
204
205 // ".comm align is in bytes but .align is pow-2."
206 AlignmentIsInBytes = false;
207
208 CommentString = "//";
209 PrivateGlobalPrefix = ".L";
210 PrivateLabelPrefix = ".L";
211
212 Data16bitsDirective = "\t.hword\t";
213 Data32bitsDirective = "\t.word\t";
214 Data64bitsDirective = "\t.xword\t";
215
217 UseAtForSpecifier = false;
218
219 WeakRefDirective = "\t.weak\t";
220
222
223 // Exceptions handling
225
226 HasIdentDirective = true;
227
229}
230
232 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
233 if (auto *AE = dyn_cast<AArch64AuthMCExpr>(&Expr))
234 return AE->print(OS, this);
236 printExpr(OS, *Expr.getSubExpr());
237}
238
240 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
241 return evaluate(Expr, Res, Asm);
242}
243
262
268
270 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
271 return evaluate(Expr, Res, Asm);
272}
273
292
298
300 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
301 return evaluate(Expr, Res, Asm);
302}
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
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:248
bool UseAtForSpecifier
True if target uses @ (expr@specifier) for relocation specifiers.
Definition MCAsmInfo.h:385
void initializeAtSpecifiers(ArrayRef< AtSpecifier >)
const char * Data64bitsDirective
Definition MCAsmInfo.h:250
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:359
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:249
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:366
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:325
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition MCAsmInfo.h:164
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:263
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:356
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition MCAsmInfo.h:178
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:314
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:273
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives.
Definition MCAsmInfo.h:212
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:220
MCContext & getContext() const
Definition MCStreamer.h:314
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
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.
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
@ 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:548
@ 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