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