LLVM  14.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"
11 #include "llvm/ADT/StringExtras.h"
12 #include "llvm/ADT/StringSwitch.h"
13 #include "llvm/Config/llvm-config.h"
14 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCAsmInfo.h"
16 #include "llvm/MC/MCAsmLayout.h"
17 #include "llvm/MC/MCAssembler.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCObjectWriter.h"
20 #include "llvm/MC/MCSymbol.h"
21 #include "llvm/MC/MCValue.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/Compiler.h"
24 #include "llvm/Support/Debug.h"
27 #include <cassert>
28 #include <cstdint>
29 
30 using namespace llvm;
31 
32 #define DEBUG_TYPE "mcexpr"
33 
34 namespace {
35 namespace stats {
36 
37 STATISTIC(MCExprEvaluate, "Number of MCExpr evaluations");
38 
39 } // end namespace stats
40 } // end anonymous namespace
41 
42 void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
43  switch (getKind()) {
44  case MCExpr::Target:
45  return cast<MCTargetExpr>(this)->printImpl(OS, MAI);
46  case MCExpr::Constant: {
47  auto Value = cast<MCConstantExpr>(*this).getValue();
48  auto PrintInHex = cast<MCConstantExpr>(*this).useHexFormat();
49  auto SizeInBytes = cast<MCConstantExpr>(*this).getSizeInBytes();
50  if (Value < 0 && MAI && !MAI->supportsSignedData())
51  PrintInHex = true;
52  if (PrintInHex)
53  switch (SizeInBytes) {
54  default:
55  OS << "0x" << Twine::utohexstr(Value);
56  break;
57  case 1:
58  OS << format("0x%02" PRIx64, Value);
59  break;
60  case 2:
61  OS << format("0x%04" PRIx64, Value);
62  break;
63  case 4:
64  OS << format("0x%08" PRIx64, Value);
65  break;
66  case 8:
67  OS << format("0x%016" PRIx64, Value);
68  break;
69  }
70  else
71  OS << Value;
72  return;
73  }
74  case MCExpr::SymbolRef: {
75  const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
76  const MCSymbol &Sym = SRE.getSymbol();
77  // Parenthesize names that start with $ so that they don't look like
78  // absolute names.
79  bool UseParens =
80  !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$';
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
93  OS << '@' << MCSymbolRefExpr::getVariantKindName(Kind);
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()) {
127  case MCBinaryExpr::Add:
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)
175 LLVM_DUMP_METHOD void MCExpr::dump() const {
176  dbgs() << *this;
177  dbgs() << '\n';
178 }
179 #endif
180 
181 /* *** */
182 
183 const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS,
184  const MCExpr *RHS, MCContext &Ctx,
185  SMLoc Loc) {
186  return new (Ctx) MCBinaryExpr(Opc, LHS, RHS, Loc);
187 }
188 
189 const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
190  MCContext &Ctx, SMLoc Loc) {
191  return new (Ctx) MCUnaryExpr(Opc, Expr, Loc);
192 }
193 
194 const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx,
195  bool PrintInHex,
196  unsigned SizeInBytes) {
197  return new (Ctx) MCConstantExpr(Value, PrintInHex, SizeInBytes);
198 }
199 
200 /* *** */
201 
202 MCSymbolRefExpr::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 
210 const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym,
211  VariantKind Kind,
212  MCContext &Ctx, SMLoc Loc) {
213  return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo(), Loc);
214 }
215 
216 const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind,
217  MCContext &Ctx) {
218  return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
219 }
220 
221 StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
222  switch (Kind) {
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_GOTTPOFF: return "GOTTPOFF";
234  case VK_INDNTPOFF: return "INDNTPOFF";
235  case VK_NTPOFF: return "NTPOFF";
236  case VK_GOTNTPOFF: return "GOTNTPOFF";
237  case VK_PLT: return "PLT";
238  case VK_TLSGD: return "TLSGD";
239  case VK_TLSLD: return "TLSLD";
240  case VK_TLSLDM: return "TLSLDM";
241  case VK_TPOFF: return "TPOFF";
242  case VK_TPREL: return "TPREL";
243  case VK_TLSCALL: return "tlscall";
244  case VK_TLSDESC: return "tlsdesc";
245  case VK_TLVP: return "TLVP";
246  case VK_TLVPPAGE: return "TLVPPAGE";
247  case VK_TLVPPAGEOFF: return "TLVPPAGEOFF";
248  case VK_PAGE: return "PAGE";
249  case VK_PAGEOFF: return "PAGEOFF";
250  case VK_GOTPAGE: return "GOTPAGE";
251  case VK_GOTPAGEOFF: return "GOTPAGEOFF";
252  case VK_SECREL: return "SECREL32";
253  case VK_SIZE: return "SIZE";
254  case VK_WEAKREF: return "WEAKREF";
255  case VK_X86_ABS8: return "ABS8";
256  case VK_X86_PLTOFF: return "PLTOFF";
257  case VK_ARM_NONE: return "none";
258  case VK_ARM_GOT_PREL: return "GOT_PREL";
259  case VK_ARM_TARGET1: return "target1";
260  case VK_ARM_TARGET2: return "target2";
261  case VK_ARM_PREL31: return "prel31";
262  case VK_ARM_SBREL: return "sbrel";
263  case VK_ARM_TLSLDO: return "tlsldo";
264  case VK_ARM_TLSDESCSEQ: return "tlsdescseq";
265  case VK_AVR_NONE: return "none";
266  case VK_AVR_LO8: return "lo8";
267  case VK_AVR_HI8: return "hi8";
268  case VK_AVR_HLO8: return "hlo8";
269  case VK_AVR_DIFF8: return "diff8";
270  case VK_AVR_DIFF16: return "diff16";
271  case VK_AVR_DIFF32: return "diff32";
272  case VK_AVR_PM: return "pm";
273  case VK_PPC_LO: return "l";
274  case VK_PPC_HI: return "h";
275  case VK_PPC_HA: return "ha";
276  case VK_PPC_HIGH: return "high";
277  case VK_PPC_HIGHA: return "higha";
278  case VK_PPC_HIGHER: return "higher";
279  case VK_PPC_HIGHERA: return "highera";
280  case VK_PPC_HIGHEST: return "highest";
281  case VK_PPC_HIGHESTA: return "highesta";
282  case VK_PPC_GOT_LO: return "got@l";
283  case VK_PPC_GOT_HI: return "got@h";
284  case VK_PPC_GOT_HA: return "got@ha";
285  case VK_PPC_TOCBASE: return "tocbase";
286  case VK_PPC_TOC: return "toc";
287  case VK_PPC_TOC_LO: return "toc@l";
288  case VK_PPC_TOC_HI: return "toc@h";
289  case VK_PPC_TOC_HA: return "toc@ha";
290  case VK_PPC_U: return "u";
291  case VK_PPC_L: return "l";
292  case VK_PPC_DTPMOD: return "dtpmod";
293  case VK_PPC_TPREL_LO: return "tprel@l";
294  case VK_PPC_TPREL_HI: return "tprel@h";
295  case VK_PPC_TPREL_HA: return "tprel@ha";
296  case VK_PPC_TPREL_HIGH: return "tprel@high";
297  case VK_PPC_TPREL_HIGHA: return "tprel@higha";
298  case VK_PPC_TPREL_HIGHER: return "tprel@higher";
299  case VK_PPC_TPREL_HIGHERA: return "tprel@highera";
300  case VK_PPC_TPREL_HIGHEST: return "tprel@highest";
301  case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta";
302  case VK_PPC_DTPREL_LO: return "dtprel@l";
303  case VK_PPC_DTPREL_HI: return "dtprel@h";
304  case VK_PPC_DTPREL_HA: return "dtprel@ha";
305  case VK_PPC_DTPREL_HIGH: return "dtprel@high";
306  case VK_PPC_DTPREL_HIGHA: return "dtprel@higha";
307  case VK_PPC_DTPREL_HIGHER: return "dtprel@higher";
308  case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera";
309  case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest";
310  case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta";
311  case VK_PPC_GOT_TPREL: return "got@tprel";
312  case VK_PPC_GOT_TPREL_LO: return "got@tprel@l";
313  case VK_PPC_GOT_TPREL_HI: return "got@tprel@h";
314  case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha";
315  case VK_PPC_GOT_DTPREL: return "got@dtprel";
316  case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l";
317  case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h";
318  case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha";
319  case VK_PPC_TLS: return "tls";
320  case VK_PPC_GOT_TLSGD: return "got@tlsgd";
321  case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l";
322  case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h";
323  case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha";
324  case VK_PPC_TLSGD: return "tlsgd";
325  case VK_PPC_AIX_TLSGD:
326  return "gd";
327  case VK_PPC_AIX_TLSGDM:
328  return "m";
329  case VK_PPC_GOT_TLSLD: return "got@tlsld";
330  case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l";
331  case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h";
332  case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha";
333  case VK_PPC_GOT_PCREL:
334  return "got@pcrel";
335  case VK_PPC_GOT_TLSGD_PCREL:
336  return "got@tlsgd@pcrel";
337  case VK_PPC_GOT_TLSLD_PCREL:
338  return "got@tlsld@pcrel";
339  case VK_PPC_GOT_TPREL_PCREL:
340  return "got@tprel@pcrel";
341  case VK_PPC_TLS_PCREL:
342  return "tls@pcrel";
343  case VK_PPC_TLSLD: return "tlsld";
344  case VK_PPC_LOCAL: return "local";
345  case VK_PPC_NOTOC: return "notoc";
346  case VK_PPC_PCREL_OPT: return "<<invalid>>";
347  case VK_COFF_IMGREL32: return "IMGREL";
348  case VK_Hexagon_LO16: return "LO16";
349  case VK_Hexagon_HI16: return "HI16";
350  case VK_Hexagon_GPREL: return "GPREL";
351  case VK_Hexagon_GD_GOT: return "GDGOT";
352  case VK_Hexagon_LD_GOT: return "LDGOT";
353  case VK_Hexagon_GD_PLT: return "GDPLT";
354  case VK_Hexagon_LD_PLT: return "LDPLT";
355  case VK_Hexagon_IE: return "IE";
356  case VK_Hexagon_IE_GOT: return "IEGOT";
357  case VK_WASM_TYPEINDEX: return "TYPEINDEX";
358  case VK_WASM_MBREL: return "MBREL";
359  case VK_WASM_TLSREL: return "TLSREL";
360  case VK_WASM_TBREL: return "TBREL";
361  case VK_WASM_GOT_TLS: return "GOT@TLS";
362  case VK_AMDGPU_GOTPCREL32_LO: return "gotpcrel32@lo";
363  case VK_AMDGPU_GOTPCREL32_HI: return "gotpcrel32@hi";
364  case VK_AMDGPU_REL32_LO: return "rel32@lo";
365  case VK_AMDGPU_REL32_HI: return "rel32@hi";
366  case VK_AMDGPU_REL64: return "rel64";
367  case VK_AMDGPU_ABS32_LO: return "abs32@lo";
368  case VK_AMDGPU_ABS32_HI: return "abs32@hi";
369  case VK_VE_HI32: return "hi";
370  case VK_VE_LO32: return "lo";
371  case VK_VE_PC_HI32: return "pc_hi";
372  case VK_VE_PC_LO32: return "pc_lo";
373  case VK_VE_GOT_HI32: return "got_hi";
374  case VK_VE_GOT_LO32: return "got_lo";
375  case VK_VE_GOTOFF_HI32: return "gotoff_hi";
376  case VK_VE_GOTOFF_LO32: return "gotoff_lo";
377  case VK_VE_PLT_HI32: return "plt_hi";
378  case VK_VE_PLT_LO32: return "plt_lo";
379  case VK_VE_TLS_GD_HI32: return "tls_gd_hi";
380  case VK_VE_TLS_GD_LO32: return "tls_gd_lo";
381  case VK_VE_TPOFF_HI32: return "tpoff_hi";
382  case VK_VE_TPOFF_LO32: return "tpoff_lo";
383  }
384  llvm_unreachable("Invalid variant kind");
385 }
386 
387 MCSymbolRefExpr::VariantKind
388 MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
389  return StringSwitch<VariantKind>(Name.lower())
390  .Case("dtprel", VK_DTPREL)
391  .Case("dtpoff", VK_DTPOFF)
392  .Case("got", VK_GOT)
393  .Case("gotoff", VK_GOTOFF)
394  .Case("gotrel", VK_GOTREL)
395  .Case("pcrel", VK_PCREL)
396  .Case("gotpcrel", VK_GOTPCREL)
397  .Case("gottpoff", VK_GOTTPOFF)
398  .Case("indntpoff", VK_INDNTPOFF)
399  .Case("ntpoff", VK_NTPOFF)
400  .Case("gotntpoff", VK_GOTNTPOFF)
401  .Case("plt", VK_PLT)
402  .Case("tlscall", VK_TLSCALL)
403  .Case("tlsdesc", VK_TLSDESC)
404  .Case("tlsgd", VK_TLSGD)
405  .Case("tlsld", VK_TLSLD)
406  .Case("tlsldm", VK_TLSLDM)
407  .Case("tpoff", VK_TPOFF)
408  .Case("tprel", VK_TPREL)
409  .Case("tlvp", VK_TLVP)
410  .Case("tlvppage", VK_TLVPPAGE)
411  .Case("tlvppageoff", VK_TLVPPAGEOFF)
412  .Case("page", VK_PAGE)
413  .Case("pageoff", VK_PAGEOFF)
414  .Case("gotpage", VK_GOTPAGE)
415  .Case("gotpageoff", VK_GOTPAGEOFF)
416  .Case("imgrel", VK_COFF_IMGREL32)
417  .Case("secrel32", VK_SECREL)
418  .Case("size", VK_SIZE)
419  .Case("abs8", VK_X86_ABS8)
420  .Case("pltoff", VK_X86_PLTOFF)
421  .Case("l", VK_PPC_LO)
422  .Case("h", VK_PPC_HI)
423  .Case("ha", VK_PPC_HA)
424  .Case("high", VK_PPC_HIGH)
425  .Case("higha", VK_PPC_HIGHA)
426  .Case("higher", VK_PPC_HIGHER)
427  .Case("highera", VK_PPC_HIGHERA)
428  .Case("highest", VK_PPC_HIGHEST)
429  .Case("highesta", VK_PPC_HIGHESTA)
430  .Case("got@l", VK_PPC_GOT_LO)
431  .Case("got@h", VK_PPC_GOT_HI)
432  .Case("got@ha", VK_PPC_GOT_HA)
433  .Case("local", VK_PPC_LOCAL)
434  .Case("tocbase", VK_PPC_TOCBASE)
435  .Case("toc", VK_PPC_TOC)
436  .Case("toc@l", VK_PPC_TOC_LO)
437  .Case("toc@h", VK_PPC_TOC_HI)
438  .Case("toc@ha", VK_PPC_TOC_HA)
439  .Case("u", VK_PPC_U)
440  .Case("l", VK_PPC_L)
441  .Case("tls", VK_PPC_TLS)
442  .Case("dtpmod", VK_PPC_DTPMOD)
443  .Case("tprel@l", VK_PPC_TPREL_LO)
444  .Case("tprel@h", VK_PPC_TPREL_HI)
445  .Case("tprel@ha", VK_PPC_TPREL_HA)
446  .Case("tprel@high", VK_PPC_TPREL_HIGH)
447  .Case("tprel@higha", VK_PPC_TPREL_HIGHA)
448  .Case("tprel@higher", VK_PPC_TPREL_HIGHER)
449  .Case("tprel@highera", VK_PPC_TPREL_HIGHERA)
450  .Case("tprel@highest", VK_PPC_TPREL_HIGHEST)
451  .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA)
452  .Case("dtprel@l", VK_PPC_DTPREL_LO)
453  .Case("dtprel@h", VK_PPC_DTPREL_HI)
454  .Case("dtprel@ha", VK_PPC_DTPREL_HA)
455  .Case("dtprel@high", VK_PPC_DTPREL_HIGH)
456  .Case("dtprel@higha", VK_PPC_DTPREL_HIGHA)
457  .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER)
458  .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA)
459  .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST)
460  .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA)
461  .Case("got@tprel", VK_PPC_GOT_TPREL)
462  .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO)
463  .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI)
464  .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA)
465  .Case("got@dtprel", VK_PPC_GOT_DTPREL)
466  .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO)
467  .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI)
468  .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA)
469  .Case("got@tlsgd", VK_PPC_GOT_TLSGD)
470  .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO)
471  .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI)
472  .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
473  .Case("got@tlsld", VK_PPC_GOT_TLSLD)
474  .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO)
475  .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI)
476  .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA)
477  .Case("got@pcrel", VK_PPC_GOT_PCREL)
478  .Case("got@tlsgd@pcrel", VK_PPC_GOT_TLSGD_PCREL)
479  .Case("got@tlsld@pcrel", VK_PPC_GOT_TLSLD_PCREL)
480  .Case("got@tprel@pcrel", VK_PPC_GOT_TPREL_PCREL)
481  .Case("tls@pcrel", VK_PPC_TLS_PCREL)
482  .Case("notoc", VK_PPC_NOTOC)
483  .Case("gdgot", VK_Hexagon_GD_GOT)
484  .Case("gdplt", VK_Hexagon_GD_PLT)
485  .Case("iegot", VK_Hexagon_IE_GOT)
486  .Case("ie", VK_Hexagon_IE)
487  .Case("ldgot", VK_Hexagon_LD_GOT)
488  .Case("ldplt", VK_Hexagon_LD_PLT)
489  .Case("none", VK_ARM_NONE)
490  .Case("got_prel", VK_ARM_GOT_PREL)
491  .Case("target1", VK_ARM_TARGET1)
492  .Case("target2", VK_ARM_TARGET2)
493  .Case("prel31", VK_ARM_PREL31)
494  .Case("sbrel", VK_ARM_SBREL)
495  .Case("tlsldo", VK_ARM_TLSLDO)
496  .Case("lo8", VK_AVR_LO8)
497  .Case("hi8", VK_AVR_HI8)
498  .Case("hlo8", VK_AVR_HLO8)
499  .Case("typeindex", VK_WASM_TYPEINDEX)
500  .Case("tbrel", VK_WASM_TBREL)
501  .Case("mbrel", VK_WASM_MBREL)
502  .Case("tlsrel", VK_WASM_TLSREL)
503  .Case("got@tls", VK_WASM_GOT_TLS)
504  .Case("gotpcrel32@lo", VK_AMDGPU_GOTPCREL32_LO)
505  .Case("gotpcrel32@hi", VK_AMDGPU_GOTPCREL32_HI)
506  .Case("rel32@lo", VK_AMDGPU_REL32_LO)
507  .Case("rel32@hi", VK_AMDGPU_REL32_HI)
508  .Case("rel64", VK_AMDGPU_REL64)
509  .Case("abs32@lo", VK_AMDGPU_ABS32_LO)
510  .Case("abs32@hi", VK_AMDGPU_ABS32_HI)
511  .Case("hi", VK_VE_HI32)
512  .Case("lo", VK_VE_LO32)
513  .Case("pc_hi", VK_VE_PC_HI32)
514  .Case("pc_lo", VK_VE_PC_LO32)
515  .Case("got_hi", VK_VE_GOT_HI32)
516  .Case("got_lo", VK_VE_GOT_LO32)
517  .Case("gotoff_hi", VK_VE_GOTOFF_HI32)
518  .Case("gotoff_lo", VK_VE_GOTOFF_LO32)
519  .Case("plt_hi", VK_VE_PLT_HI32)
520  .Case("plt_lo", VK_VE_PLT_LO32)
521  .Case("tls_gd_hi", VK_VE_TLS_GD_HI32)
522  .Case("tls_gd_lo", VK_VE_TLS_GD_LO32)
523  .Case("tpoff_hi", VK_VE_TPOFF_HI32)
524  .Case("tpoff_lo", VK_VE_TPOFF_LO32)
525  .Default(VK_Invalid);
526 }
527 
528 /* *** */
529 
530 void MCTargetExpr::anchor() {}
531 
532 /* *** */
533 
534 bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
535  return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr, false);
536 }
537 
538 bool MCExpr::evaluateAsAbsolute(int64_t &Res,
539  const MCAsmLayout &Layout) const {
540  return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, false);
541 }
542 
543 bool MCExpr::evaluateAsAbsolute(int64_t &Res,
544  const MCAsmLayout &Layout,
545  const SectionAddrMap &Addrs) const {
546  // Setting InSet causes us to absolutize differences across sections and that
547  // is what the MachO writer uses Addrs for.
548  return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs, true);
549 }
550 
551 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
552  return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr, false);
553 }
554 
555 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
556  return evaluateAsAbsolute(Res, Asm, nullptr, nullptr, false);
557 }
558 
559 bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
560  const MCAsmLayout &Layout) const {
561  return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr,
562  true);
563 }
564 
565 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
566  const MCAsmLayout *Layout,
567  const SectionAddrMap *Addrs, bool InSet) const {
568  MCValue Value;
569 
570  // Fast path constants.
571  if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) {
572  Res = CE->getValue();
573  return true;
574  }
575 
576  bool IsRelocatable =
577  evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
578 
579  // Record the current value.
580  Res = Value.getConstant();
581 
582  return IsRelocatable && Value.isAbsolute();
583 }
584 
585 /// Helper method for \see EvaluateSymbolAdd().
586 static void AttemptToFoldSymbolOffsetDifference(
587  const MCAssembler *Asm, const MCAsmLayout *Layout,
588  const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A,
589  const MCSymbolRefExpr *&B, int64_t &Addend) {
590  if (!A || !B)
591  return;
592 
593  const MCSymbol &SA = A->getSymbol();
594  const MCSymbol &SB = B->getSymbol();
595 
596  if (SA.isUndefined() || SB.isUndefined())
597  return;
598 
599  if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
600  return;
601 
602  auto FinalizeFolding = [&]() {
603  // Pointers to Thumb symbols need to have their low-bit set to allow
604  // for interworking.
605  if (Asm->isThumbFunc(&SA))
606  Addend |= 1;
607 
608  // If symbol is labeled as micromips, we set low-bit to ensure
609  // correct offset in .gcc_except_table
610  if (Asm->getBackend().isMicroMips(&SA))
611  Addend |= 1;
612 
613  // Clear the symbol expr pointers to indicate we have folded these
614  // operands.
615  A = B = nullptr;
616  };
617 
618  const MCFragment *FA = SA.getFragment();
619  const MCFragment *FB = SB.getFragment();
620  // If both symbols are in the same fragment, return the difference of their
621  // offsets
622  if (FA == FB && !SA.isVariable() && !SA.isUnset() && !SB.isVariable() &&
623  !SB.isUnset()) {
624  Addend += SA.getOffset() - SB.getOffset();
625  return FinalizeFolding();
626  }
627 
628  const MCSection &SecA = *FA->getParent();
629  const MCSection &SecB = *FB->getParent();
630 
631  if ((&SecA != &SecB) && !Addrs)
632  return;
633 
634  if (Layout) {
635  // One of the symbol involved is part of a fragment being laid out. Quit now
636  // to avoid a self loop.
637  if (!Layout->canGetFragmentOffset(FA) || !Layout->canGetFragmentOffset(FB))
638  return;
639 
640  // Eagerly evaluate when layout is finalized.
641  Addend += Layout->getSymbolOffset(A->getSymbol()) -
642  Layout->getSymbolOffset(B->getSymbol());
643  if (Addrs && (&SecA != &SecB))
644  Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
645 
646  FinalizeFolding();
647  } else {
648  // When layout is not finalized, our ability to resolve differences between
649  // symbols is limited to specific cases where the fragments between two
650  // symbols (including the fragments the symbols are defined in) are
651  // fixed-size fragments so the difference can be calculated. For example,
652  // this is important when the Subtarget is changed and a new MCDataFragment
653  // is created in the case of foo: instr; .arch_extension ext; instr .if . -
654  // foo.
655  if (SA.isVariable() || SA.isUnset() || SB.isVariable() || SB.isUnset() ||
656  FA->getKind() != MCFragment::FT_Data ||
657  FB->getKind() != MCFragment::FT_Data ||
658  FA->getSubsectionNumber() != FB->getSubsectionNumber())
659  return;
660  // Try to find a constant displacement from FA to FB, add the displacement
661  // between the offset in FA of SA and the offset in FB of SB.
662  int64_t Displacement = SA.getOffset() - SB.getOffset();
663  for (auto FI = FB->getIterator(), FE = SecA.end(); FI != FE; ++FI) {
664  if (&*FI == FA) {
665  Addend += Displacement;
666  return FinalizeFolding();
667  }
668 
669  if (FI->getKind() != MCFragment::FT_Data)
670  return;
671  Displacement += cast<MCDataFragment>(FI)->getContents().size();
672  }
673  }
674 }
675 
676 /// Evaluate the result of an add between (conceptually) two MCValues.
677 ///
678 /// This routine conceptually attempts to construct an MCValue:
679 /// Result = (Result_A - Result_B + Result_Cst)
680 /// from two MCValue's LHS and RHS where
681 /// Result = LHS + RHS
682 /// and
683 /// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
684 ///
685 /// This routine attempts to aggressively fold the operands such that the result
686 /// is representable in an MCValue, but may not always succeed.
687 ///
688 /// \returns True on success, false if the result is not representable in an
689 /// MCValue.
690 
691 /// NOTE: It is really important to have both the Asm and Layout arguments.
692 /// They might look redundant, but this function can be used before layout
693 /// is done (see the object streamer for example) and having the Asm argument
694 /// lets us avoid relaxations early.
695 static bool
696 EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
697  const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS,
698  const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B,
699  int64_t RHS_Cst, MCValue &Res) {
700  // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
701  // about dealing with modifiers. This will ultimately bite us, one day.
702  const MCSymbolRefExpr *LHS_A = LHS.getSymA();
703  const MCSymbolRefExpr *LHS_B = LHS.getSymB();
704  int64_t LHS_Cst = LHS.getConstant();
705 
706  // Fold the result constant immediately.
707  int64_t Result_Cst = LHS_Cst + RHS_Cst;
708 
709  assert((!Layout || Asm) &&
710  "Must have an assembler object if layout is given!");
711 
712  // If we have a layout, we can fold resolved differences.
713  if (Asm) {
714  // First, fold out any differences which are fully resolved. By
715  // reassociating terms in
716  // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
717  // we have the four possible differences:
718  // (LHS_A - LHS_B),
719  // (LHS_A - RHS_B),
720  // (RHS_A - LHS_B),
721  // (RHS_A - RHS_B).
722  // Since we are attempting to be as aggressive as possible about folding, we
723  // attempt to evaluate each possible alternative.
724  AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B,
725  Result_Cst);
726  AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B,
727  Result_Cst);
728  AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B,
729  Result_Cst);
730  AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B,
731  Result_Cst);
732  }
733 
734  // We can't represent the addition or subtraction of two symbols.
735  if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
736  return false;
737 
738  // At this point, we have at most one additive symbol and one subtractive
739  // symbol -- find them.
740  const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
741  const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
742 
743  Res = MCValue::get(A, B, Result_Cst);
744  return true;
745 }
746 
748  const MCAsmLayout *Layout,
749  const MCFixup *Fixup) const {
750  MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr;
751  return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
752  false);
753 }
754 
755 bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
756  MCAssembler *Assembler = &Layout.getAssembler();
757  return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
758  true);
759 }
760 
761 static bool canExpand(const MCSymbol &Sym, bool InSet) {
762  const MCExpr *Expr = Sym.getVariableValue();
763  const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
764  if (Inner) {
765  if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
766  return false;
767  }
768 
769  if (InSet)
770  return true;
771  return !Sym.isInSection();
772 }
773 
775  const MCAsmLayout *Layout,
776  const MCFixup *Fixup,
777  const SectionAddrMap *Addrs,
778  bool InSet) const {
779  ++stats::MCExprEvaluate;
780 
781  switch (getKind()) {
782  case Target:
783  return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout,
784  Fixup);
785 
786  case Constant:
787  Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
788  return true;
789 
790  case SymbolRef: {
791  const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
792  const MCSymbol &Sym = SRE->getSymbol();
793  const auto Kind = SRE->getKind();
794 
795  // Evaluate recursively if this is a variable.
796  if (Sym.isVariable() && (Kind == MCSymbolRefExpr::VK_None || Layout) &&
797  canExpand(Sym, InSet)) {
798  bool IsMachO = SRE->hasSubsectionsViaSymbols();
800  Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
801  if (Kind != MCSymbolRefExpr::VK_None) {
802  if (Res.isAbsolute()) {
803  Res = MCValue::get(SRE, nullptr, 0);
804  return true;
805  }
806  // If the reference has a variant kind, we can only handle expressions
807  // which evaluate exactly to a single unadorned symbol. Attach the
808  // original VariantKind to SymA of the result.
809  if (Res.getRefKind() != MCSymbolRefExpr::VK_None || !Res.getSymA() ||
810  Res.getSymB() || Res.getConstant())
811  return false;
812  Res =
814  Kind, Asm->getContext()),
815  Res.getSymB(), Res.getConstant(), Res.getRefKind());
816  }
817  if (!IsMachO)
818  return true;
819 
820  const MCSymbolRefExpr *A = Res.getSymA();
821  const MCSymbolRefExpr *B = Res.getSymB();
822  // FIXME: This is small hack. Given
823  // a = b + 4
824  // .long a
825  // the OS X assembler will completely drop the 4. We should probably
826  // include it in the relocation or produce an error if that is not
827  // possible.
828  // Allow constant expressions.
829  if (!A && !B)
830  return true;
831  // Allows aliases with zero offset.
832  if (Res.getConstant() == 0 && (!A || !B))
833  return true;
834  }
835  }
836 
837  Res = MCValue::get(SRE, nullptr, 0);
838  return true;
839  }
840 
841  case Unary: {
842  const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
843  MCValue Value;
844 
845  if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
846  Addrs, InSet))
847  return false;
848 
849  switch (AUE->getOpcode()) {
850  case MCUnaryExpr::LNot:
851  if (!Value.isAbsolute())
852  return false;
853  Res = MCValue::get(!Value.getConstant());
854  break;
855  case MCUnaryExpr::Minus:
856  /// -(a - b + const) ==> (b - a - const)
857  if (Value.getSymA() && !Value.getSymB())
858  return false;
859 
860  // The cast avoids undefined behavior if the constant is INT64_MIN.
861  Res = MCValue::get(Value.getSymB(), Value.getSymA(),
862  -(uint64_t)Value.getConstant());
863  break;
864  case MCUnaryExpr::Not:
865  if (!Value.isAbsolute())
866  return false;
867  Res = MCValue::get(~Value.getConstant());
868  break;
869  case MCUnaryExpr::Plus:
870  Res = Value;
871  break;
872  }
873 
874  return true;
875  }
876 
877  case Binary: {
878  const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
879  MCValue LHSValue, RHSValue;
880 
881  if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
882  Addrs, InSet) ||
883  !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
884  Addrs, InSet)) {
885  // Check if both are Target Expressions, see if we can compare them.
886  if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS()))
887  if (const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS())) {
888  switch (ABE->getOpcode()) {
889  case MCBinaryExpr::EQ:
890  Res = MCValue::get((L->isEqualTo(R)) ? -1 : 0);
891  return true;
892  case MCBinaryExpr::NE:
893  Res = MCValue::get((R->isEqualTo(R)) ? 0 : -1);
894  return true;
895  default: break;
896  }
897  }
898  return false;
899  }
900 
901  // We only support a few operations on non-constant expressions, handle
902  // those first.
903  if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
904  switch (ABE->getOpcode()) {
905  default:
906  return false;
907  case MCBinaryExpr::Sub:
908  // Negate RHS and add.
909  // The cast avoids undefined behavior if the constant is INT64_MIN.
910  return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
911  RHSValue.getSymB(), RHSValue.getSymA(),
912  -(uint64_t)RHSValue.getConstant(), Res);
913 
914  case MCBinaryExpr::Add:
915  return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
916  RHSValue.getSymA(), RHSValue.getSymB(),
917  RHSValue.getConstant(), Res);
918  }
919  }
920 
921  // FIXME: We need target hooks for the evaluation. It may be limited in
922  // width, and gas defines the result of comparisons differently from
923  // Apple as.
924  int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
925  int64_t Result = 0;
926  auto Op = ABE->getOpcode();
927  switch (Op) {
928  case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
929  case MCBinaryExpr::Add: Result = LHS + RHS; break;
930  case MCBinaryExpr::And: Result = LHS & RHS; break;
931  case MCBinaryExpr::Div:
932  case MCBinaryExpr::Mod:
933  // Handle division by zero. gas just emits a warning and keeps going,
934  // we try to be stricter.
935  // FIXME: Currently the caller of this function has no way to understand
936  // we're bailing out because of 'division by zero'. Therefore, it will
937  // emit a 'expected relocatable expression' error. It would be nice to
938  // change this code to emit a better diagnostic.
939  if (RHS == 0)
940  return false;
941  if (ABE->getOpcode() == MCBinaryExpr::Div)
942  Result = LHS / RHS;
943  else
944  Result = LHS % RHS;
945  break;
946  case MCBinaryExpr::EQ: Result = LHS == RHS; break;
947  case MCBinaryExpr::GT: Result = LHS > RHS; break;
948  case MCBinaryExpr::GTE: Result = LHS >= RHS; break;
949  case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
950  case MCBinaryExpr::LOr: Result = LHS || RHS; break;
951  case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break;
952  case MCBinaryExpr::LT: Result = LHS < RHS; break;
953  case MCBinaryExpr::LTE: Result = LHS <= RHS; break;
954  case MCBinaryExpr::Mul: Result = LHS * RHS; break;
955  case MCBinaryExpr::NE: Result = LHS != RHS; break;
956  case MCBinaryExpr::Or: Result = LHS | RHS; break;
957  case MCBinaryExpr::OrNot: Result = LHS | ~RHS; break;
958  case MCBinaryExpr::Shl: Result = uint64_t(LHS) << uint64_t(RHS); break;
959  case MCBinaryExpr::Sub: Result = LHS - RHS; break;
960  case MCBinaryExpr::Xor: Result = LHS ^ RHS; break;
961  }
962 
963  switch (Op) {
964  default:
965  Res = MCValue::get(Result);
966  break;
967  case MCBinaryExpr::EQ:
968  case MCBinaryExpr::GT:
969  case MCBinaryExpr::GTE:
970  case MCBinaryExpr::LT:
971  case MCBinaryExpr::LTE:
972  case MCBinaryExpr::NE:
973  // A comparison operator returns a -1 if true and 0 if false.
974  Res = MCValue::get(Result ? -1 : 0);
975  break;
976  }
977 
978  return true;
979  }
980  }
981 
982  llvm_unreachable("Invalid assembly expression kind!");
983 }
984 
986  switch (getKind()) {
987  case Target:
988  // We never look through target specific expressions.
989  return cast<MCTargetExpr>(this)->findAssociatedFragment();
990 
991  case Constant:
993 
994  case SymbolRef: {
995  const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
996  const MCSymbol &Sym = SRE->getSymbol();
997  return Sym.getFragment();
998  }
999 
1000  case Unary:
1001  return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedFragment();
1002 
1003  case Binary: {
1004  const MCBinaryExpr *BE = cast<MCBinaryExpr>(this);
1005  MCFragment *LHS_F = BE->getLHS()->findAssociatedFragment();
1006  MCFragment *RHS_F = BE->getRHS()->findAssociatedFragment();
1007 
1008  // If either is absolute, return the other.
1009  if (LHS_F == MCSymbol::AbsolutePseudoFragment)
1010  return RHS_F;
1011  if (RHS_F == MCSymbol::AbsolutePseudoFragment)
1012  return LHS_F;
1013 
1014  // Not always correct, but probably the best we can do without more context.
1015  if (BE->getOpcode() == MCBinaryExpr::Sub)
1017 
1018  // Otherwise, return the first non-null fragment.
1019  return LHS_F ? LHS_F : RHS_F;
1020  }
1021  }
1022 
1023  llvm_unreachable("Invalid assembly expression kind!");
1024 }
llvm::MCSymbolRefExpr::getKind
VariantKind getKind() const
Definition: MCExpr.h:400
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCExpr::evaluateAsValue
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:755
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::MCUnaryExpr::getOpcode
Opcode getOpcode() const
Get the kind of this unary expression.
Definition: MCExpr.h:467
llvm::MCBinaryExpr::LT
@ LT
Signed less than comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:493
llvm::MCAsmInfo
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Statistic.h
llvm::MCSymbol::AbsolutePseudoFragment
static MCFragment * AbsolutePseudoFragment
Definition: MCSymbol.h:66
ErrorHandling.h
llvm::MCBinaryExpr::EQ
@ EQ
Equality comparison.
Definition: MCExpr.h:486
llvm::MCUnaryExpr::Plus
@ Plus
Unary plus.
Definition: MCExpr.h:430
llvm::MCBinaryExpr::Add
@ Add
Addition.
Definition: MCExpr.h:483
MCAssembler.h
llvm::MCBinaryExpr::Mul
@ Mul
Multiplication.
Definition: MCExpr.h:498
llvm::MCSymbol::getFragment
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:392
llvm::MCBinaryExpr::AShr
@ AShr
Arithmetic shift right.
Definition: MCExpr.h:503
llvm::MCBinaryExpr
Binary assembler expressions.
Definition: MCExpr.h:480
llvm::MCBinaryExpr::And
@ And
Bitwise and.
Definition: MCExpr.h:484
llvm::MCUnaryExpr
Unary assembler expressions.
Definition: MCExpr.h:424
llvm::MCExpr::evaluateAsRelocatable
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:747
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCBinaryExpr::LOr
@ LOr
Logical or.
Definition: MCExpr.h:492
MCAsmBackend.h
llvm::MCExpr::Target
@ Target
Target specific expression.
Definition: MCExpr.h:42
EvaluateSymbolicAdd
static bool EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout, const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS, const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B, int64_t RHS_Cst, MCValue &Res)
Evaluate the result of an add between (conceptually) two MCValues.
Definition: MCExpr.cpp:696
MCContext.h
llvm::MCBinaryExpr::Or
@ Or
Bitwise or.
Definition: MCExpr.h:500
MCSymbol.h
t
bitcast float %x to i32 %s=and i32 %t, 2147483647 %d=bitcast i32 %s to float ret float %d } declare float @fabsf(float %n) define float @bar(float %x) nounwind { %d=call float @fabsf(float %x) ret float %d } This IR(from PR6194):target datalayout="e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple="x86_64-apple-darwin10.0.0" %0=type { double, double } %struct.float3=type { float, float, float } define void @test(%0, %struct.float3 *nocapture %res) nounwind noinline ssp { entry:%tmp18=extractvalue %0 %0, 0 t
Definition: README-SSE.txt:788
llvm::MCValue::isAbsolute
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:50
llvm::MCBinaryExpr::getRHS
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:630
llvm::MCSymbol::getVariableValue
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
Definition: MCSymbol.h:298
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCSymbolRefExpr::getSymbol
const MCSymbol & getSymbol() const
Definition: MCExpr.h:398
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::MCBinaryExpr::Mod
@ Mod
Signed remainder.
Definition: MCExpr.h:497
llvm::MCSymbol::getName
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:198
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:45
llvm::MCExpr::getKind
ExprKind getKind() const
Definition: MCExpr.h:81
llvm::MCSymbol::print
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:59
llvm::MCUnaryExpr::Minus
@ Minus
Unary minus.
Definition: MCExpr.h:428
llvm::MCExpr::Binary
@ Binary
Binary expressions.
Definition: MCExpr.h:38
llvm::MCAsmInfo::useParensForSymbolVariant
bool useParensForSymbolVariant() const
Definition: MCAsmInfo.h:790
llvm::MCConstantExpr
Definition: MCExpr.h:144
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::Twine::utohexstr
static Twine utohexstr(const uint64_t &Val)
Definition: Twine.h:408
llvm::MCSymbolRefExpr::VariantKind
VariantKind
Definition: MCExpr.h:194
uint64_t
llvm::MCValue::get
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
Definition: MCValue.h:60
llvm::MCBinaryExpr::Div
@ Div
Signed division.
Definition: MCExpr.h:485
llvm::DenseMap< const MCSection *, uint64_t >
StringExtras.h
llvm::MCExpr::evaluateAsRelocatableImpl
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCAsmLayout *Layout, const MCFixup *Fixup, const SectionAddrMap *Addrs, bool InSet) const
Definition: MCExpr.cpp:774
llvm::MCBinaryExpr::GTE
@ GTE
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:489
llvm::MCBinaryExpr::Shl
@ Shl
Shift left.
Definition: MCExpr.h:502
llvm::MCSymbol::isVariable
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:293
llvm::MCBinaryExpr::LAnd
@ LAnd
Logical and.
Definition: MCExpr.h:491
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::MCBinaryExpr::NE
@ NE
Inequality comparison.
Definition: MCExpr.h:499
llvm::MCBinaryExpr::GT
@ GT
Signed greater than comparison (result is either 0 or some target-specific non-zero value)
Definition: MCExpr.h:487
llvm::MCUnaryExpr::getSubExpr
const MCExpr * getSubExpr() const
Get the child of this unary expression.
Definition: MCExpr.h:470
MCAsmInfo.h
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:235
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
Compiler.h
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::MCSymbolRefExpr::VK_WEAKREF
@ VK_WEAKREF
Definition: MCExpr.h:224
MCAsmLayout.h
MCObjectWriter.h
llvm::MCBinaryExpr::getOpcode
Opcode getOpcode() const
Get the kind of this binary expression.
Definition: MCExpr.h:624
stats
Definition: MCAssembler.cpp:52
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
or
compiles or
Definition: README.txt:606
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:321
llvm::MCBinaryExpr::Sub
@ Sub
Subtraction.
Definition: MCExpr.h:505
llvm::MCUnaryExpr::LNot
@ LNot
Logical negation.
Definition: MCExpr.h:427
Casting.h
llvm::MCBinaryExpr::Xor
@ Xor
Bitwise exclusive or.
Definition: MCExpr.h:506
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MCValue::getRefKind
uint32_t getRefKind() const
Definition: MCValue.h:47
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
StringSwitch.h
llvm::MCSymbolRefExpr::getVariantKindName
static StringRef getVariantKindName(VariantKind Kind)
Definition: MCExpr.cpp:221
MCValue.h
llvm::MCSymbolRefExpr::hasSubsectionsViaSymbols
bool hasSubsectionsViaSymbols() const
Definition: MCExpr.h:404
llvm::MCExpr::print
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
llvm::MCBinaryExpr::OrNot
@ OrNot
Bitwise or not.
Definition: MCExpr.h:501
llvm::MCExpr::SymbolRef
@ SymbolRef
References to labels and assigned expressions.
Definition: MCExpr.h:40
llvm::MCExpr::Unary
@ Unary
Unary expressions.
Definition: MCExpr.h:41
llvm::MCSymbol::isInSection
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).
Definition: MCSymbol.h:247
llvm::MCExpr::Constant
@ Constant
Constant expressions.
Definition: MCExpr.h:39
canExpand
static bool canExpand(const MCSymbol &Sym, bool InSet)
Definition: MCExpr.cpp:761
llvm::MCExpr::findAssociatedFragment
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Definition: MCExpr.cpp:985
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCAsmLayout::getAssembler
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:50
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCBinaryExpr::LTE
@ LTE
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value).
Definition: MCExpr.h:495
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::MCBinaryExpr::LShr
@ LShr
Logical shift right.
Definition: MCExpr.h:504
raw_ostream.h
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
llvm::MCTargetExpr
This is an extension point for target-specific MCExpr subclasses to implement.
Definition: MCExpr.h:644
MCExpr.h
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Debug.h
llvm::MCUnaryExpr::Not
@ Not
Bitwise negation.
Definition: MCExpr.h:429
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:46
of
Add support for conditional and other related patterns Instead of
Definition: README.txt:134
llvm::MCBinaryExpr::getLHS
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:627