]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / llvm / lib / Target / X86 / MCTargetDesc / X86MCAsmInfo.cpp
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"
17 #include "llvm/Support/CommandLine.h"
18 using namespace llvm;
19
20 enum AsmWriterFlavorTy {
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
26 static cl::opt<AsmWriterFlavorTy> AsmWriterFlavor(
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
39 X86MCAsmInfoDarwin::X86MCAsmInfoDarwin(const Triple &T) {
40   bool is64Bit = T.getArch() == Triple::x86_64;
41   if (is64Bit)
42     CodePointerSize = CalleeSaveStackSlotSize = 8;
43
44   AssemblerDialect = AsmWriterFlavor;
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
58   SupportsDebugInformation = true;
59   UseDataRegionDirectives = MarkedJTDataRegions;
60
61   // Exceptions handling
62   ExceptionsType = ExceptionHandling::DwarfCFI;
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))
68     HasWeakDefCanBeHiddenDirective = false;
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).
73   DwarfFDESymbolsUseAbsDiff = true;
74
75   UseIntegratedAssembler = true;
76 }
77
78 X86_64MCAsmInfoDarwin::X86_64MCAsmInfoDarwin(const Triple &Triple)
79   : X86MCAsmInfoDarwin(Triple) {
80 }
81
82 void X86ELFMCAsmInfo::anchor() { }
83
84 X86ELFMCAsmInfo::X86ELFMCAsmInfo(const Triple &T) {
85   bool is64Bit = T.getArch() == Triple::x86_64;
86   bool isX32 = T.getEnvironment() == Triple::GNUX32;
87
88   // For ELF, x86-64 pointer size depends on the ABI.
89   // For x86-64 without the x32 ABI, pointer size is 8. For x86 and for x86-64
90   // with the x32 ABI, pointer size remains the default 4.
91   CodePointerSize = (is64Bit && !isX32) ? 8 : 4;
92
93   // OTOH, stack slot size is always 8 for x86-64, even with the x32 ABI.
94   CalleeSaveStackSlotSize = is64Bit ? 8 : 4;
95
96   AssemblerDialect = AsmWriterFlavor;
97
98   TextAlignFillValue = 0x90;
99
100   // Debug Information
101   SupportsDebugInformation = true;
102
103   // Exceptions handling
104   ExceptionsType = ExceptionHandling::DwarfCFI;
105
106   // Always enable the integrated assembler by default.
107   // Clang also enabled it when the OS is Solaris but that is redundant here.
108   UseIntegratedAssembler = true;
109 }
110
111 const MCExpr *
112 X86_64MCAsmInfoDarwin::getExprForPersonalitySymbol(const MCSymbol *Sym,
113                                                    unsigned Encoding,
114                                                    MCStreamer &Streamer) const {
115   MCContext &Context = Streamer.getContext();
116   const MCExpr *Res =
117     MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOTPCREL, Context);
118   const MCExpr *Four = MCConstantExpr::create(4, Context);
119   return MCBinaryExpr::createAdd(Res, Four, Context);
120 }
121
122 void X86MCAsmInfoMicrosoft::anchor() { }
123
124 X86MCAsmInfoMicrosoft::X86MCAsmInfoMicrosoft(const Triple &Triple) {
125   if (Triple.getArch() == Triple::x86_64) {
126     PrivateGlobalPrefix = ".L";
127     PrivateLabelPrefix = ".L";
128     CodePointerSize = 8;
129     WinEHEncodingType = WinEH::EncodingType::Itanium;
130   } else {
131     // 32-bit X86 doesn't use CFI, so this isn't a real encoding type. It's just
132     // a place holder that the Windows EHStreamer looks for to suppress CFI
133     // output. In particular, usesWindowsCFI() returns false.
134     WinEHEncodingType = WinEH::EncodingType::X86;
135   }
136
137   ExceptionsType = ExceptionHandling::WinEH;
138
139   AssemblerDialect = AsmWriterFlavor;
140
141   TextAlignFillValue = 0x90;
142
143   AllowAtInName = true;
144
145   UseIntegratedAssembler = true;
146 }
147
148 void X86MCAsmInfoGNUCOFF::anchor() { }
149
150 X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
151   assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
152   if (Triple.getArch() == Triple::x86_64) {
153     PrivateGlobalPrefix = ".L";
154     PrivateLabelPrefix = ".L";
155     CodePointerSize = 8;
156     WinEHEncodingType = WinEH::EncodingType::Itanium;
157     ExceptionsType = ExceptionHandling::WinEH;
158   } else {
159     ExceptionsType = ExceptionHandling::DwarfCFI;
160   }
161
162   AssemblerDialect = AsmWriterFlavor;
163
164   TextAlignFillValue = 0x90;
165
166   AllowAtInName = true;
167
168   UseIntegratedAssembler = true;
169 }