1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
//===-- PPCMCAsmInfo.cpp - PPC asm properties -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains the declarations of the MCAsmInfoDarwin properties.
//
//===----------------------------------------------------------------------===//
#include "MCTargetDesc/PPCMCAsmInfo.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Triple.h"
using namespace llvm;
void PPCELFMCAsmInfo::anchor() { }
const MCAsmInfo::AtSpecifier elfAtSpecifiers[] = {
{PPC::S_DTPREL, "DTPREL"},
{PPC::S_GOT, "GOT"},
{PPC::S_GOT_HA, "got@ha"},
{PPC::S_GOT_HI, "got@h"},
{PPC::S_GOT_LO, "got@l"},
{PPC::S_HA, "ha"},
{PPC::S_HI, "h"},
{PPC::S_HIGH, "high"},
{PPC::S_HIGHA, "higha"},
{PPC::S_HIGHER, "higher"},
{PPC::S_HIGHERA, "highera"},
{PPC::S_HIGHEST, "highest"},
{PPC::S_HIGHESTA, "highesta"},
{PPC::S_LO, "l"},
{PPC::S_PCREL, "PCREL"},
{PPC::S_PLT, "PLT"},
{PPC::S_TLSGD, "tlsgd"},
{PPC::S_TLSLD, "tlsld"},
{PPC::S_TOC, "toc"},
{PPC::S_TOCBASE, "tocbase"},
{PPC::S_TOC_HA, "toc@ha"},
{PPC::S_TOC_HI, "toc@h"},
{PPC::S_TOC_LO, "toc@l"},
{PPC::S_TPREL, "TPREL"},
{PPC::S_AIX_TLSGD, "gd"},
{PPC::S_AIX_TLSGDM, "m"},
{PPC::S_AIX_TLSIE, "ie"},
{PPC::S_AIX_TLSLD, "ld"},
{PPC::S_AIX_TLSLE, "le"},
{PPC::S_AIX_TLSML, "ml"},
{PPC::S_DTPMOD, "dtpmod"},
{PPC::S_DTPREL_HA, "dtprel@ha"},
{PPC::S_DTPREL_HI, "dtprel@h"},
{PPC::S_DTPREL_HIGH, "dtprel@high"},
{PPC::S_DTPREL_HIGHA, "dtprel@higha"},
{PPC::S_DTPREL_HIGHER, "dtprel@higher"},
{PPC::S_DTPREL_HIGHERA, "dtprel@highera"},
{PPC::S_DTPREL_HIGHEST, "dtprel@highest"},
{PPC::S_DTPREL_HIGHESTA, "dtprel@highesta"},
{PPC::S_DTPREL_LO, "dtprel@l"},
{PPC::S_GOT_DTPREL, "got@dtprel"},
{PPC::S_GOT_DTPREL_HA, "got@dtprel@ha"},
{PPC::S_GOT_DTPREL_HI, "got@dtprel@h"},
{PPC::S_GOT_DTPREL_LO, "got@dtprel@l"},
{PPC::S_GOT_PCREL, "got@pcrel"},
{PPC::S_GOT_TLSGD, "got@tlsgd"},
{PPC::S_GOT_TLSGD_HA, "got@tlsgd@ha"},
{PPC::S_GOT_TLSGD_HI, "got@tlsgd@h"},
{PPC::S_GOT_TLSGD_LO, "got@tlsgd@l"},
{PPC::S_GOT_TLSGD_PCREL, "got@tlsgd@pcrel"},
{PPC::S_GOT_TLSLD, "got@tlsld"},
{PPC::S_GOT_TLSLD_HA, "got@tlsld@ha"},
{PPC::S_GOT_TLSLD_HI, "got@tlsld@h"},
{PPC::S_GOT_TLSLD_LO, "got@tlsld@l"},
{PPC::S_GOT_TLSLD_PCREL, "got@tlsld@pcrel"},
{PPC::S_GOT_TPREL, "got@tprel"},
{PPC::S_GOT_TPREL_HA, "got@tprel@ha"},
{PPC::S_GOT_TPREL_HI, "got@tprel@h"},
{PPC::S_GOT_TPREL_LO, "got@tprel@l"},
{PPC::S_GOT_TPREL_PCREL, "got@tprel@pcrel"},
{PPC::S_LOCAL, "local"},
{PPC::S_NOTOC, "notoc"},
{PPC::S_PCREL_OPT, "<<invalid>>"},
{PPC::S_TLS, "tls"},
{PPC::S_TLS_PCREL, "tls@pcrel"},
{PPC::S_TPREL_HA, "tprel@ha"},
{PPC::S_TPREL_HI, "tprel@h"},
{PPC::S_TPREL_HIGH, "tprel@high"},
{PPC::S_TPREL_HIGHA, "tprel@higha"},
{PPC::S_TPREL_HIGHER, "tprel@higher"},
{PPC::S_TPREL_HIGHERA, "tprel@highera"},
{PPC::S_TPREL_HIGHEST, "tprel@highest"},
{PPC::S_TPREL_HIGHESTA, "tprel@highesta"},
{PPC::S_TPREL_LO, "tprel@l"},
};
const MCAsmInfo::AtSpecifier xcoffAtSpecifiers[] = {
// clang-format off
{PPC::S_AIX_TLSGD, "gd"},
{PPC::S_AIX_TLSGDM, "m"},
{PPC::S_AIX_TLSIE, "ie"},
{PPC::S_AIX_TLSLD, "ld"},
{PPC::S_AIX_TLSLE, "le"},
{PPC::S_AIX_TLSML, "ml"},
{PPC::S_L, "l"},
{PPC::S_U, "u"},
// clang-format on
};
static std::optional<int64_t> evaluateAsInt64(uint16_t specifier,
int64_t Value) {
switch (specifier) {
case PPC::S_LO:
return Value & 0xffff;
case PPC::S_HI:
return (Value >> 16) & 0xffff;
case PPC::S_HA:
return ((Value + 0x8000) >> 16) & 0xffff;
case PPC::S_HIGH:
return (Value >> 16) & 0xffff;
case PPC::S_HIGHA:
return ((Value + 0x8000) >> 16) & 0xffff;
case PPC::S_HIGHER:
return (Value >> 32) & 0xffff;
case PPC::S_HIGHERA:
return ((Value + 0x8000) >> 32) & 0xffff;
case PPC::S_HIGHEST:
return (Value >> 48) & 0xffff;
case PPC::S_HIGHESTA:
return ((Value + 0x8000) >> 48) & 0xffff;
default:
return {};
}
}
bool PPC::evaluateAsConstant(const MCSpecifierExpr &Expr, int64_t &Res) {
MCValue Value;
if (!Expr.getSubExpr()->evaluateAsRelocatable(Value, nullptr))
return false;
if (!Value.isAbsolute())
return false;
auto Tmp = evaluateAsInt64(Expr.getSpecifier(), Value.getConstant());
if (!Tmp)
return false;
Res = *Tmp;
return true;
}
static bool evaluateAsRelocatable(const MCSpecifierExpr &Expr, MCValue &Res,
const MCAssembler *Asm) {
if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
return false;
// The signedness of the result is dependent on the instruction operand. E.g.
// in addis 3,3,65535@l, 65535@l is signed. In the absence of information at
// parse time (!Asm), disable the folding.
std::optional<int64_t> MaybeInt =
evaluateAsInt64(Expr.getSpecifier(), Res.getConstant());
if (Res.isAbsolute() && MaybeInt) {
Res = MCValue::get(*MaybeInt);
} else {
Res.setSpecifier(Expr.getSpecifier());
}
return true;
}
PPCELFMCAsmInfo::PPCELFMCAsmInfo(bool is64Bit, const Triple& T) {
// FIXME: This is not always needed. For example, it is not needed in the
// v2 abi.
NeedsLocalForSize = true;
if (is64Bit) {
CodePointerSize = CalleeSaveStackSlotSize = 8;
}
IsLittleEndian =
T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle;
// ".comm align is in bytes but .align is pow-2."
AlignmentIsInBytes = false;
CommentString = "#";
// Uses '.section' before '.bss' directive
UsesELFSectionDirectiveForBSS = true;
// Debug Information
SupportsDebugInformation = true;
DollarIsPC = true;
AllowDollarAtStartOfIdentifier = false;
// Set up DWARF directives
MinInstAlignment = 4;
// Exceptions handling
ExceptionsType = ExceptionHandling::DwarfCFI;
ZeroDirective = "\t.space\t";
Data64bitsDirective = is64Bit ? "\t.quad\t" : nullptr;
AssemblerDialect = 1; // New-Style mnemonics.
LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
initializeAtSpecifiers(elfAtSpecifiers);
}
void PPCELFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
const MCSpecifierExpr &Expr) const {
printExpr(OS, *Expr.getSubExpr());
OS << '@' << getSpecifierName(Expr.getSpecifier());
}
bool PPCELFMCAsmInfo::evaluateAsRelocatableImpl(const MCSpecifierExpr &Expr,
MCValue &Res,
const MCAssembler *Asm) const {
return evaluateAsRelocatable(Expr, Res, Asm);
}
PPCXCOFFMCAsmInfo::PPCXCOFFMCAsmInfo(bool Is64Bit, const Triple &T) {
if (T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle)
report_fatal_error("XCOFF is not supported for little-endian targets");
CodePointerSize = CalleeSaveStackSlotSize = Is64Bit ? 8 : 4;
// A size of 8 is only supported by the assembler under 64-bit.
Data64bitsDirective = Is64Bit ? "\t.vbyte\t8, " : nullptr;
// Debug Information
SupportsDebugInformation = true;
// Set up DWARF directives
MinInstAlignment = 4;
// Support $ as PC in inline asm
DollarIsPC = true;
AllowDollarAtStartOfIdentifier = false;
UsesSetToEquateSymbol = true;
initializeAtSpecifiers(xcoffAtSpecifiers);
}
void PPCXCOFFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
const MCSpecifierExpr &Expr) const {
printExpr(OS, *Expr.getSubExpr());
OS << '@' << getSpecifierName(Expr.getSpecifier());
}
bool PPCXCOFFMCAsmInfo::evaluateAsRelocatableImpl(
const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
return evaluateAsRelocatable(Expr, Res, Asm);
}
|