LLVM 19.0.0git
MCExpr.cpp
Go to the documentation of this file.
1//===- MCExpr.cpp - Assembly Level Expression Implementation --------------===//
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#include "llvm/MC/MCExpr.h"
10#include "llvm/ADT/Statistic.h"
12#include "llvm/Config/llvm-config.h"
14#include "llvm/MC/MCAsmInfo.h"
15#include "llvm/MC/MCAsmLayout.h"
16#include "llvm/MC/MCAssembler.h"
17#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCSymbol.h"
20#include "llvm/MC/MCValue.h"
23#include "llvm/Support/Debug.h"
26#include <cassert>
27#include <cstdint>
28
29using namespace llvm;
30
31#define DEBUG_TYPE "mcexpr"
32
33namespace {
34namespace stats {
35
36STATISTIC(MCExprEvaluate, "Number of MCExpr evaluations");
37
38} // end namespace stats
39} // end anonymous namespace
40
41void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
42 switch (getKind()) {
43 case MCExpr::Target:
44 return cast<MCTargetExpr>(this)->printImpl(OS, MAI);
45 case MCExpr::Constant: {
46 auto Value = cast<MCConstantExpr>(*this).getValue();
47 auto PrintInHex = cast<MCConstantExpr>(*this).useHexFormat();
48 auto SizeInBytes = cast<MCConstantExpr>(*this).getSizeInBytes();
49 if (Value < 0 && MAI && !MAI->supportsSignedData())
50 PrintInHex = true;
51 if (PrintInHex)
52 switch (SizeInBytes) {
53 default:
54 OS << "0x" << Twine::utohexstr(Value);
55 break;
56 case 1:
57 OS << format("0x%02" PRIx64, Value);
58 break;
59 case 2:
60 OS << format("0x%04" PRIx64, Value);
61 break;
62 case 4:
63 OS << format("0x%08" PRIx64, Value);
64 break;
65 case 8:
66 OS << format("0x%016" PRIx64, Value);
67 break;
68 }
69 else
70 OS << Value;
71 return;
72 }
73 case MCExpr::SymbolRef: {
74 const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
75 const MCSymbol &Sym = SRE.getSymbol();
76 // Parenthesize names that start with $ so that they don't look like
77 // absolute names.
78 bool UseParens = MAI && MAI->useParensForDollarSignNames() && !InParens &&
79 Sym.getName().starts_with('$');
80
81 if (UseParens) {
82 OS << '(';
83 Sym.print(OS, MAI);
84 OS << ')';
85 } else
86 Sym.print(OS, MAI);
87
88 const MCSymbolRefExpr::VariantKind Kind = SRE.getKind();
89 if (Kind != MCSymbolRefExpr::VK_None) {
90 if (MAI && MAI->useParensForSymbolVariant()) // ARM
91 OS << '(' << MCSymbolRefExpr::getVariantKindName(Kind) << ')';
92 else
94 }
95
96 return;
97 }
98
99 case MCExpr::Unary: {
100 const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this);
101 switch (UE.getOpcode()) {
102 case MCUnaryExpr::LNot: OS << '!'; break;
103 case MCUnaryExpr::Minus: OS << '-'; break;
104 case MCUnaryExpr::Not: OS << '~'; break;
105 case MCUnaryExpr::Plus: OS << '+'; break;
106 }
107 bool Binary = UE.getSubExpr()->getKind() == MCExpr::Binary;
108 if (Binary) OS << "(";
109 UE.getSubExpr()->print(OS, MAI);
110 if (Binary) OS << ")";
111 return;
112 }
113
114 case MCExpr::Binary: {
115 const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this);
116
117 // Only print parens around the LHS if it is non-trivial.
118 if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) {
119 BE.getLHS()->print(OS, MAI);
120 } else {
121 OS << '(';
122 BE.getLHS()->print(OS, MAI);
123 OS << ')';
124 }
125
126 switch (BE.getOpcode()) {
128 // Print "X-42" instead of "X+-42".
129 if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) {
130 if (RHSC->getValue() < 0) {
131 OS << RHSC->getValue();
132 return;
133 }
134 }
135
136 OS << '+';
137 break;
138 case MCBinaryExpr::AShr: OS << ">>"; break;
139 case MCBinaryExpr::And: OS << '&'; break;
140 case MCBinaryExpr::Div: OS << '/'; break;
141 case MCBinaryExpr::EQ: OS << "=="; break;
142 case MCBinaryExpr::GT: OS << '>'; break;
143 case MCBinaryExpr::GTE: OS << ">="; break;
144 case MCBinaryExpr::LAnd: OS << "&&"; break;
145 case MCBinaryExpr::LOr: OS << "||"; break;
146 case MCBinaryExpr::LShr: OS << ">>"; break;
147 case MCBinaryExpr::LT: OS << '<'; break;
148 case MCBinaryExpr::LTE: OS << "<="; break;
149 case MCBinaryExpr::Mod: OS << '%'; break;
150 case MCBinaryExpr::Mul: OS << '*'; break;
151 case MCBinaryExpr::NE: OS << "!="; break;
152 case MCBinaryExpr::Or: OS << '|'; break;
153 case MCBinaryExpr::OrNot: OS << '!'; break;
154 case MCBinaryExpr::Shl: OS << "<<"; break;
155 case MCBinaryExpr::Sub: OS << '-'; break;
156 case MCBinaryExpr::Xor: OS << '^'; break;
157 }
158
159 // Only print parens around the LHS if it is non-trivial.
160 if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {
161 BE.getRHS()->print(OS, MAI);
162 } else {
163 OS << '(';
164 BE.getRHS()->print(OS, MAI);
165 OS << ')';
166 }
167 return;
168 }
169 }
170
171 llvm_unreachable("Invalid expression kind!");
172}
173
174#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
176 dbgs() << *this;
177 dbgs() << '\n';
178}
179#endif
180
181/* *** */
182
184 const MCExpr *RHS, MCContext &Ctx,
185 SMLoc Loc) {
186 return new (Ctx) MCBinaryExpr(Opc, LHS, RHS, Loc);
187}
188
190 MCContext &Ctx, SMLoc Loc) {
191 return new (Ctx) MCUnaryExpr(Opc, Expr, Loc);
192}
193
195 bool PrintInHex,
196 unsigned SizeInBytes) {
197 return new (Ctx) MCConstantExpr(Value, PrintInHex, SizeInBytes);
198}
199
200/* *** */
201
202MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind,
203 const MCAsmInfo *MAI, SMLoc Loc)
204 : MCExpr(MCExpr::SymbolRef, Loc,
205 encodeSubclassData(Kind, MAI->hasSubsectionsViaSymbols())),
206 Symbol(Symbol) {
207 assert(Symbol);
208}
209
211 VariantKind Kind,
212 MCContext &Ctx, SMLoc Loc) {
213 return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo(), Loc);
214}
215
217 MCContext &Ctx) {
218 return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
219}
220
222 switch (Kind) {
223 // clang-format off
224 case VK_Invalid: return "<<invalid>>";
225 case VK_None: return "<<none>>";
226
227 case VK_DTPOFF: return "DTPOFF";
228 case VK_DTPREL: return "DTPREL";
229 case VK_GOT: return "GOT";
230 case VK_GOTOFF: return "GOTOFF";
231 case VK_GOTREL: return "GOTREL";
232 case VK_PCREL: return "PCREL";
233 case VK_GOTPCREL: return "GOTPCREL";
234 case VK_GOTPCREL_NORELAX: return "GOTPCREL_NORELAX";
235 case VK_GOTTPOFF: return "GOTTPOFF";
236 case VK_GOTTPOFF_FDPIC: return "gottpoff_fdpic";
237 case VK_INDNTPOFF: return "INDNTPOFF";
238 case VK_NTPOFF: return "NTPOFF";
239 case VK_GOTNTPOFF: return "GOTNTPOFF";
240 case VK_PLT: return "PLT";
241 case VK_TLSGD: return "TLSGD";
242 case VK_TLSGD_FDPIC: return "tlsgd_fdpic";
243 case VK_TLSLD: return "TLSLD";
244 case VK_TLSLDM: return "TLSLDM";
245 case VK_TLSLDM_FDPIC: return "tlsldm_fdpic";
246 case VK_TPOFF: return "TPOFF";
247 case VK_TPREL: return "TPREL";
248 case VK_TLSCALL: return "tlscall";
249 case VK_TLSDESC: return "tlsdesc";
250 case VK_TLVP: return "TLVP";
251 case VK_TLVPPAGE: return "TLVPPAGE";
252 case VK_TLVPPAGEOFF: return "TLVPPAGEOFF";
253 case VK_PAGE: return "PAGE";
254 case VK_PAGEOFF: return "PAGEOFF";
255 case VK_GOTPAGE: return "GOTPAGE";
256 case VK_GOTPAGEOFF: return "GOTPAGEOFF";
257 case VK_SECREL: return "SECREL32";
258 case VK_SIZE: return "SIZE";
259 case VK_WEAKREF: return "WEAKREF";
260 case VK_FUNCDESC: return "FUNCDESC";
261 case VK_GOTFUNCDESC: return "GOTFUNCDESC";
262 case VK_GOTOFFFUNCDESC: return "GOTOFFFUNCDESC";
263 case VK_X86_ABS8: return "ABS8";
264 case VK_X86_PLTOFF: return "PLTOFF";
265 case VK_ARM_NONE: return "none";
266 case VK_ARM_GOT_PREL: return "GOT_PREL";
267 case VK_ARM_TARGET1: return "target1";
268 case VK_ARM_TARGET2: return "target2";
269 case VK_ARM_PREL31: return "prel31";
270 case VK_ARM_SBREL: return "sbrel";
271 case VK_ARM_TLSLDO: return "tlsldo";
272 case VK_ARM_TLSDESCSEQ: return "tlsdescseq";
273 case VK_AVR_NONE: return "none";
274 case VK_AVR_LO8: return "lo8";
275 case VK_AVR_HI8: return "hi8";
276 case VK_AVR_HLO8: return "hlo8";
277 case VK_AVR_DIFF8: return "diff8";
278 case VK_AVR_DIFF16: return "diff16";
279 case VK_AVR_DIFF32: return "diff32";
280 case VK_AVR_PM: return "pm";
281 case VK_PPC_LO: return "l";
282 case VK_PPC_HI: return "h";
283 case VK_PPC_HA: return "ha";
284 case VK_PPC_HIGH: return "high";
285 case VK_PPC_HIGHA: return "higha";
286 case VK_PPC_HIGHER: return "higher";
287 case VK_PPC_HIGHERA: return "highera";
288 case VK_PPC_HIGHEST: return "highest";
289 case VK_PPC_HIGHESTA: return "highesta";
290 case VK_PPC_GOT_LO: return "got@l";
291 case VK_PPC_GOT_HI: return "got@h";
292 case VK_PPC_GOT_HA: return "got@ha";
293 case VK_PPC_TOCBASE: return "tocbase";
294 case VK_PPC_TOC: return "toc";
295 case VK_PPC_TOC_LO: return "toc@l";
296 case VK_PPC_TOC_HI: return "toc@h";
297 case VK_PPC_TOC_HA: return "toc@ha";
298 case VK_PPC_U: return "u";
299 case VK_PPC_L: return "l";
300 case VK_PPC_DTPMOD: return "dtpmod";
301 case VK_PPC_TPREL_LO: return "tprel@l";
302 case VK_PPC_TPREL_HI: return "tprel@h";
303 case VK_PPC_TPREL_HA: return "tprel@ha";
304 case VK_PPC_TPREL_HIGH: return "tprel@high";
305 case VK_PPC_TPREL_HIGHA: return "tprel@higha";
306 case VK_PPC_TPREL_HIGHER: return "tprel@higher";
307 case VK_PPC_TPREL_HIGHERA: return "tprel@highera";
308 case VK_PPC_TPREL_HIGHEST: return "tprel@highest";
309 case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta";
310 case VK_PPC_DTPREL_LO: return "dtprel@l";
311 case VK_PPC_DTPREL_HI: return "dtprel@h";
312 case VK_PPC_DTPREL_HA: return "dtprel@ha";
313 case VK_PPC_DTPREL_HIGH: return "dtprel@high";
314 case VK_PPC_DTPREL_HIGHA: return "dtprel@higha";
315 case VK_PPC_DTPREL_HIGHER: return "dtprel@higher";
316 case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera";
317 case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest";
318 case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta";
319 case VK_PPC_GOT_TPREL: return "got@tprel";
320 case VK_PPC_GOT_TPREL_LO: return "got@tprel@l";
321 case VK_PPC_GOT_TPREL_HI: return "got@tprel@h";
322 case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha";
323 case VK_PPC_GOT_DTPREL: return "got@dtprel";
324 case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l";
325 case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h";
326 case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha";
327 case VK_PPC_TLS: return "tls";
328 case VK_PPC_GOT_TLSGD: return "got@tlsgd";
329 case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l";
330 case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h";
331 case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha";
332 case VK_PPC_TLSGD: return "tlsgd";
333 case VK_PPC_AIX_TLSGD:
334 return "gd";
336 return "m";
337 case VK_PPC_AIX_TLSIE:
338 return "ie";
339 case VK_PPC_AIX_TLSLE:
340 return "le";
341 case VK_PPC_AIX_TLSLD:
342 return "ld";
343 case VK_PPC_AIX_TLSML:
344 return "ml";
345 case VK_PPC_GOT_TLSLD: return "got@tlsld";
346 case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l";
347 case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h";
348 case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha";
349 case VK_PPC_GOT_PCREL:
350 return "got@pcrel";
352 return "got@tlsgd@pcrel";
354 return "got@tlsld@pcrel";
356 return "got@tprel@pcrel";
357 case VK_PPC_TLS_PCREL:
358 return "tls@pcrel";
359 case VK_PPC_TLSLD: return "tlsld";
360 case VK_PPC_LOCAL: return "local";
361 case VK_PPC_NOTOC: return "notoc";
362 case VK_PPC_PCREL_OPT: return "<<invalid>>";
363 case VK_COFF_IMGREL32: return "IMGREL";
364 case VK_Hexagon_LO16: return "LO16";
365 case VK_Hexagon_HI16: return "HI16";
366 case VK_Hexagon_GPREL: return "GPREL";
367 case VK_Hexagon_GD_GOT: return "GDGOT";
368 case VK_Hexagon_LD_GOT: return "LDGOT";
369 case VK_Hexagon_GD_PLT: return "GDPLT";
370 case VK_Hexagon_LD_PLT: return "LDPLT";
371 case VK_Hexagon_IE: return "IE";
372 case VK_Hexagon_IE_GOT: return "IEGOT";
373 case VK_WASM_TYPEINDEX: return "TYPEINDEX";
374 case VK_WASM_MBREL: return "MBREL";
375 case VK_WASM_TLSREL: return "TLSREL";
376 case VK_WASM_TBREL: return "TBREL";
377 case VK_WASM_GOT_TLS: return "GOT@TLS";
378 case VK_WASM_FUNCINDEX: return "FUNCINDEX";
379 case VK_AMDGPU_GOTPCREL32_LO: return "gotpcrel32@lo";
380 case VK_AMDGPU_GOTPCREL32_HI: return "gotpcrel32@hi";
381 case VK_AMDGPU_REL32_LO: return "rel32@lo";
382 case VK_AMDGPU_REL32_HI: return "rel32@hi";
383 case VK_AMDGPU_REL64: return "rel64";
384 case VK_AMDGPU_ABS32_LO: return "abs32@lo";
385 case VK_AMDGPU_ABS32_HI: return "abs32@hi";
386 case VK_VE_HI32: return "hi";
387 case VK_VE_LO32: return "lo";
388 case VK_VE_PC_HI32: return "pc_hi";
389 case VK_VE_PC_LO32: return "pc_lo";
390 case VK_VE_GOT_HI32: return "got_hi";
391 case VK_VE_GOT_LO32: return "got_lo";
392 case VK_VE_GOTOFF_HI32: return "gotoff_hi";
393 case VK_VE_GOTOFF_LO32: return "gotoff_lo";
394 case VK_VE_PLT_HI32: return "plt_hi";
395 case VK_VE_PLT_LO32: return "plt_lo";
396 case VK_VE_TLS_GD_HI32: return "tls_gd_hi";
397 case VK_VE_TLS_GD_LO32: return "tls_gd_lo";
398 case VK_VE_TPOFF_HI32: return "tpoff_hi";
399 case VK_VE_TPOFF_LO32: return "tpoff_lo";
400 // clang-format on
401 }
402 llvm_unreachable("Invalid variant kind");
403}
404
407 return StringSwitch<VariantKind>(Name.lower())
408 .Case("dtprel", VK_DTPREL)
409 .Case("dtpoff", VK_DTPOFF)
410 .Case("got", VK_GOT)
411 .Case("gotoff", VK_GOTOFF)
412 .Case("gotrel", VK_GOTREL)
413 .Case("pcrel", VK_PCREL)
414 .Case("gotpcrel", VK_GOTPCREL)
415 .Case("gotpcrel_norelax", VK_GOTPCREL_NORELAX)
416 .Case("gottpoff", VK_GOTTPOFF)
417 .Case("indntpoff", VK_INDNTPOFF)
418 .Case("ntpoff", VK_NTPOFF)
419 .Case("gotntpoff", VK_GOTNTPOFF)
420 .Case("plt", VK_PLT)
421 .Case("tlscall", VK_TLSCALL)
422 .Case("tlsdesc", VK_TLSDESC)
423 .Case("tlsgd", VK_TLSGD)
424 .Case("tlsld", VK_TLSLD)
425 .Case("tlsldm", VK_TLSLDM)
426 .Case("tpoff", VK_TPOFF)
427 .Case("tprel", VK_TPREL)
428 .Case("tlvp", VK_TLVP)
429 .Case("tlvppage", VK_TLVPPAGE)
430 .Case("tlvppageoff", VK_TLVPPAGEOFF)
431 .Case("page", VK_PAGE)
432 .Case("pageoff", VK_PAGEOFF)
433 .Case("gotpage", VK_GOTPAGE)
434 .Case("gotpageoff", VK_GOTPAGEOFF)
435 .Case("imgrel", VK_COFF_IMGREL32)
436 .Case("secrel32", VK_SECREL)
437 .Case("size", VK_SIZE)
438 .Case("abs8", VK_X86_ABS8)
439 .Case("pltoff", VK_X86_PLTOFF)
440 .Case("l", VK_PPC_LO)
441 .Case("h", VK_PPC_HI)
442 .Case("ha", VK_PPC_HA)
443 .Case("high", VK_PPC_HIGH)
444 .Case("higha", VK_PPC_HIGHA)
445 .Case("higher", VK_PPC_HIGHER)
446 .Case("highera", VK_PPC_HIGHERA)
447 .Case("highest", VK_PPC_HIGHEST)
448 .Case("highesta", VK_PPC_HIGHESTA)
449 .Case("got@l", VK_PPC_GOT_LO)
450 .Case("got@h", VK_PPC_GOT_HI)
451 .Case("got@ha", VK_PPC_GOT_HA)
452 .Case("local", VK_PPC_LOCAL)
453 .Case("tocbase", VK_PPC_TOCBASE)
454 .Case("toc", VK_PPC_TOC)
455 .Case("toc@l", VK_PPC_TOC_LO)
456 .Case("toc@h", VK_PPC_TOC_HI)
457 .Case("toc@ha", VK_PPC_TOC_HA)
458 .Case("u", VK_PPC_U)
459 .Case("l", VK_PPC_L)
460 .Case("tls", VK_PPC_TLS)
461 .Case("dtpmod", VK_PPC_DTPMOD)
462 .Case("tprel@l", VK_PPC_TPREL_LO)
463 .Case("tprel@h", VK_PPC_TPREL_HI)
464 .Case("tprel@ha", VK_PPC_TPREL_HA)
465 .Case("tprel@high", VK_PPC_TPREL_HIGH)
466 .Case("tprel@higha", VK_PPC_TPREL_HIGHA)
467 .Case("tprel@higher", VK_PPC_TPREL_HIGHER)
468 .Case("tprel@highera", VK_PPC_TPREL_HIGHERA)
469 .Case("tprel@highest", VK_PPC_TPREL_HIGHEST)
470 .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA)
471 .Case("dtprel@l", VK_PPC_DTPREL_LO)
472 .Case("dtprel@h", VK_PPC_DTPREL_HI)
473 .Case("dtprel@ha", VK_PPC_DTPREL_HA)
474 .Case("dtprel@high", VK_PPC_DTPREL_HIGH)
475 .Case("dtprel@higha", VK_PPC_DTPREL_HIGHA)
476 .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER)
477 .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA)
478 .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST)
479 .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA)
480 .Case("got@tprel", VK_PPC_GOT_TPREL)
481 .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO)
482 .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI)
483 .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA)
484 .Case("got@dtprel", VK_PPC_GOT_DTPREL)
485 .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO)
486 .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI)
487 .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA)
488 .Case("got@tlsgd", VK_PPC_GOT_TLSGD)
489 .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO)
490 .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI)
491 .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
492 .Case("got@tlsld", VK_PPC_GOT_TLSLD)
493 .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO)
494 .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI)
495 .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA)
496 .Case("got@pcrel", VK_PPC_GOT_PCREL)
497 .Case("got@tlsgd@pcrel", VK_PPC_GOT_TLSGD_PCREL)
498 .Case("got@tlsld@pcrel", VK_PPC_GOT_TLSLD_PCREL)
499 .Case("got@tprel@pcrel", VK_PPC_GOT_TPREL_PCREL)
500 .Case("tls@pcrel", VK_PPC_TLS_PCREL)
501 .Case("notoc", VK_PPC_NOTOC)
502 .Case("gdgot", VK_Hexagon_GD_GOT)
503 .Case("gdplt", VK_Hexagon_GD_PLT)
504 .Case("iegot", VK_Hexagon_IE_GOT)
505 .Case("ie", VK_Hexagon_IE)
506 .Case("ldgot", VK_Hexagon_LD_GOT)
507 .Case("ldplt", VK_Hexagon_LD_PLT)
508 .Case("lo8", VK_AVR_LO8)
509 .Case("hi8", VK_AVR_HI8)
510 .Case("hlo8", VK_AVR_HLO8)
511 .Case("typeindex", VK_WASM_TYPEINDEX)
512 .Case("tbrel", VK_WASM_TBREL)
513 .Case("mbrel", VK_WASM_MBREL)
514 .Case("tlsrel", VK_WASM_TLSREL)
515 .Case("got@tls", VK_WASM_GOT_TLS)
516 .Case("funcindex", VK_WASM_FUNCINDEX)
517 .Case("gotpcrel32@lo", VK_AMDGPU_GOTPCREL32_LO)
518 .Case("gotpcrel32@hi", VK_AMDGPU_GOTPCREL32_HI)
519 .Case("rel32@lo", VK_AMDGPU_REL32_LO)
520 .Case("rel32@hi", VK_AMDGPU_REL32_HI)
521 .Case("rel64", VK_AMDGPU_REL64)
522 .Case("abs32@lo", VK_AMDGPU_ABS32_LO)
523 .Case("abs32@hi", VK_AMDGPU_ABS32_HI)
524 .Case("hi", VK_VE_HI32)
525 .Case("lo", VK_VE_LO32)
526 .Case("pc_hi", VK_VE_PC_HI32)
527 .Case("pc_lo", VK_VE_PC_LO32)
528 .Case("got_hi", VK_VE_GOT_HI32)
529 .Case("got_lo", VK_VE_GOT_LO32)
530 .Case("gotoff_hi", VK_VE_GOTOFF_HI32)
531 .Case("gotoff_lo", VK_VE_GOTOFF_LO32)
532 .Case("plt_hi", VK_VE_PLT_HI32)
533 .Case("plt_lo", VK_VE_PLT_LO32)
534 .Case("tls_gd_hi", VK_VE_TLS_GD_HI32)
535 .Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
536 .Case("tpoff_hi", VK_VE_TPOFF_HI32)
537 .Case("tpoff_lo", VK_VE_TPOFF_LO32)
539}
540
541/* *** */
542
543void MCTargetExpr::anchor() {}
544
545/* *** */
546
547bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
548 return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr, false);
549}
550
551bool MCExpr::evaluateAsAbsolute(int64_t &Res,
552 const MCAsmLayout &Layout) const {
553 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, false);
554}
555
556bool MCExpr::evaluateAsAbsolute(int64_t &Res,
557 const MCAsmLayout &Layout,
558 const SectionAddrMap &Addrs) const {
559 // Setting InSet causes us to absolutize differences across sections and that
560 // is what the MachO writer uses Addrs for.
561 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs, true);
562}
563
564bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
565 return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr, false);
566}
567
568bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
569 return evaluateAsAbsolute(Res, Asm, nullptr, nullptr, false);
570}
571
573 const MCAsmLayout &Layout) const {
574 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr,
575 true);
576}
577
578bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
579 const MCAsmLayout *Layout,
580 const SectionAddrMap *Addrs, bool InSet) const {
582
583 // Fast path constants.
584 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) {
585 Res = CE->getValue();
586 return true;
587 }
588
589 bool IsRelocatable =
590 evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
591
592 // Record the current value.
593 Res = Value.getConstant();
594
595 return IsRelocatable && Value.isAbsolute();
596}
597
598/// Helper method for \see EvaluateSymbolAdd().
600 const MCAssembler *Asm, const MCAsmLayout *Layout,
601 const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A,
602 const MCSymbolRefExpr *&B, int64_t &Addend) {
603 if (!A || !B)
604 return;
605
606 const MCSymbol &SA = A->getSymbol();
607 const MCSymbol &SB = B->getSymbol();
608
609 if (SA.isUndefined() || SB.isUndefined())
610 return;
611
612 if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
613 return;
614
615 auto FinalizeFolding = [&]() {
616 // Pointers to Thumb symbols need to have their low-bit set to allow
617 // for interworking.
618 if (Asm->isThumbFunc(&SA))
619 Addend |= 1;
620
621 // Clear the symbol expr pointers to indicate we have folded these
622 // operands.
623 A = B = nullptr;
624 };
625
626 const MCFragment *FA = SA.getFragment();
627 const MCFragment *FB = SB.getFragment();
628 const MCSection &SecA = *FA->getParent();
629 const MCSection &SecB = *FB->getParent();
630 if ((&SecA != &SecB) && !Addrs)
631 return;
632
633 // When layout is available, we can generally compute the difference using the
634 // getSymbolOffset path, which also avoids the possible slow fragment walk.
635 // However, linker relaxation may cause incorrect fold of A-B if A and B are
636 // separated by a linker-relaxable instruction. If the section contains
637 // instructions and InSet is false (not expressions in directive like
638 // .size/.fill), disable the fast path.
639 if (Layout && (InSet || !SecA.hasInstructions() ||
640 !(Asm->getContext().getTargetTriple().isRISCV() ||
641 Asm->getContext().getTargetTriple().isLoongArch()))) {
642 // If both symbols are in the same fragment, return the difference of their
643 // offsets. canGetFragmentOffset(FA) may be false.
644 if (FA == FB && !SA.isVariable() && !SB.isVariable()) {
645 Addend += SA.getOffset() - SB.getOffset();
646 return FinalizeFolding();
647 }
648
649 // Eagerly evaluate when layout is finalized.
650 Addend += Layout->getSymbolOffset(A->getSymbol()) -
651 Layout->getSymbolOffset(B->getSymbol());
652 if (Addrs && (&SecA != &SecB))
653 Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
654
655 FinalizeFolding();
656 } else {
657 // When layout is not finalized, our ability to resolve differences between
658 // symbols is limited to specific cases where the fragments between two
659 // symbols (including the fragments the symbols are defined in) are
660 // fixed-size fragments so the difference can be calculated. For example,
661 // this is important when the Subtarget is changed and a new MCDataFragment
662 // is created in the case of foo: instr; .arch_extension ext; instr .if . -
663 // foo.
664 if (SA.isVariable() || SB.isVariable())
665 return;
666
667 // Try to find a constant displacement from FA to FB, add the displacement
668 // between the offset in FA of SA and the offset in FB of SB.
669 bool Reverse = false;
670 if (FA == FB)
671 Reverse = SA.getOffset() < SB.getOffset();
672 else
673 Reverse = FA->getLayoutOrder() < FB->getLayoutOrder();
674
675 uint64_t SAOffset = SA.getOffset(), SBOffset = SB.getOffset();
676 int64_t Displacement = SA.getOffset() - SB.getOffset();
677 if (Reverse) {
678 std::swap(FA, FB);
679 std::swap(SAOffset, SBOffset);
680 Displacement *= -1;
681 }
682
683 // Track whether B is before a relaxable instruction and whether A is after
684 // a relaxable instruction. If SA and SB are separated by a linker-relaxable
685 // instruction, the difference cannot be resolved as it may be changed by
686 // the linker.
687 bool BBeforeRelax = false, AAfterRelax = false;
688 for (auto FI = FB; FI; FI = FI->getNext()) {
689 auto DF = dyn_cast<MCDataFragment>(FI);
690 if (DF && DF->isLinkerRelaxable()) {
691 if (&*FI != FB || SBOffset != DF->getContents().size())
692 BBeforeRelax = true;
693 if (&*FI != FA || SAOffset == DF->getContents().size())
694 AAfterRelax = true;
695 if (BBeforeRelax && AAfterRelax)
696 return;
697 }
698 if (&*FI == FA) {
699 // If FA and FB belong to the same subsection, the loop will find FA and
700 // we can resolve the difference.
701 Addend += Reverse ? -Displacement : Displacement;
702 FinalizeFolding();
703 return;
704 }
705
706 int64_t Num;
707 unsigned Count;
708 if (DF) {
709 Displacement += DF->getContents().size();
710 } else if (auto *AF = dyn_cast<MCAlignFragment>(FI);
711 AF && Layout && AF->hasEmitNops() &&
712 !Asm->getBackend().shouldInsertExtraNopBytesForCodeAlign(
713 *AF, Count)) {
714 Displacement += Asm->computeFragmentSize(*Layout, *AF);
715 } else if (auto *FF = dyn_cast<MCFillFragment>(FI);
716 FF && FF->getNumValues().evaluateAsAbsolute(Num)) {
717 Displacement += Num * FF->getValueSize();
718 } else {
719 return;
720 }
721 }
722 }
723}
724
725/// Evaluate the result of an add between (conceptually) two MCValues.
726///
727/// This routine conceptually attempts to construct an MCValue:
728/// Result = (Result_A - Result_B + Result_Cst)
729/// from two MCValue's LHS and RHS where
730/// Result = LHS + RHS
731/// and
732/// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
733///
734/// This routine attempts to aggressively fold the operands such that the result
735/// is representable in an MCValue, but may not always succeed.
736///
737/// \returns True on success, false if the result is not representable in an
738/// MCValue.
739
740/// NOTE: It is really important to have both the Asm and Layout arguments.
741/// They might look redundant, but this function can be used before layout
742/// is done (see the object streamer for example) and having the Asm argument
743/// lets us avoid relaxations early.
744static bool EvaluateSymbolicAdd(const MCAssembler *Asm,
745 const MCAsmLayout *Layout,
746 const SectionAddrMap *Addrs, bool InSet,
747 const MCValue &LHS, const MCValue &RHS,
748 MCValue &Res) {
749 // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
750 // about dealing with modifiers. This will ultimately bite us, one day.
751 const MCSymbolRefExpr *LHS_A = LHS.getSymA();
752 const MCSymbolRefExpr *LHS_B = LHS.getSymB();
753 int64_t LHS_Cst = LHS.getConstant();
754
755 const MCSymbolRefExpr *RHS_A = RHS.getSymA();
756 const MCSymbolRefExpr *RHS_B = RHS.getSymB();
757 int64_t RHS_Cst = RHS.getConstant();
758
759 if (LHS.getRefKind() != RHS.getRefKind())
760 return false;
761
762 // Fold the result constant immediately.
763 int64_t Result_Cst = LHS_Cst + RHS_Cst;
764
765 assert((!Layout || Asm) &&
766 "Must have an assembler object if layout is given!");
767
768 // If we have a layout, we can fold resolved differences.
769 if (Asm) {
770 // First, fold out any differences which are fully resolved. By
771 // reassociating terms in
772 // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
773 // we have the four possible differences:
774 // (LHS_A - LHS_B),
775 // (LHS_A - RHS_B),
776 // (RHS_A - LHS_B),
777 // (RHS_A - RHS_B).
778 // Since we are attempting to be as aggressive as possible about folding, we
779 // attempt to evaluate each possible alternative.
780 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B,
781 Result_Cst);
782 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B,
783 Result_Cst);
784 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B,
785 Result_Cst);
786 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B,
787 Result_Cst);
788 }
789
790 // We can't represent the addition or subtraction of two symbols.
791 if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
792 return false;
793
794 // At this point, we have at most one additive symbol and one subtractive
795 // symbol -- find them.
796 const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
797 const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
798
799 Res = MCValue::get(A, B, Result_Cst);
800 return true;
801}
802
804 const MCAsmLayout *Layout,
805 const MCFixup *Fixup) const {
806 MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr;
807 return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
808 false);
809}
810
811bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
812 MCAssembler *Assembler = &Layout.getAssembler();
813 return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
814 true);
815}
816
817static bool canExpand(const MCSymbol &Sym, bool InSet) {
818 if (Sym.isWeakExternal())
819 return false;
820
821 const MCExpr *Expr = Sym.getVariableValue();
822 const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
823 if (Inner) {
824 if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
825 return false;
826 }
827
828 if (InSet)
829 return true;
830 return !Sym.isInSection();
831}
832
834 const MCAsmLayout *Layout,
835 const MCFixup *Fixup,
836 const SectionAddrMap *Addrs,
837 bool InSet) const {
838 ++stats::MCExprEvaluate;
839
840 switch (getKind()) {
841 case Target:
842 return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout,
843 Fixup);
844
845 case Constant:
846 Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
847 return true;
848
849 case SymbolRef: {
850 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
851 const MCSymbol &Sym = SRE->getSymbol();
852 const auto Kind = SRE->getKind();
853
854 // Evaluate recursively if this is a variable.
855 if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&
856 canExpand(Sym, InSet)) {
857 bool IsMachO = SRE->hasSubsectionsViaSymbols();
858 if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
859 Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
860 if (Kind != MCSymbolRefExpr::VK_None) {
861 if (Res.isAbsolute()) {
862 Res = MCValue::get(SRE, nullptr, 0);
863 return true;
864 }
865 // If the reference has a variant kind, we can only handle expressions
866 // which evaluate exactly to a single unadorned symbol. Attach the
867 // original VariantKind to SymA of the result.
868 if (Res.getRefKind() != MCSymbolRefExpr::VK_None || !Res.getSymA() ||
869 Res.getSymB() || Res.getConstant())
870 return false;
871 Res =
873 Kind, Asm->getContext()),
874 Res.getSymB(), Res.getConstant(), Res.getRefKind());
875 }
876 if (!IsMachO)
877 return true;
878
879 const MCSymbolRefExpr *A = Res.getSymA();
880 const MCSymbolRefExpr *B = Res.getSymB();
881 // FIXME: This is small hack. Given
882 // a = b + 4
883 // .long a
884 // the OS X assembler will completely drop the 4. We should probably
885 // include it in the relocation or produce an error if that is not
886 // possible.
887 // Allow constant expressions.
888 if (!A && !B)
889 return true;
890 // Allows aliases with zero offset.
891 if (Res.getConstant() == 0 && (!A || !B))
892 return true;
893 }
894 }
895
896 Res = MCValue::get(SRE, nullptr, 0);
897 return true;
898 }
899
900 case Unary: {
901 const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
903
904 if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
905 Addrs, InSet))
906 return false;
907
908 switch (AUE->getOpcode()) {
910 if (!Value.isAbsolute())
911 return false;
912 Res = MCValue::get(!Value.getConstant());
913 break;
915 /// -(a - b + const) ==> (b - a - const)
916 if (Value.getSymA() && !Value.getSymB())
917 return false;
918
919 // The cast avoids undefined behavior if the constant is INT64_MIN.
920 Res = MCValue::get(Value.getSymB(), Value.getSymA(),
921 -(uint64_t)Value.getConstant());
922 break;
923 case MCUnaryExpr::Not:
924 if (!Value.isAbsolute())
925 return false;
926 Res = MCValue::get(~Value.getConstant());
927 break;
929 Res = Value;
930 break;
931 }
932
933 return true;
934 }
935
936 case Binary: {
937 const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
938 MCValue LHSValue, RHSValue;
939
940 if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
941 Addrs, InSet) ||
942 !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
943 Addrs, InSet)) {
944 // Check if both are Target Expressions, see if we can compare them.
945 if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS())) {
946 if (const MCTargetExpr *R = dyn_cast<MCTargetExpr>(ABE->getRHS())) {
947 switch (ABE->getOpcode()) {
948 case MCBinaryExpr::EQ:
949 Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
950 return true;
951 case MCBinaryExpr::NE:
952 Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
953 return true;
954 default:
955 break;
956 }
957 }
958 }
959 return false;
960 }
961
962 // We only support a few operations on non-constant expressions, handle
963 // those first.
964 if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
965 switch (ABE->getOpcode()) {
966 default:
967 return false;
969 // Negate RHS and add.
970 // The cast avoids undefined behavior if the constant is INT64_MIN.
971 return EvaluateSymbolicAdd(
972 Asm, Layout, Addrs, InSet, LHSValue,
973 MCValue::get(RHSValue.getSymB(), RHSValue.getSymA(),
974 -(uint64_t)RHSValue.getConstant(),
975 RHSValue.getRefKind()),
976 Res);
977
979 return EvaluateSymbolicAdd(
980 Asm, Layout, Addrs, InSet, LHSValue,
981 MCValue::get(RHSValue.getSymA(), RHSValue.getSymB(),
982 RHSValue.getConstant(), RHSValue.getRefKind()),
983 Res);
984 }
985 }
986
987 // FIXME: We need target hooks for the evaluation. It may be limited in
988 // width, and gas defines the result of comparisons differently from
989 // Apple as.
990 int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
991 int64_t Result = 0;
992 auto Op = ABE->getOpcode();
993 switch (Op) {
994 case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
995 case MCBinaryExpr::Add: Result = LHS + RHS; break;
996 case MCBinaryExpr::And: Result = LHS & RHS; break;
999 // Handle division by zero. gas just emits a warning and keeps going,
1000 // we try to be stricter.
1001 // FIXME: Currently the caller of this function has no way to understand
1002 // we're bailing out because of 'division by zero'. Therefore, it will
1003 // emit a 'expected relocatable expression' error. It would be nice to
1004 // change this code to emit a better diagnostic.
1005 if (RHS == 0)
1006 return false;
1007 if (ABE->getOpcode() == MCBinaryExpr::Div)
1008 Result = LHS / RHS;
1009 else
1010 Result = LHS % RHS;
1011 break;
1012 case MCBinaryExpr::EQ: Result = LHS == RHS; break;
1013 case MCBinaryExpr::GT: Result = LHS > RHS; break;
1014 case MCBinaryExpr::GTE: Result = LHS >= RHS; break;
1015 case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
1016 case MCBinaryExpr::LOr: Result = LHS || RHS; break;
1017 case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break;
1018 case MCBinaryExpr::LT: Result = LHS < RHS; break;
1019 case MCBinaryExpr::LTE: Result = LHS <= RHS; break;
1020 case MCBinaryExpr::Mul: Result = LHS * RHS; break;
1021 case MCBinaryExpr::NE: Result = LHS != RHS; break;
1022 case MCBinaryExpr::Or: Result = LHS | RHS; break;
1023 case MCBinaryExpr::OrNot: Result = LHS | ~RHS; break;
1024 case MCBinaryExpr::Shl: Result = uint64_t(LHS) << uint64_t(RHS); break;
1025 case MCBinaryExpr::Sub: Result = LHS - RHS; break;
1026 case MCBinaryExpr::Xor: Result = LHS ^ RHS; break;
1027 }
1028
1029 switch (Op) {
1030 default:
1031 Res = MCValue::get(Result);
1032 break;
1033 case MCBinaryExpr::EQ:
1034 case MCBinaryExpr::GT:
1035 case MCBinaryExpr::GTE:
1036 case MCBinaryExpr::LT:
1037 case MCBinaryExpr::LTE:
1038 case MCBinaryExpr::NE:
1039 // A comparison operator returns a -1 if true and 0 if false.
1040 Res = MCValue::get(Result ? -1 : 0);
1041 break;
1042 }
1043
1044 return true;
1045 }
1046 }
1047
1048 llvm_unreachable("Invalid assembly expression kind!");
1049}
1050
1052 switch (getKind()) {
1053 case Target:
1054 // We never look through target specific expressions.
1055 return cast<MCTargetExpr>(this)->findAssociatedFragment();
1056
1057 case Constant:
1059
1060 case SymbolRef: {
1061 const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
1062 const MCSymbol &Sym = SRE->getSymbol();
1063 return Sym.getFragment();
1064 }
1065
1066 case Unary:
1067 return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedFragment();
1068
1069 case Binary: {
1070 const MCBinaryExpr *BE = cast<MCBinaryExpr>(this);
1071 MCFragment *LHS_F = BE->getLHS()->findAssociatedFragment();
1072 MCFragment *RHS_F = BE->getRHS()->findAssociatedFragment();
1073
1074 // If either is absolute, return the other.
1076 return RHS_F;
1078 return LHS_F;
1079
1080 // Not always correct, but probably the best we can do without more context.
1081 if (BE->getOpcode() == MCBinaryExpr::Sub)
1083
1084 // Otherwise, return the first non-null fragment.
1085 return LHS_F ? LHS_F : RHS_F;
1086 }
1087 }
1088
1089 llvm_unreachable("Invalid assembly expression kind!");
1090}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:537
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
static bool canExpand(const MCSymbol &Sym, bool InSet)
Definition: MCExpr.cpp:817
static void AttemptToFoldSymbolOffsetDifference(const MCAssembler *Asm, const MCAsmLayout *Layout, const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A, const MCSymbolRefExpr *&B, int64_t &Addend)
Helper method for.
Definition: MCExpr.cpp:599
static bool EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout, const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS, const MCValue &RHS, MCValue &Res)
Evaluate the result of an add between (conceptually) two MCValues.
Definition: MCExpr.cpp:744
PowerPC TLS Dynamic Call Fixup
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Value * RHS
Value * LHS
This class represents an Operation in the Expression.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
bool useParensForSymbolVariant() const
Definition: MCAsmInfo.h:811
bool useParensForDollarSignNames() const
Definition: MCAsmInfo.h:812
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
Definition: MCFragment.cpp:97
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:41
Binary assembler expressions.
Definition: MCExpr.h:492
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:639
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:642
Opcode getOpcode() const
Get the kind of this binary expression.
Definition: MCExpr.h:636
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:183
@ Div
Signed division.
Definition: MCExpr.h:497
@ Shl
Shift left.
Definition: MCExpr.h:514
@ AShr
Arithmetic shift right.
Definition: MCExpr.h:515
@ LShr
Logical shift right.
Definition: MCExpr.h:516
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:501
@ EQ
Equality comparison.
Definition: MCExpr.h:498
@ Sub
Subtraction.
Definition: MCExpr.h:517
@ Mul
Multiplication.
Definition: MCExpr.h:510
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
Definition: MCExpr.h:499
@ Mod
Signed remainder.
Definition: MCExpr.h:509
@ And
Bitwise and.
Definition: MCExpr.h:496
@ Or
Bitwise or.
Definition: MCExpr.h:512
@ Xor
Bitwise exclusive or.
Definition: MCExpr.h:518
@ OrNot
Bitwise or not.
Definition: MCExpr.h:513
@ LAnd
Logical and.
Definition: MCExpr.h:503
@ LOr
Logical or.
Definition: MCExpr.h:504
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:505
@ Add
Addition.
Definition: MCExpr.h:495
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:507
@ NE
Inequality comparison.
Definition: MCExpr.h:511
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:83
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:412
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:212
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
@ Unary
Unary expressions.
Definition: MCExpr.h:41
@ Constant
Constant expressions.
Definition: MCExpr.h:39
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:40
@ Target
Target specific expression.
Definition: MCExpr.h:42
@ Binary
Binary expressions.
Definition: MCExpr.h:38
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
Definition: MCExpr.cpp:572
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:803
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCAsmLayout *Layout, const MCFixup *Fixup, const SectionAddrMap *Addrs, bool InSet) const
Definition: MCExpr.cpp:833
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:41
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:1051
bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.
Definition: MCExpr.cpp:811
void dump() const
Definition: MCExpr.cpp:175
ExprKind getKind() const
Definition: MCExpr.h:81
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
unsigned getLayoutOrder() const
Definition: MCFragment.h:99
MCSection * getParent() const
Definition: MCFragment.h:94
MCFragment * getNext() const
Definition: MCFragment.h:90
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
bool hasInstructions() const
Definition: MCSection.h:184
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
const MCSymbol & getSymbol() const
Definition: MCExpr.h:410
static StringRef getVariantKindName(VariantKind Kind)
Definition: MCExpr.cpp:221
static VariantKind getVariantKindForName(StringRef Name)
Definition: MCExpr.cpp:406
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:397
VariantKind getKind() const
Definition: MCExpr.h:412
bool hasSubsectionsViaSymbols() const
Definition: MCExpr.h:416
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:300
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:259
static MCFragment * AbsolutePseudoFragment
Definition: MCSymbol.h:66
uint64_t getOffset() const
Definition: MCSymbol.h:327
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:397
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:656
Unary assembler expressions.
Definition: MCExpr.h:436
Opcode getOpcode() const
Get the kind of this unary expression.
Definition: MCExpr.h:479
static const MCUnaryExpr * create(Opcode Op, const MCExpr *Expr, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:189
@ Minus
Unary minus.
Definition: MCExpr.h:440
@ Plus
Unary plus.
Definition: MCExpr.h:442
@ Not
Bitwise negation.
Definition: MCExpr.h:441
@ LNot
Logical negation.
Definition: MCExpr.h:439
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Definition: MCExpr.h:482
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
uint32_t getRefKind() const
Definition: MCValue.h:46
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:59
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:45
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:44
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:49
Represents a location in source code.
Definition: SMLoc.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:416
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860