LLVM 22.0.0git
PPCMCAsmInfo.cpp
Go to the documentation of this file.
1//===-- PPCMCAsmInfo.cpp - PPC 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 MCAsmInfoDarwin properties.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/MC/MCExpr.h"
17
18using namespace llvm;
19
20void PPCELFMCAsmInfo::anchor() { }
21
23 {PPC::S_DTPREL, "DTPREL"},
24 {PPC::S_GOT, "GOT"},
25 {PPC::S_GOT_HA, "got@ha"},
26 {PPC::S_GOT_HI, "got@h"},
27 {PPC::S_GOT_LO, "got@l"},
28 {PPC::S_HA, "ha"},
29 {PPC::S_HI, "h"},
30 {PPC::S_HIGH, "high"},
31 {PPC::S_HIGHA, "higha"},
32 {PPC::S_HIGHER, "higher"},
33 {PPC::S_HIGHERA, "highera"},
34 {PPC::S_HIGHEST, "highest"},
35 {PPC::S_HIGHESTA, "highesta"},
36 {PPC::S_LO, "l"},
37 {PPC::S_PCREL, "PCREL"},
38 {PPC::S_PLT, "PLT"},
39 {PPC::S_TLSGD, "tlsgd"},
40 {PPC::S_TLSLD, "tlsld"},
41 {PPC::S_TOC, "toc"},
42 {PPC::S_TOCBASE, "tocbase"},
43 {PPC::S_TOC_HA, "toc@ha"},
44 {PPC::S_TOC_HI, "toc@h"},
45 {PPC::S_TOC_LO, "toc@l"},
46 {PPC::S_TPREL, "TPREL"},
47 {PPC::S_AIX_TLSGD, "gd"},
48 {PPC::S_AIX_TLSGDM, "m"},
49 {PPC::S_AIX_TLSIE, "ie"},
50 {PPC::S_AIX_TLSLD, "ld"},
51 {PPC::S_AIX_TLSLE, "le"},
52 {PPC::S_AIX_TLSML, "ml"},
53 {PPC::S_DTPMOD, "dtpmod"},
54 {PPC::S_DTPREL_HA, "dtprel@ha"},
55 {PPC::S_DTPREL_HI, "dtprel@h"},
56 {PPC::S_DTPREL_HIGH, "dtprel@high"},
57 {PPC::S_DTPREL_HIGHA, "dtprel@higha"},
58 {PPC::S_DTPREL_HIGHER, "dtprel@higher"},
59 {PPC::S_DTPREL_HIGHERA, "dtprel@highera"},
60 {PPC::S_DTPREL_HIGHEST, "dtprel@highest"},
61 {PPC::S_DTPREL_HIGHESTA, "dtprel@highesta"},
62 {PPC::S_DTPREL_LO, "dtprel@l"},
63 {PPC::S_GOT_DTPREL, "got@dtprel"},
64 {PPC::S_GOT_DTPREL_HA, "got@dtprel@ha"},
65 {PPC::S_GOT_DTPREL_HI, "got@dtprel@h"},
66 {PPC::S_GOT_DTPREL_LO, "got@dtprel@l"},
67 {PPC::S_GOT_PCREL, "got@pcrel"},
68 {PPC::S_GOT_TLSGD, "got@tlsgd"},
69 {PPC::S_GOT_TLSGD_HA, "got@tlsgd@ha"},
70 {PPC::S_GOT_TLSGD_HI, "got@tlsgd@h"},
71 {PPC::S_GOT_TLSGD_LO, "got@tlsgd@l"},
72 {PPC::S_GOT_TLSGD_PCREL, "got@tlsgd@pcrel"},
73 {PPC::S_GOT_TLSLD, "got@tlsld"},
74 {PPC::S_GOT_TLSLD_HA, "got@tlsld@ha"},
75 {PPC::S_GOT_TLSLD_HI, "got@tlsld@h"},
76 {PPC::S_GOT_TLSLD_LO, "got@tlsld@l"},
77 {PPC::S_GOT_TLSLD_PCREL, "got@tlsld@pcrel"},
78 {PPC::S_GOT_TPREL, "got@tprel"},
79 {PPC::S_GOT_TPREL_HA, "got@tprel@ha"},
80 {PPC::S_GOT_TPREL_HI, "got@tprel@h"},
81 {PPC::S_GOT_TPREL_LO, "got@tprel@l"},
82 {PPC::S_GOT_TPREL_PCREL, "got@tprel@pcrel"},
83 {PPC::S_LOCAL, "local"},
84 {PPC::S_NOTOC, "notoc"},
85 {PPC::S_PCREL_OPT, "<<invalid>>"},
86 {PPC::S_TLS, "tls"},
87 {PPC::S_TLS_PCREL, "tls@pcrel"},
88 {PPC::S_TPREL_HA, "tprel@ha"},
89 {PPC::S_TPREL_HI, "tprel@h"},
90 {PPC::S_TPREL_HIGH, "tprel@high"},
91 {PPC::S_TPREL_HIGHA, "tprel@higha"},
92 {PPC::S_TPREL_HIGHER, "tprel@higher"},
93 {PPC::S_TPREL_HIGHERA, "tprel@highera"},
94 {PPC::S_TPREL_HIGHEST, "tprel@highest"},
95 {PPC::S_TPREL_HIGHESTA, "tprel@highesta"},
96 {PPC::S_TPREL_LO, "tprel@l"},
97};
98
100 // clang-format off
101 {PPC::S_AIX_TLSGD, "gd"},
102 {PPC::S_AIX_TLSGDM, "m"},
103 {PPC::S_AIX_TLSIE, "ie"},
104 {PPC::S_AIX_TLSLD, "ld"},
105 {PPC::S_AIX_TLSLE, "le"},
106 {PPC::S_AIX_TLSML, "ml"},
107 {PPC::S_L, "l"},
108 {PPC::S_U, "u"},
109 // clang-format on
110};
111
112static std::optional<int64_t> evaluateAsInt64(uint16_t specifier,
113 int64_t Value) {
114 switch (specifier) {
115 case PPC::S_LO:
116 return Value & 0xffff;
117 case PPC::S_HI:
118 return (Value >> 16) & 0xffff;
119 case PPC::S_HA:
120 return ((Value + 0x8000) >> 16) & 0xffff;
121 case PPC::S_HIGH:
122 return (Value >> 16) & 0xffff;
123 case PPC::S_HIGHA:
124 return ((Value + 0x8000) >> 16) & 0xffff;
125 case PPC::S_HIGHER:
126 return (Value >> 32) & 0xffff;
127 case PPC::S_HIGHERA:
128 return ((Value + 0x8000) >> 32) & 0xffff;
129 case PPC::S_HIGHEST:
130 return (Value >> 48) & 0xffff;
131 case PPC::S_HIGHESTA:
132 return ((Value + 0x8000) >> 48) & 0xffff;
133 default:
134 return {};
135 }
136}
137
138bool PPC::evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res) {
140
141 if (!Expr.getSubExpr()->evaluateAsRelocatable(Value, nullptr))
142 return false;
143
144 if (!Value.isAbsolute())
145 return false;
146 auto Tmp = evaluateAsInt64(Expr.getSpecifier(), Value.getConstant());
147 if (!Tmp)
148 return false;
149 Res = *Tmp;
150 return true;
151}
152
153static bool evaluateAsRelocatable(const MCSpecifierExpr &Expr, MCValue &Res,
154 const MCAssembler *Asm) {
155 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
156 return false;
157
158 // The signedness of the result is dependent on the instruction operand. E.g.
159 // in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
160 // parse time (!Asm), disable the folding.
161 std::optional<int64_t> MaybeInt =
163 if (Res.isAbsolute() && MaybeInt) {
164 Res = MCValue::get(*MaybeInt);
165 } else {
166 Res.setSpecifier(Expr.getSpecifier());
167 }
168
169 return true;
170}
171
173 // FIXME: This is not always needed. For example, it is not needed in the
174 // v2 abi.
175 NeedsLocalForSize = true;
176
177 if (is64Bit) {
179 }
181 T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle;
182
183 // ".comm align is in bytes but .align is pow-2."
184 AlignmentIsInBytes = false;
185
186 CommentString = "#";
187
188 // Uses '.section' before '.bss' directive
190
191 // Debug Information
193
194 DollarIsPC = true;
196
197 // Set up DWARF directives
199
200 // Exceptions handling
202
203 ZeroDirective = "\t.space\t";
204 Data64bitsDirective = is64Bit ? "\t.quad\t" : nullptr;
205 AssemblerDialect = 1; // New-Style mnemonics.
207
209}
210
212 const MCSpecifierExpr &Expr) const {
213 printExpr(OS, *Expr.getSubExpr());
214 OS << '@' << getSpecifierName(Expr.getSpecifier());
215}
216
218 MCValue &Res,
219 const MCAssembler *Asm) const {
220 return evaluateAsRelocatable(Expr, Res, Asm);
221}
222
224 if (T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle)
225 report_fatal_error("XCOFF is not supported for little-endian targets");
226 CodePointerSize = CalleeSaveStackSlotSize = Is64Bit ? 8 : 4;
227
228 // A size of 8 is only supported by the assembler under 64-bit.
229 Data64bitsDirective = Is64Bit ? "\t.vbyte\t8, " : nullptr;
230
231 // Debug Information
233
234 // Set up DWARF directives
236
237 // Support $ as PC in inline asm
238 DollarIsPC = true;
240
242
244}
245
247 const MCSpecifierExpr &Expr) const {
248 printExpr(OS, *Expr.getSubExpr());
249 OS << '@' << getSpecifierName(Expr.getSpecifier());
250}
251
253 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
254 return evaluateAsRelocatable(Expr, Res, Asm);
255}
static bool evaluateAsRelocatable(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm)
const MCAsmInfo::AtSpecifier elfAtSpecifiers[]
static std::optional< int64_t > evaluateAsInt64(uint16_t specifier, int64_t Value)
const MCAsmInfo::AtSpecifier xcoffAtSpecifiers[]
raw_pwrite_stream & OS
static bool is64Bit(const char *name)
unsigned MinInstAlignment
Every possible instruction length is a multiple of this value.
Definition: MCAsmInfo.h:123
void initializeAtSpecifiers(ArrayRef< AtSpecifier >)
Definition: MCAsmInfo.cpp:127
const char * Data64bitsDirective
Definition: MCAsmInfo.h:250
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC.
Definition: MCAsmInfo.h:127
bool NeedsLocalForSize
Definition: MCAsmInfo.h:155
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition: MCAsmInfo.h:359
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:196
StringRef getSpecifierName(uint32_t S) const
Definition: MCAsmInfo.cpp:139
bool UsesSetToEquateSymbol
Use .set instead of = to equate a symbol to an expression.
Definition: MCAsmInfo.h:149
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition: MCAsmInfo.h:298
void printExpr(raw_ostream &, const MCExpr &) const
Definition: MCAsmInfo.cpp:153
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
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition: MCAsmInfo.h:273
const char * ZeroDirective
This should be set to the directive used to get some number of zero (and non-zero if supported by the...
Definition: MCAsmInfo.h:226
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
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
static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB=nullptr, int64_t Val=0, uint32_t Specifier=0)
Definition: MCValue.h:56
void setSpecifier(uint32_t S)
Definition: MCValue.h:47
int64_t getConstant() const
Definition: MCValue.h:44
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:54
PPCELFMCAsmInfo(bool is64Bit, const Triple &)
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
PPCXCOFFMCAsmInfo(bool is64Bit, const Triple &)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
@ ByteAlignment
Definition: MCAsmInfo.h:58
bool evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res)
@ S_TPREL_HIGHESTA
Definition: PPCMCAsmInfo.h:122
@ S_GOT_TLSGD_PCREL
Definition: PPCMCAsmInfo.h:88
@ S_GOT_TLSGD_LO
Definition: PPCMCAsmInfo.h:87
@ S_DTPREL_HIGHA
Definition: PPCMCAsmInfo.h:69
@ S_GOT_TPREL_PCREL
Definition: PPCMCAsmInfo.h:98
@ S_GOT_TLSLD_PCREL
Definition: PPCMCAsmInfo.h:93
@ S_DTPREL_HIGHEST
Definition: PPCMCAsmInfo.h:72
@ S_GOT_TLSLD_LO
Definition: PPCMCAsmInfo.h:92
@ S_DTPREL_HIGHESTA
Definition: PPCMCAsmInfo.h:73
@ S_GOT_TLSGD_HA
Definition: PPCMCAsmInfo.h:85
@ S_GOT_TLSGD_HI
Definition: PPCMCAsmInfo.h:86
@ S_GOT_DTPREL_HI
Definition: PPCMCAsmInfo.h:78
@ S_GOT_TLSLD_HI
Definition: PPCMCAsmInfo.h:91
@ S_GOT_TPREL_HA
Definition: PPCMCAsmInfo.h:95
@ S_GOT_DTPREL_HA
Definition: PPCMCAsmInfo.h:77
@ S_GOT_TPREL_LO
Definition: PPCMCAsmInfo.h:97
@ S_GOT_TLSLD_HA
Definition: PPCMCAsmInfo.h:90
@ S_DTPREL_HIGHER
Definition: PPCMCAsmInfo.h:70
@ S_GOT_TPREL_HI
Definition: PPCMCAsmInfo.h:96
@ S_DTPREL_HIGHERA
Definition: PPCMCAsmInfo.h:71
@ S_GOT_DTPREL_LO
Definition: PPCMCAsmInfo.h:79
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ DwarfCFI
DWARF-like instruction based exceptions.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition: Error.cpp:167