LLVM  14.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/ADT/Triple.h"
15 #include "llvm/MC/MCExpr.h"
16 #include "llvm/MC/MCStreamer.h"
18 using 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("Choose style of code to emit from X86 backend:"),
29  cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"),
30  clEnumValN(Intel, "intel", "Emit Intel-style assembly")));
31 
32 static cl::opt<bool>
33 MarkedJTDataRegions("mark-data-regions", cl::init(true),
34  cl::desc("Mark code section jump table data regions."),
35  cl::Hidden);
36 
37 void X86MCAsmInfoDarwin::anchor() { }
38 
40  bool is64Bit = T.getArch() == Triple::x86_64;
41  if (is64Bit)
43 
45 
46  TextAlignFillValue = 0x90;
47 
48  if (!is64Bit)
49  Data64bitsDirective = nullptr; // we can't emit a 64-bit unit
50 
51  // Use ## as a comment string so that .s files generated by llvm can go
52  // through the GCC preprocessor without causing an error. This is needed
53  // because "clang foo.s" runs the C preprocessor, which is usually reserved
54  // for .S files on other systems. Perhaps this is because the file system
55  // wasn't always case preserving or something.
56  CommentString = "##";
57 
60 
61  // Exceptions handling
63 
64  // old assembler lacks some directives
65  // FIXME: this should really be a check on the assembler characteristics
66  // rather than OS version
67  if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))
69 
70  // Assume ld64 is new enough that the abs-ified FDE relocs may be used
71  // (actually, must, since otherwise the non-extern relocations we produce
72  // overwhelm ld64's tiny little mind and it fails).
74 }
75 
78 }
79 
80 void X86ELFMCAsmInfo::anchor() { }
81 
83  bool is64Bit = T.getArch() == Triple::x86_64;
84  bool isX32 = T.isX32();
85 
86  // For ELF, x86-64 pointer size depends on the ABI.
87  // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
88  // with the x32 ABI, pointer size remains the default 4.
89  CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
90 
91  // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
93 
95 
96  TextAlignFillValue = 0x90;
97 
98  // Debug Information
100 
101  // Exceptions handling
103 }
104 
105 const MCExpr *
107  unsigned Encoding,
108  MCStreamer &Streamer) const {
109  MCContext &Context = Streamer.getContext();
110  const MCExpr *Res =
112  const MCExpr *Four = MCConstantExpr::create(4, Context);
113  return MCBinaryExpr::createAdd(Res, Four, Context);
114 }
115 
116 void X86MCAsmInfoMicrosoft::anchor() { }
117 
119  if (Triple.getArch() == Triple::x86_64) {
120  PrivateGlobalPrefix = ".L";
121  PrivateLabelPrefix = ".L";
122  CodePointerSize = 8;
124  } else {
125  // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
126  // a place holder that the Windows EHStreamer looks for to suppress CFI
127  // output. In particular, usesWindowsCFI() returns false.
129  }
130 
132 
134 
135  TextAlignFillValue = 0x90;
136 
137  AllowAtInName = true;
138 }
139 
140 void X86MCAsmInfoMicrosoftMASM::anchor() { }
141 
144  DollarIsPC = true;
145  SeparatorString = "\n";
146  CommentString = ";";
147  AllowAdditionalComments = false;
151 }
152 
153 void X86MCAsmInfoGNUCOFF::anchor() { }
154 
156  assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
157  if (Triple.getArch() == Triple::x86_64) {
158  PrivateGlobalPrefix = ".L";
159  PrivateLabelPrefix = ".L";
160  CodePointerSize = 8;
163  } else {
165  }
166 
168 
169  TextAlignFillValue = 0x90;
170 
171  AllowAtInName = true;
172 }
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::X86MCAsmInfoMicrosoft
Definition: X86MCAsmInfo.h:44
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin
X86_64MCAsmInfoDarwin(const Triple &Triple)
Definition: X86MCAsmInfo.cpp:76
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
is64Bit
static bool is64Bit(const char *name)
Definition: X86Disassembler.cpp:1023
llvm::X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF
X86MCAsmInfoGNUCOFF(const Triple &Triple)
Definition: X86MCAsmInfo.cpp:155
llvm::MCConstantExpr::create
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
llvm::MCAsmInfo::SupportsDebugInformation
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition: MCAsmInfo.h:445
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::WinEH::EncodingType::X86
@ X86
Windows x64, Windows Itanium (IA-64)
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:84
llvm::WinEH::EncodingType::Itanium
@ Itanium
Windows CE ARM, PowerPC, SH3, SH4.
llvm::MCAsmInfo::Data64bitsDirective
const char * Data64bitsDirective
Definition: MCAsmInfo.h:288
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::X86MCAsmInfoDarwin::X86MCAsmInfoDarwin
X86MCAsmInfoDarwin(const Triple &Triple)
Definition: X86MCAsmInfo.cpp:39
llvm::MCAsmInfo::PrivateLabelPrefix
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition: MCAsmInfo.h:172
llvm::MCAsmInfo::UseDataRegionDirectives
bool UseDataRegionDirectives
This is true if data region markers should be printed as ".data_region/.end_data_region" directives.
Definition: MCAsmInfo.h:234
llvm::X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM
X86MCAsmInfoMicrosoftMASM(const Triple &Triple)
Definition: X86MCAsmInfo.cpp:142
llvm::MCAsmInfo::AllowAtInName
bool AllowAtInName
This is true if the assembler allows @ characters in symbol names.
Definition: MCAsmInfo.h:197
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
CommandLine.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::MCAsmInfo::PrivateGlobalPrefix
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition: MCAsmInfo.h:168
llvm::MCAsmInfo::DwarfFDESymbolsUseAbsDiff
bool DwarfFDESymbolsUseAbsDiff
True if DWARF FDE symbol reference relocations should be replaced by an absolute difference.
Definition: MCAsmInfo.h:463
ATT
@ ATT
Definition: X86MCAsmInfo.cpp:23
llvm::X86ELFMCAsmInfo::X86ELFMCAsmInfo
X86ELFMCAsmInfo(const Triple &Triple)
Definition: X86MCAsmInfo.cpp:82
llvm::Triple::getArch
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
Definition: Triple.h:307
llvm::MCAsmInfo::SeparatorString
const char * SeparatorString
This string, if specified, is used to separate instructions from each other when on the same line.
Definition: MCAsmInfo.h:131
llvm::cl::opt
Definition: CommandLine.h:1434
llvm::cl::values
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:699
llvm::X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol
const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const override
Definition: X86MCAsmInfo.cpp:106
llvm::MCAsmInfo::CommentString
StringRef CommentString
This indicates the comment string used by the assembler.
Definition: MCAsmInfo.h:135
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
llvm::MCAsmInfo::CodePointerSize
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition: MCAsmInfo.h:72
llvm::MCAsmInfo::AssemblerDialect
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition: MCAsmInfo.h:193
llvm::MCAsmInfo::HasWeakDefCanBeHiddenDirective
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:422
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCAsmInfo::WinEHEncodingType
WinEH::EncodingType WinEHEncodingType
Windows exception handling data (.pdata) encoding. Defaults to Invalid.
Definition: MCAsmInfo.h:455
llvm::X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft
X86MCAsmInfoMicrosoft(const Triple &Triple)
Definition: X86MCAsmInfo.cpp:118
Triple.h
llvm::MCBinaryExpr::createAdd
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:524
AsmWriterFlavor
static cl::opt< AsmWriterFlavorTy > AsmWriterFlavor("x86-asm-syntax", cl::init(ATT), cl::Hidden, cl::desc("Choose style of code to emit from X86 backend:"), cl::values(clEnumValN(ATT, "att", "Emit AT&T-style assembly"), clEnumValN(Intel, "intel", "Emit Intel-style assembly")))
clEnumValN
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:674
llvm::MCAsmInfo::AllowDollarAtStartOfIdentifier
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:211
MarkedJTDataRegions
static cl::opt< bool > MarkedJTDataRegions("mark-data-regions", cl::init(true), cl::desc("Mark code section jump table data regions."), cl::Hidden)
llvm::MCSymbolRefExpr::VK_GOTPCREL
@ VK_GOTPCREL
Definition: MCExpr.h:202
llvm::MCAsmInfo::TextAlignFillValue
unsigned TextAlignFillValue
If non-zero, this is used to fill the executable space created as the result of a alignment directive...
Definition: MCAsmInfo.h:333
llvm::X86MCAsmInfoDarwin
Definition: X86MCAsmInfo.h:23
X86MCAsmInfo.h
llvm::MCAsmInfo::AllowAtAtStartOfIdentifier
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:218
llvm::Triple::isOSWindows
bool isOSWindows() const
Tests whether the OS is Windows.
Definition: Triple.h:547
llvm::MCAsmInfo::CalleeSaveStackSlotSize
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition: MCAsmInfo.h:76
llvm::ExceptionHandling::WinEH
@ WinEH
Windows Exception Handling.
llvm::MCAsmInfo::DollarIsPC
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC.
Definition: MCAsmInfo.h:119
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
Intel
@ Intel
Definition: X86MCAsmInfo.cpp:23
llvm::MCAsmInfo::AllowQuestionAtStartOfIdentifier
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:204
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:280
MCStreamer.h
llvm::MCAsmInfo::ExceptionsType
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition: MCAsmInfo.h:448
llvm::MCAsmInfo::AllowAdditionalComments
bool AllowAdditionalComments
This indicates whether to allow additional "comment strings" to be lexed as a comment.
Definition: MCAsmInfo.h:147
llvm::cl::desc
Definition: CommandLine.h:414
MCExpr.h
llvm::ExceptionHandling::DwarfCFI
@ DwarfCFI
DWARF-like instruction based exceptions.
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
AsmWriterFlavorTy
AsmWriterFlavorTy
Definition: X86MCAsmInfo.cpp:20