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