LLVM 23.0.0git
X86MCAsmInfo.cpp
Go to the documentation of this file.
1//===-- X86MCAsmInfo.cpp - X86 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 X86MCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "X86MCAsmInfo.h"
14#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCStreamer.h"
18using namespace llvm;
19
21 // Note: This numbering has to match the GCC assembler dialects for inline
22 // asm alternatives to work right.
23 ATT = 0, Intel = 1
24};
25
27 "x86-asm-syntax", cl::init(ATT), cl::Hidden,
28 cl::desc("Select the assembly style for input"),
29 cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
30 clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
31
32static cl::opt<bool>
33MarkedJTDataRegions("mark-data-regions", cl::init(true),
34 cl::desc("Mark code section jump table data regions."),
36
38 {X86::S_ABS8, "ABS8"},
39 {X86::S_DTPOFF, "DTPOFF"},
40 {X86::S_DTPREL, "DTPREL"},
41 {X86::S_GOT, "GOT"},
42 {X86::S_GOTENT, "GOTENT"},
43 {X86::S_GOTNTPOFF, "GOTNTPOFF"},
44 {X86::S_GOTOFF, "GOTOFF"},
45 {X86::S_GOTPCREL, "GOTPCREL"},
46 {X86::S_GOTPCREL_NORELAX, "GOTPCREL_NORELAX"},
47 {X86::S_GOTREL, "GOTREL"},
48 {X86::S_GOTTPOFF, "GOTTPOFF"},
49 {X86::S_INDNTPOFF, "INDNTPOFF"},
51 {X86::S_NTPOFF, "NTPOFF"},
52 {X86::S_PCREL, "PCREL"},
53 {X86::S_PLT, "PLT"},
54 {X86::S_PLTOFF, "PLTOFF"},
55 {X86::S_COFF_SECREL, "SECREL32"},
56 {X86::S_SIZE, "SIZE"},
57 {X86::S_TLSCALL, "tlscall"},
58 {X86::S_TLSDESC, "tlsdesc"},
59 {X86::S_TLSGD, "TLSGD"},
60 {X86::S_TLSLD, "TLSLD"},
61 {X86::S_TLSLDM, "TLSLDM"},
62 {X86::S_TLVP, "TLVP"},
63 {X86::S_TLVPPAGE, "TLVPPAGE"},
64 {X86::S_TLVPPAGEOFF, "TLVPPAGEOFF"},
65 {X86::S_TPOFF, "TPOFF"},
66};
67
68void X86MCAsmInfoDarwin::anchor() { }
69
73 bool is64Bit = T.isX86_64();
74 if (is64Bit)
76
78
79 if (!is64Bit)
80 Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
81
82 // Use ## as a comment string so that .s files generated by llvm can go
83 // through the GCC preprocessor without causing an error. This is needed
84 // because "clang foo.s" runs the C preprocessor, which is usually reserved
85 // for .S files on other systems. Perhaps this is because the file system
86 // wasn't always case preserving or something.
87 CommentString = "##";
88
91
92 // Exceptions handling
94
95 // old assembler lacks some directives
96 // FIXME: this should really be a check on the assembler characteristics
97 // rather than OS version
98 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
100
101 // Assume ld64 is new enough that the abs-ified FDE relocs may be used
102 // (actually, must, since otherwise the non-extern relocations we produce
103 // overwhelm ld64's tiny little mind and it fails).
105
107}
108
112
113void X86ELFMCAsmInfo::anchor() { }
114
118 bool is64Bit = T.isX86_64();
119 bool isX32 = T.isX32();
120
121 // For ELF, x86-64 pointer size depends on the ABI.
122 // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
123 // with the x32 ABI, pointer size remains the default 4.
124 CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
125
126 // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
128
130
131 // Debug Information
133
134 // Exceptions handling
136
138}
139
140const MCExpr *
142 unsigned Encoding,
143 MCStreamer &Streamer) const {
144 MCContext &Context = Streamer.getContext();
145 const MCExpr *Res = MCSymbolRefExpr::create(Sym, X86::S_GOTPCREL, Context);
146 const MCExpr *Four = MCConstantExpr::create(4, Context);
147 return MCBinaryExpr::createAdd(Res, Four, Context);
148}
149
150void X86MCAsmInfoMicrosoft::anchor() { }
151
155 if (Triple.isX86_64()) {
156 InternalSymbolPrefix = ".L";
157 PrivateLabelPrefix = ".L";
158 CodePointerSize = 8;
159 WinEHEncodingType = WinEH::EncodingType::Itanium;
160 } else {
161 // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
162 // a place holder that the Windows EHStreamer looks for to suppress CFI
163 // output. In particular, usesWindowsCFI() returns false.
164 WinEHEncodingType = WinEH::EncodingType::X86;
165 }
166
168
170
171 AllowAtInName = true;
172
174}
175
176void X86MCAsmInfoMicrosoftMASM::anchor() { }
177
189
190static bool isValidX86UnquotedName(const MCAsmInfo &MAI,
191 const StringSet<> &ReservedIdentifiers,
192 StringRef Name) {
193 if (!MAI.MCAsmInfo::isValidUnquotedName(Name))
194 return false;
195 // Only Intel-syntax output needs to avoid register/keyword collisions; AT&T
196 // disambiguates registers with '%' and doesn't treat `byte`, `ptr`, etc. as
197 // keywords.
198 return MAI.getOutputAssemblerDialect() == 0 ||
199 !ReservedIdentifiers.contains(Name.lower());
200}
201
205
209
213
217
218void X86MCAsmInfoGNUCOFF::anchor() { }
219
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const MCAsmInfo::AtSpecifier atSpecifiers[]
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
static LVOptions Options
Definition LVOptions.cpp:25
#define T
static bool is64Bit(const char *name)
static cl::opt< bool > MarkedJTDataRegions("mark-data-regions", cl::init(true), cl::desc("Mark code section jump table data regions."), cl::Hidden)
AsmWriterFlavorTy
@ Intel
@ ATT
static bool isValidX86UnquotedName(const MCAsmInfo &MAI, const StringSet<> &ReservedIdentifiers, StringRef Name)
static cl::opt< AsmWriterFlavorTy > X86AsmSyntax("x86-asm-syntax", cl::init(ATT), cl::Hidden, cl::desc("Select the assembly style for input"), cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"), clEnumValN(Intel, "intel", "Emit Intel-style assembly")))
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:64
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:160
bool AllowAdditionalComments
This indicates whether to allow additional "comment strings" to be lexed as a comment.
Definition MCAsmInfo.h:143
bool AllowQuestionAtStartOfIdentifier
This is true if the assembler allows the "?" character at the start of of a string to be lexed as an ...
Definition MCAsmInfo.h:188
void initializeAtSpecifiers(ArrayRef< AtSpecifier >)
const char * Data64bitsDirective
Definition MCAsmInfo.h:249
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC.
Definition MCAsmInfo.h:127
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:361
bool AllowDollarAtStartOfIdentifier
This is true if the assembler allows the "$" character at the start of of a string to be lexed as an ...
Definition MCAsmInfo.h:195
bool DwarfFDESymbolsUseAbsDiff
True if DWARF FDE symbol reference relocations should be replaced by an absolute difference.
Definition MCAsmInfo.h:376
bool AllowAtAtStartOfIdentifier
This is true if the assembler allows the "@" character at the start of a string to be lexed as an Asm...
Definition MCAsmInfo.h:202
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition MCAsmInfo.h:368
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks. Defaults to "L".
Definition MCAsmInfo.h:163
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition MCAsmInfo.h:181
bool HasWeakDefCanBeHiddenDirective
True if we have a directive to declare a global as being a weak defined symbol that can be hidden (un...
Definition MCAsmInfo.h:331
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 UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives.
Definition MCAsmInfo.h:211
unsigned getOutputAssemblerDialect() const
Definition MCAsmInfo.h:569
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 * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:343
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
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
Streaming machine code generation interface.
Definition MCStreamer.h:222
MCContext & getContext() const
Definition MCStreamer.h:323
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
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition StringSet.h:25
bool contains(StringRef key) const
Check if the set contains the given key.
Definition StringSet.h:60
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
bool isX86_64() const
Tests whether the target is x86 (64-bit).
Definition Triple.h:1115
bool isUEFI() const
Tests whether the OS is UEFI.
Definition Triple.h:695
bool isOSWindows() const
Tests whether the OS is Windows.
Definition Triple.h:698
StringSet ReservedIdentifiers
bool isValidUnquotedName(StringRef Name) const override
Return true if the identifier Name does not need quotes to be syntactically correct.
X86ELFMCAsmInfo(const Triple &Triple, const MCTargetOptions &Options)
bool isValidUnquotedName(StringRef Name) const override
Return true if the identifier Name does not need quotes to be syntactically correct.
X86MCAsmInfoDarwin(const Triple &Triple, const MCTargetOptions &Options)
bool isValidUnquotedName(StringRef Name) const override
Return true if the identifier Name does not need quotes to be syntactically correct.
X86MCAsmInfoGNUCOFF(const Triple &Triple, const MCTargetOptions &Options)
X86MCAsmInfoMicrosoftMASM(const Triple &Triple, const MCTargetOptions &Options)
bool isValidUnquotedName(StringRef Name) const override
Return true if the identifier Name does not need quotes to be syntactically correct.
X86MCAsmInfoMicrosoft(const Triple &Triple, const MCTargetOptions &Options)
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
Definition MCAsmInfo.h:49
@ S_GOTPCREL_NORELAX
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.
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
@ WinEH
Windows Exception Handling.
Definition CodeGen.h:58
const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const override
X86_64MCAsmInfoDarwin(const Triple &Triple, const MCTargetOptions &Options)