LLVM 24.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/ADT/Enum.h"
15#include "llvm/MC/MCExpr.h"
18
19using namespace llvm;
20
21void PPCELFMCAsmInfo::anchor() { }
22
24 {{"DTPREL"}, PPC::S_DTPREL},
25 {{"GOT"}, PPC::S_GOT},
26 {{"got@ha"}, PPC::S_GOT_HA},
27 {{"got@h"}, PPC::S_GOT_HI},
28 {{"got@l"}, PPC::S_GOT_LO},
29 {{"ha"}, PPC::S_HA},
30 {{"h"}, PPC::S_HI},
31 {{"high"}, PPC::S_HIGH},
32 {{"higha"}, PPC::S_HIGHA},
33 {{"higher"}, PPC::S_HIGHER},
34 {{"highera"}, PPC::S_HIGHERA},
35 {{"highest"}, PPC::S_HIGHEST},
36 {{"highesta"}, PPC::S_HIGHESTA},
37 {{"l"}, PPC::S_LO},
38 {{"PCREL"}, PPC::S_PCREL},
39 {{"PLT"}, PPC::S_PLT},
40 {{"tlsgd"}, PPC::S_TLSGD},
41 {{"tlsld"}, PPC::S_TLSLD},
42 {{"toc"}, PPC::S_TOC},
43 {{"tocbase"}, PPC::S_TOCBASE},
44 {{"toc@ha"}, PPC::S_TOC_HA},
45 {{"toc@h"}, PPC::S_TOC_HI},
46 {{"toc@l"}, PPC::S_TOC_LO},
47 {{"TPREL"}, PPC::S_TPREL},
48 {{"gd"}, PPC::S_AIX_TLSGD},
49 {{"m"}, PPC::S_AIX_TLSGDM},
50 {{"ie"}, PPC::S_AIX_TLSIE},
51 {{"ld"}, PPC::S_AIX_TLSLD},
52 {{"le"}, PPC::S_AIX_TLSLE},
53 {{"ml"}, PPC::S_AIX_TLSML},
54 {{"dtpmod"}, PPC::S_DTPMOD},
55 {{"dtprel@ha"}, PPC::S_DTPREL_HA},
56 {{"dtprel@h"}, PPC::S_DTPREL_HI},
57 {{"dtprel@high"}, PPC::S_DTPREL_HIGH},
58 {{"dtprel@higha"}, PPC::S_DTPREL_HIGHA},
59 {{"dtprel@higher"}, PPC::S_DTPREL_HIGHER},
60 {{"dtprel@highera"}, PPC::S_DTPREL_HIGHERA},
61 {{"dtprel@highest"}, PPC::S_DTPREL_HIGHEST},
62 {{"dtprel@highesta"}, PPC::S_DTPREL_HIGHESTA},
63 {{"dtprel@l"}, PPC::S_DTPREL_LO},
64 {{"got@dtprel"}, PPC::S_GOT_DTPREL},
65 {{"got@dtprel@ha"}, PPC::S_GOT_DTPREL_HA},
66 {{"got@dtprel@h"}, PPC::S_GOT_DTPREL_HI},
67 {{"got@dtprel@l"}, PPC::S_GOT_DTPREL_LO},
68 {{"got@pcrel"}, PPC::S_GOT_PCREL},
69 {{"got@tlsgd"}, PPC::S_GOT_TLSGD},
70 {{"got@tlsgd@ha"}, PPC::S_GOT_TLSGD_HA},
71 {{"got@tlsgd@h"}, PPC::S_GOT_TLSGD_HI},
72 {{"got@tlsgd@l"}, PPC::S_GOT_TLSGD_LO},
73 {{"got@tlsgd@pcrel"}, PPC::S_GOT_TLSGD_PCREL},
74 {{"got@tlsld"}, PPC::S_GOT_TLSLD},
75 {{"got@tlsld@ha"}, PPC::S_GOT_TLSLD_HA},
76 {{"got@tlsld@h"}, PPC::S_GOT_TLSLD_HI},
77 {{"got@tlsld@l"}, PPC::S_GOT_TLSLD_LO},
78 {{"got@tlsld@pcrel"}, PPC::S_GOT_TLSLD_PCREL},
79 {{"got@tprel"}, PPC::S_GOT_TPREL},
80 {{"got@tprel@ha"}, PPC::S_GOT_TPREL_HA},
81 {{"got@tprel@h"}, PPC::S_GOT_TPREL_HI},
82 {{"got@tprel@l"}, PPC::S_GOT_TPREL_LO},
83 {{"got@tprel@pcrel"}, PPC::S_GOT_TPREL_PCREL},
84 {{"local"}, PPC::S_LOCAL},
85 {{"notoc"}, PPC::S_NOTOC},
86 {{"<<invalid>>"}, PPC::S_PCREL_OPT},
87 {{"tls"}, PPC::S_TLS},
88 {{"tls@pcrel"}, PPC::S_TLS_PCREL},
89 {{"tprel@ha"}, PPC::S_TPREL_HA},
90 {{"tprel@h"}, PPC::S_TPREL_HI},
91 {{"tprel@high"}, PPC::S_TPREL_HIGH},
92 {{"tprel@higha"}, PPC::S_TPREL_HIGHA},
93 {{"tprel@higher"}, PPC::S_TPREL_HIGHER},
94 {{"tprel@highera"}, PPC::S_TPREL_HIGHERA},
95 {{"tprel@highest"}, PPC::S_TPREL_HIGHEST},
96 {{"tprel@highesta"}, PPC::S_TPREL_HIGHESTA},
97 {{"tprel@l"}, PPC::S_TPREL_LO},
98};
100
102 // clang-format off
103 {{"gd"}, PPC::S_AIX_TLSGD},
104 {{"m"}, PPC::S_AIX_TLSGDM},
105 {{"ie"}, PPC::S_AIX_TLSIE},
106 {{"ld"}, PPC::S_AIX_TLSLD},
107 {{"le"}, PPC::S_AIX_TLSLE},
108 {{"ml"}, PPC::S_AIX_TLSML},
109 {{"l"}, PPC::S_L},
110 {{"u"}, PPC::S_U},
111 // clang-format on
112};
114
115static std::optional<int64_t> evaluateAsInt64(uint16_t specifier,
116 int64_t Value) {
117 switch (specifier) {
118 case PPC::S_LO:
119 return Value & 0xffff;
120 case PPC::S_HI:
121 return (Value >> 16) & 0xffff;
122 case PPC::S_HA:
123 return ((Value + 0x8000) >> 16) & 0xffff;
124 case PPC::S_HIGH:
125 return (Value >> 16) & 0xffff;
126 case PPC::S_HIGHA:
127 return ((Value + 0x8000) >> 16) & 0xffff;
128 case PPC::S_HIGHER:
129 return (Value >> 32) & 0xffff;
130 case PPC::S_HIGHERA:
131 return ((Value + 0x8000) >> 32) & 0xffff;
132 case PPC::S_HIGHEST:
133 return (Value >> 48) & 0xffff;
134 case PPC::S_HIGHESTA:
135 return ((Value + 0x8000) >> 48) & 0xffff;
136 default:
137 return {};
138 }
139}
140
141bool PPC::evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res) {
143
144 if (!Expr.getSubExpr()->evaluateAsRelocatable(Value, nullptr))
145 return false;
146
147 if (!Value.isAbsolute())
148 return false;
149 auto Tmp = evaluateAsInt64(Expr.getSpecifier(), Value.getConstant());
150 if (!Tmp)
151 return false;
152 Res = *Tmp;
153 return true;
154}
155
156static bool evaluateAsRelocatable(const MCSpecifierExpr &Expr, MCValue &Res,
157 const MCAssembler *Asm) {
158 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
159 return false;
160
161 // The signedness of the result is dependent on the instruction operand. E.g.
162 // in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
163 // parse time (!Asm), disable the folding.
164 std::optional<int64_t> MaybeInt =
166 if (Res.isAbsolute() && MaybeInt) {
167 Res = MCValue::get(*MaybeInt);
168 } else {
169 Res.setSpecifier(Expr.getSpecifier());
170 }
171
172 return true;
173}
174
178 // FIXME: This is not always needed. For example, it is not needed in the
179 // v2 abi.
180 NeedsLocalForSize = true;
181
182 if (is64Bit) {
184 }
186 T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle;
187
188 // ".comm align is in bytes but .align is pow-2."
189 AlignmentIsInBytes = false;
190
191 CommentString = "#";
192
193 // Uses '.section' before '.bss' directive
195
196 // Debug Information
198
199 DollarIsPC = true;
200
201 // Set up DWARF directives
203
204 // Exceptions handling
206
207 ZeroDirective = "\t.space\t";
208 Data64bitsDirective = is64Bit ? "\t.quad\t" : nullptr;
209 AssemblerDialect = 1; // New-Style mnemonics.
211
213}
214
216 const MCSpecifierExpr &Expr) const {
217 printExpr(OS, *Expr.getSubExpr());
218 OS << '@' << getSpecifierName(Expr.getSpecifier());
219}
220
222 MCValue &Res,
223 const MCAssembler *Asm) const {
224 return evaluateAsRelocatable(Expr, Res, Asm);
225}
226
230 if (T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle)
231 report_fatal_error("XCOFF is not supported for little-endian targets");
232 CodePointerSize = CalleeSaveStackSlotSize = Is64Bit ? 8 : 4;
233
234 // A size of 8 is only supported by the assembler under 64-bit.
235 Data64bitsDirective = Is64Bit ? "\t.vbyte\t8, " : nullptr;
236
237 // Debug Information
239
240 // Set up DWARF directives
242
243 // Support $ as PC in inline asm
244 DollarIsPC = true;
245
247
249}
250
252 const MCSpecifierExpr &Expr) const {
253 printExpr(OS, *Expr.getSubExpr());
254 OS << '@' << getSpecifierName(Expr.getSpecifier());
255}
256
258 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
259 return evaluateAsRelocatable(Expr, Res, Asm);
260}
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > ELFAtSpecifierDefs[]
#define BUILD_ENUM_STRINGS(Tab)
Definition Enum.h:120
static LVOptions Options
Definition LVOptions.cpp:25
#define T
static bool evaluateAsRelocatable(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm)
constexpr EnumStringDef< MCAsmInfo::AtSpecifierKind > XCOFFAtSpecifierDefs[]
static std::optional< int64_t > evaluateAsInt64(uint16_t specifier, int64_t Value)
constexpr auto elfAtSpecifiers
constexpr auto xcoffAtSpecifiers
static bool is64Bit(const char *name)
MCAsmInfoELF(const MCTargetOptions &Options)
MCAsmInfoXCOFF(const MCTargetOptions &Options)
unsigned MinInstAlignment
Every possible instruction length is a multiple of this value.
Definition MCAsmInfo.h:122
const char * Data64bitsDirective
Definition MCAsmInfo.h:245
bool DollarIsPC
The '$' token, when not referencing an identifier or constant, refers to the current PC.
Definition MCAsmInfo.h:126
bool NeedsLocalForSize
Definition MCAsmInfo.h:154
ExceptionHandling ExceptionsType
Exception handling format for the target. Defaults to None.
Definition MCAsmInfo.h:357
StringRef getSpecifierName(uint32_t S) const
bool UsesSetToEquateSymbol
Use .set instead of = to equate a symbol to an expression.
Definition MCAsmInfo.h:148
LCOMM::LCOMMType LCOMMDirectiveAlignmentType
Describes if the .lcomm directive for the target supports an alignment argument and how it is interpr...
Definition MCAsmInfo.h:293
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:258
bool SupportsDebugInformation
True if target supports emission of debugging information.
Definition MCAsmInfo.h:354
unsigned AssemblerDialect
Which dialect of an assembler variant to use. Defaults to 0.
Definition MCAsmInfo.h:173
bool AlignmentIsInBytes
If this is true (the default) then the asmprinter emits ".align N" directives, where N is the number ...
Definition MCAsmInfo.h:268
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:221
void initializeAtSpecifiers(EnumStrings< AtSpecifierKind, 1 >)
bool IsLittleEndian
True if target is little endian. Default is true.
Definition MCAsmInfo.h:93
unsigned CodePointerSize
Code pointer size in bytes. Default is 4.
Definition MCAsmInfo.h:86
unsigned CalleeSaveStackSlotSize
Size of the stack slot reserved for callee-saved registers, in bytes.
Definition MCAsmInfo.h:90
StringRef CommentString
This indicates the comment string used by the assembler.
Definition MCAsmInfo.h:134
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:494
const MCExpr * getSubExpr() const
Definition MCExpr.h:508
Spec getSpecifier() const
Definition MCExpr.h:507
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
bool evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const override
PPCELFMCAsmInfo(bool is64Bit, const Triple &, const MCTargetOptions &Options)
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 &, const MCTargetOptions &Options)
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
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
bool evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res)
@ S_GOT_TLSGD_PCREL
@ S_GOT_TLSLD_PCREL
@ S_DTPREL_HIGHESTA
This is an optimization pass for GlobalISel generic memory operations.
@ DwarfCFI
DWARF-like instruction based exceptions.
Definition CodeGen.h:55
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
Compile-time data representation of enum entries.
Definition Enum.h:47