13 #include "llvm/Config/llvm-config.h" 32 #define DEBUG_TYPE "mcexpr" 37 STATISTIC(MCExprEvaluate,
"Number of MCExpr evaluations");
45 return cast<MCTargetExpr>(
this)->printImpl(OS, MAI);
47 OS << cast<MCConstantExpr>(*this).getValue();
79 if (Binary) OS <<
"(";
81 if (Binary) OS <<
")";
89 if (isa<MCConstantExpr>(BE.
getLHS()) || isa<MCSymbolRefExpr>(BE.
getLHS())) {
101 if (RHSC->getValue() < 0) {
102 OS << RHSC->getValue();
114 case MCBinaryExpr::GTE: OS << ">="; break; 115 case MCBinaryExpr::LAnd: OS << "&&"; break; 116 case MCBinaryExpr::LOr: OS << "||"; break; 117 case MCBinaryExpr::LShr: OS << ">>"; break; 118 case MCBinaryExpr::LT: OS << '<
'; break; 119 case MCBinaryExpr::LTE: OS << "<="; break; 120 case MCBinaryExpr::Mod: OS << '%
'; break; 121 case MCBinaryExpr::Mul: OS << '*
'; break; 122 case MCBinaryExpr::NE: OS << "!="; break; 123 case MCBinaryExpr::Or: OS << '|
'; break; 124 case MCBinaryExpr::Shl: OS << "<<"; break; 125 case MCBinaryExpr::Sub: OS << '-
'; break; 126 case MCBinaryExpr::Xor: OS << '^
'; break; 129 // Only print parens around the LHS if it is non-trivial. 130 if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) { 131 BE.getRHS()->print(OS, MAI); 134 BE.getRHS()->print(OS, MAI); 141 llvm_unreachable("Invalid expression kind!"); 144 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 145 LLVM_DUMP_METHOD void MCExpr::dump() const { 153 const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS, 154 const MCExpr *RHS, MCContext &Ctx, 156 return new (Ctx) MCBinaryExpr(Opc, LHS, RHS, Loc); 159 const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr, 160 MCContext &Ctx, SMLoc Loc) { 161 return new (Ctx) MCUnaryExpr(Opc, Expr, Loc); 164 const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) { 165 return new (Ctx) MCConstantExpr(Value); 170 MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind, 171 const MCAsmInfo *MAI, SMLoc Loc) 172 : MCExpr(MCExpr::SymbolRef, Loc), Kind(Kind), 173 UseParensForSymbolVariant(MAI->useParensForSymbolVariant()), 174 HasSubsectionsViaSymbols(MAI->hasSubsectionsViaSymbols()), 179 const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym, 181 MCContext &Ctx, SMLoc Loc) { 182 return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo(), Loc); 185 const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind, 187 return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx); 190 StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) { 192 case VK_Invalid: return "<<invalid>>"; 193 case VK_None: return "<<none>>"; 195 case VK_DTPOFF: return "DTPOFF"; 196 case VK_DTPREL: return "DTPREL"; 197 case VK_GOT: return "GOT"; 198 case VK_GOTOFF: return "GOTOFF"; 199 case VK_GOTREL: return "GOTREL"; 200 case VK_GOTPCREL: return "GOTPCREL"; 201 case VK_GOTTPOFF: return "GOTTPOFF"; 202 case VK_INDNTPOFF: return "INDNTPOFF"; 203 case VK_NTPOFF: return "NTPOFF"; 204 case VK_GOTNTPOFF: return "GOTNTPOFF"; 205 case VK_PLT: return "PLT"; 206 case VK_TLSGD: return "TLSGD"; 207 case VK_TLSLD: return "TLSLD"; 208 case VK_TLSLDM: return "TLSLDM"; 209 case VK_TPOFF: return "TPOFF"; 210 case VK_TPREL: return "TPREL"; 211 case VK_TLSCALL: return "tlscall"; 212 case VK_TLSDESC: return "tlsdesc"; 213 case VK_TLVP: return "TLVP"; 214 case VK_TLVPPAGE: return "TLVPPAGE"; 215 case VK_TLVPPAGEOFF: return "TLVPPAGEOFF"; 216 case VK_PAGE: return "PAGE"; 217 case VK_PAGEOFF: return "PAGEOFF"; 218 case VK_GOTPAGE: return "GOTPAGE"; 219 case VK_GOTPAGEOFF: return "GOTPAGEOFF"; 220 case VK_SECREL: return "SECREL32"; 221 case VK_SIZE: return "SIZE"; 222 case VK_WEAKREF: return "WEAKREF"; 223 case VK_X86_ABS8: return "ABS8"; 224 case VK_ARM_NONE: return "none"; 225 case VK_ARM_GOT_PREL: return "GOT_PREL"; 226 case VK_ARM_TARGET1: return "target1"; 227 case VK_ARM_TARGET2: return "target2"; 228 case VK_ARM_PREL31: return "prel31"; 229 case VK_ARM_SBREL: return "sbrel"; 230 case VK_ARM_TLSLDO: return "tlsldo"; 231 case VK_ARM_TLSDESCSEQ: return "tlsdescseq"; 232 case VK_AVR_NONE: return "none"; 233 case VK_AVR_LO8: return "lo8"; 234 case VK_AVR_HI8: return "hi8"; 235 case VK_AVR_HLO8: return "hlo8"; 236 case VK_AVR_DIFF8: return "diff8"; 237 case VK_AVR_DIFF16: return "diff16"; 238 case VK_AVR_DIFF32: return "diff32"; 239 case VK_PPC_LO: return "l"; 240 case VK_PPC_HI: return "h"; 241 case VK_PPC_HA: return "ha"; 242 case VK_PPC_HIGH: return "high"; 243 case VK_PPC_HIGHA: return "higha"; 244 case VK_PPC_HIGHER: return "higher"; 245 case VK_PPC_HIGHERA: return "highera"; 246 case VK_PPC_HIGHEST: return "highest"; 247 case VK_PPC_HIGHESTA: return "highesta"; 248 case VK_PPC_GOT_LO: return "got@l"; 249 case VK_PPC_GOT_HI: return "got@h"; 250 case VK_PPC_GOT_HA: return "got@ha"; 251 case VK_PPC_TOCBASE: return "tocbase"; 252 case VK_PPC_TOC: return "toc"; 253 case VK_PPC_TOC_LO: return "toc@l"; 254 case VK_PPC_TOC_HI: return "toc@h"; 255 case VK_PPC_TOC_HA: return "toc@ha"; 256 case VK_PPC_DTPMOD: return "dtpmod"; 257 case VK_PPC_TPREL_LO: return "tprel@l"; 258 case VK_PPC_TPREL_HI: return "tprel@h"; 259 case VK_PPC_TPREL_HA: return "tprel@ha"; 260 case VK_PPC_TPREL_HIGH: return "tprel@high"; 261 case VK_PPC_TPREL_HIGHA: return "tprel@higha"; 262 case VK_PPC_TPREL_HIGHER: return "tprel@higher"; 263 case VK_PPC_TPREL_HIGHERA: return "tprel@highera"; 264 case VK_PPC_TPREL_HIGHEST: return "tprel@highest"; 265 case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta"; 266 case VK_PPC_DTPREL_LO: return "dtprel@l"; 267 case VK_PPC_DTPREL_HI: return "dtprel@h"; 268 case VK_PPC_DTPREL_HA: return "dtprel@ha"; 269 case VK_PPC_DTPREL_HIGH: return "dtprel@high"; 270 case VK_PPC_DTPREL_HIGHA: return "dtprel@higha"; 271 case VK_PPC_DTPREL_HIGHER: return "dtprel@higher"; 272 case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera"; 273 case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest"; 274 case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta"; 275 case VK_PPC_GOT_TPREL: return "got@tprel"; 276 case VK_PPC_GOT_TPREL_LO: return "got@tprel@l"; 277 case VK_PPC_GOT_TPREL_HI: return "got@tprel@h"; 278 case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha"; 279 case VK_PPC_GOT_DTPREL: return "got@dtprel"; 280 case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l"; 281 case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h"; 282 case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha"; 283 case VK_PPC_TLS: return "tls"; 284 case VK_PPC_GOT_TLSGD: return "got@tlsgd"; 285 case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l"; 286 case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h"; 287 case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha"; 288 case VK_PPC_TLSGD: return "tlsgd"; 289 case VK_PPC_GOT_TLSLD: return "got@tlsld"; 290 case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l"; 291 case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h"; 292 case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha"; 293 case VK_PPC_TLSLD: return "tlsld"; 294 case VK_PPC_LOCAL: return "local"; 295 case VK_COFF_IMGREL32: return "IMGREL"; 296 case VK_Hexagon_PCREL: return "PCREL"; 297 case VK_Hexagon_LO16: return "LO16"; 298 case VK_Hexagon_HI16: return "HI16"; 299 case VK_Hexagon_GPREL: return "GPREL"; 300 case VK_Hexagon_GD_GOT: return "GDGOT"; 301 case VK_Hexagon_LD_GOT: return "LDGOT"; 302 case VK_Hexagon_GD_PLT: return "GDPLT"; 303 case VK_Hexagon_LD_PLT: return "LDPLT"; 304 case VK_Hexagon_IE: return "IE"; 305 case VK_Hexagon_IE_GOT: return "IEGOT"; 306 case VK_WebAssembly_FUNCTION: return "FUNCTION"; 307 case VK_WebAssembly_GLOBAL: return "GLOBAL"; 308 case VK_WebAssembly_TYPEINDEX: return "TYPEINDEX"; 309 case VK_WebAssembly_EVENT: return "EVENT"; 310 case VK_AMDGPU_GOTPCREL32_LO: return "gotpcrel32@lo"; 311 case VK_AMDGPU_GOTPCREL32_HI: return "gotpcrel32@hi"; 312 case VK_AMDGPU_REL32_LO: return "rel32@lo"; 313 case VK_AMDGPU_REL32_HI: return "rel32@hi"; 314 case VK_AMDGPU_REL64: return "rel64"; 316 llvm_unreachable("Invalid variant kind"); 319 MCSymbolRefExpr::VariantKind 320 MCSymbolRefExpr::getVariantKindForName(StringRef Name) { 321 return StringSwitch<VariantKind>(Name.lower()) 322 .Case("dtprel", VK_DTPREL) 323 .Case("dtpoff", VK_DTPOFF) 325 .Case("gotoff", VK_GOTOFF) 326 .Case("gotrel", VK_GOTREL) 327 .Case("gotpcrel", VK_GOTPCREL) 328 .Case("gottpoff", VK_GOTTPOFF) 329 .Case("indntpoff", VK_INDNTPOFF) 330 .Case("ntpoff", VK_NTPOFF) 331 .Case("gotntpoff", VK_GOTNTPOFF) 333 .Case("tlscall", VK_TLSCALL) 334 .Case("tlsdesc", VK_TLSDESC) 335 .Case("tlsgd", VK_TLSGD) 336 .Case("tlsld", VK_TLSLD) 337 .Case("tlsldm", VK_TLSLDM) 338 .Case("tpoff", VK_TPOFF) 339 .Case("tprel", VK_TPREL) 340 .Case("tlvp", VK_TLVP) 341 .Case("tlvppage", VK_TLVPPAGE) 342 .Case("tlvppageoff", VK_TLVPPAGEOFF) 343 .Case("page", VK_PAGE) 344 .Case("pageoff", VK_PAGEOFF) 345 .Case("gotpage", VK_GOTPAGE) 346 .Case("gotpageoff", VK_GOTPAGEOFF) 347 .Case("imgrel", VK_COFF_IMGREL32) 348 .Case("secrel32", VK_SECREL) 349 .Case("size", VK_SIZE) 350 .Case("abs8", VK_X86_ABS8) 351 .Case("l", VK_PPC_LO) 352 .Case("h", VK_PPC_HI) 353 .Case("ha", VK_PPC_HA) 354 .Case("high", VK_PPC_HIGH) 355 .Case("higha", VK_PPC_HIGHA) 356 .Case("higher", VK_PPC_HIGHER) 357 .Case("highera", VK_PPC_HIGHERA) 358 .Case("highest", VK_PPC_HIGHEST) 359 .Case("highesta", VK_PPC_HIGHESTA) 360 .Case("got@l", VK_PPC_GOT_LO) 361 .Case("got@h", VK_PPC_GOT_HI) 362 .Case("got@ha", VK_PPC_GOT_HA) 363 .Case("local", VK_PPC_LOCAL) 364 .Case("tocbase", VK_PPC_TOCBASE) 365 .Case("toc", VK_PPC_TOC) 366 .Case("toc@l", VK_PPC_TOC_LO) 367 .Case("toc@h", VK_PPC_TOC_HI) 368 .Case("toc@ha", VK_PPC_TOC_HA) 369 .Case("tls", VK_PPC_TLS) 370 .Case("dtpmod", VK_PPC_DTPMOD) 371 .Case("tprel@l", VK_PPC_TPREL_LO) 372 .Case("tprel@h", VK_PPC_TPREL_HI) 373 .Case("tprel@ha", VK_PPC_TPREL_HA) 374 .Case("tprel@high", VK_PPC_TPREL_HIGH) 375 .Case("tprel@higha", VK_PPC_TPREL_HIGHA) 376 .Case("tprel@higher", VK_PPC_TPREL_HIGHER) 377 .Case("tprel@highera", VK_PPC_TPREL_HIGHERA) 378 .Case("tprel@highest", VK_PPC_TPREL_HIGHEST) 379 .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA) 380 .Case("dtprel@l", VK_PPC_DTPREL_LO) 381 .Case("dtprel@h", VK_PPC_DTPREL_HI) 382 .Case("dtprel@ha", VK_PPC_DTPREL_HA) 383 .Case("dtprel@high", VK_PPC_DTPREL_HIGH) 384 .Case("dtprel@higha", VK_PPC_DTPREL_HIGHA) 385 .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER) 386 .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA) 387 .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST) 388 .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA) 389 .Case("got@tprel", VK_PPC_GOT_TPREL) 390 .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO) 391 .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI) 392 .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA) 393 .Case("got@dtprel", VK_PPC_GOT_DTPREL) 394 .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO) 395 .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI) 396 .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA) 397 .Case("got@tlsgd", VK_PPC_GOT_TLSGD) 398 .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO) 399 .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI) 400 .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA) 401 .Case("got@tlsld", VK_PPC_GOT_TLSLD) 402 .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO) 403 .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI) 404 .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA) 405 .Case("gdgot", VK_Hexagon_GD_GOT) 406 .Case("gdplt", VK_Hexagon_GD_PLT) 407 .Case("iegot", VK_Hexagon_IE_GOT) 408 .Case("ie", VK_Hexagon_IE) 409 .Case("ldgot", VK_Hexagon_LD_GOT) 410 .Case("ldplt", VK_Hexagon_LD_PLT) 411 .Case("pcrel", VK_Hexagon_PCREL) 412 .Case("none", VK_ARM_NONE) 413 .Case("got_prel", VK_ARM_GOT_PREL) 414 .Case("target1", VK_ARM_TARGET1) 415 .Case("target2", VK_ARM_TARGET2) 416 .Case("prel31", VK_ARM_PREL31) 417 .Case("sbrel", VK_ARM_SBREL) 418 .Case("tlsldo", VK_ARM_TLSLDO) 419 .Case("lo8", VK_AVR_LO8) 420 .Case("hi8", VK_AVR_HI8) 421 .Case("hlo8", VK_AVR_HLO8) 422 .Case("function", VK_WebAssembly_FUNCTION) 423 .Case("global", VK_WebAssembly_GLOBAL) 424 .Case("typeindex", VK_WebAssembly_TYPEINDEX) 425 .Case("event", VK_WebAssembly_EVENT) 426 .Case("gotpcrel32@lo", VK_AMDGPU_GOTPCREL32_LO) 427 .Case("gotpcrel32@hi", VK_AMDGPU_GOTPCREL32_HI) 428 .Case("rel32@lo", VK_AMDGPU_REL32_LO) 429 .Case("rel32@hi", VK_AMDGPU_REL32_HI) 430 .Case("rel64", VK_AMDGPU_REL64) 431 .Default(VK_Invalid); 434 void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const { 435 if (UseParensForSymbolVariant) 436 OS << '(
' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')
'; 438 OS << '@
' << MCSymbolRefExpr::getVariantKindName(getKind()); 443 void MCTargetExpr::anchor() {} 447 bool MCExpr::evaluateAsAbsolute(int64_t &Res) const { 448 return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr); 451 bool MCExpr::evaluateAsAbsolute(int64_t &Res, 452 const MCAsmLayout &Layout) const { 453 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr); 456 bool MCExpr::evaluateAsAbsolute(int64_t &Res, 457 const MCAsmLayout &Layout, 458 const SectionAddrMap &Addrs) const { 459 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs); 462 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const { 463 return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr); 466 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const { 467 return evaluateAsAbsolute(Res, Asm, nullptr, nullptr); 470 bool MCExpr::evaluateKnownAbsolute(int64_t &Res, 471 const MCAsmLayout &Layout) const { 472 return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr, 476 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, 477 const MCAsmLayout *Layout, 478 const SectionAddrMap *Addrs) const { 479 // FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us 480 // absolutize differences across sections and that is what the MachO writer 482 return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs); 485 bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm, 486 const MCAsmLayout *Layout, 487 const SectionAddrMap *Addrs, bool InSet) const { 490 // Fast path constants. 491 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) { 492 Res = CE->getValue(); 497 evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet); 499 // Record the current value. 500 Res = Value.getConstant(); 502 return IsRelocatable && Value.isAbsolute(); 506 static void AttemptToFoldSymbolOffsetDifference(
507 const MCAssembler *Asm, const MCAsmLayout *Layout,
508 const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A,
509 const MCSymbolRefExpr *&B, int64_t &Addend) {
513 const MCSymbol &SA = A->getSymbol();
514 const MCSymbol &SB = B->getSymbol();
516 if (SA.isUndefined() || SB.isUndefined())
519 if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
522 if (SA.getFragment() == SB.getFragment() && !SA.isVariable() &&
523 !SA.isUnset() && !SB.isVariable() && !SB.isUnset()) {
524 Addend += (SA.getOffset() - SB.getOffset());
526 // Pointers to Thumb symbols need to have their low-bit set to allow
528 if (Asm->isThumbFunc(&SA))
531 // If symbol is labeled as micromips, we set low-bit to ensure
532 // correct offset in .gcc_except_table
533 if (Asm->getBackend().isMicroMips(&SA))
536 // Clear the symbol expr pointers to indicate we have folded these
545 const MCSection &SecA = *SA.getFragment()->getParent();
546 const MCSection &SecB = *SB.getFragment()->getParent();
548 if ((&SecA != &SecB) && !Addrs)
552 Addend += Layout->getSymbolOffset(A->getSymbol()) -
553 Layout->getSymbolOffset(B->getSymbol());
554 if (Addrs && (&SecA != &SecB))
555 Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
557 // Pointers to Thumb symbols need to have their low-bit set to allow
559 if (Asm->isThumbFunc(&SA))
562 // If symbol is labeled as micromips, we set low-bit to ensure
563 // correct offset in .gcc_except_table
564 if (Asm->getBackend().isMicroMips(&SA))
567 // Clear the symbol expr pointers to indicate we have folded these
592 EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
593 const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS,
594 const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B,
595 int64_t RHS_Cst, MCValue &Res) {
596 // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
597 // about dealing with modifiers. This will ultimately bite us, one day.
598 const MCSymbolRefExpr *LHS_A = LHS.getSymA();
599 const MCSymbolRefExpr *LHS_B = LHS.getSymB();
600 int64_t LHS_Cst = LHS.getConstant();
602 // Fold the result constant immediately.
603 int64_t Result_Cst = LHS_Cst + RHS_Cst;
605 assert((!Layout || Asm) &&
606 "Must have an assembler object if layout is given!");
608 // If we have a layout, we can fold resolved differences. Do not do this if
609 // the backend requires this to be emitted as individual relocations, unless
610 // the InSet flag is set to get the current difference anyway (used for
611 // example to calculate symbol sizes).
613 (InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) {
614 // First, fold out any differences which are fully resolved. By
615 // reassociating terms in
616 // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
617 // we have the four possible differences:
622 // Since we are attempting to be as aggressive as possible about folding, we
623 // attempt to evaluate each possible alternative.
624 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B,
626 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B,
628 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B,
630 AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B,
634 // We can't represent the addition or subtraction of two symbols.
635 if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
651 return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup,
nullptr,
657 return evaluateAsRelocatableImpl(Res, Assembler, &Layout,
nullptr,
nullptr,
679 ++stats::MCExprEvaluate;
683 return cast<MCTargetExpr>(
this)->evaluateAsRelocatableImpl(Res, Layout,
687 Res =
MCValue::get(cast<MCConstantExpr>(
this)->getValue());
698 if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
699 Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
734 if (!Value.isAbsolute())
740 if (Value.getSymA() && !Value.getSymB())
745 -(uint64_t)Value.getConstant());
748 if (!Value.isAbsolute())
786 if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
794 RHSValue.getSymB(), RHSValue.getSymA(),
795 -(uint64_t)RHSValue.getConstant(), Res);
799 RHSValue.getSymA(), RHSValue.getSymB(),
800 RHSValue.getConstant(), Res);
807 int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
871 return cast<MCTargetExpr>(
this)->findAssociatedFragment();
883 return cast<MCUnaryExpr>(
this)->getSubExpr()->findAssociatedFragment();
901 return LHS_F ? LHS_F : RHS_F;
Signed less than comparison (result is either 0 or some target-specific non-zero value).
This class represents lattice values for constants.
Signed less than or equal comparison (result is either 0 or some target-specific non-zero value)...
This represents an "assembler immediate".
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
VariantKind getKind() const
Opcode getOpcode() const
Get the kind of this unary expression.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
STATISTIC(NumFunctions, "Total number of functions")
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
Encapsulates the layout of an assembly file at a particular point in time.
Base class for the full range of assembler expressions which are needed for parsing.
This is an extension point for target-specific MCExpr subclasses to implement.
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Represent a reference to a symbol from inside an expression.
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Unary assembler expressions.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
static bool canExpand(const MCSymbol &Sym, bool InSet)
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
This class is intended to be used as a base class for asm properties and features specific to the tar...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
This is an important base class in LLVM.
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.
const MCSymbolRefExpr * getSymA() const
Binary assembler expressions.
bool hasSubsectionsViaSymbols() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static MCFragment * AbsolutePseudoFragment
void printVariantKind(raw_ostream &OS) const
const MCSymbol & getSymbol() const
MCFragment * getFragment(bool SetUsed=true) const
bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, const MCAsmLayout *Layout, const MCFixup *Fixup, const SectionAddrMap *Addrs, bool InSet) const
Signed greater than comparison (result is either 0 or some target-specific non-zero value) ...
MCFragment * findAssociatedFragment() const
Find the "associated section" for this expression, which is currently defined as the absolute section...
Signed greater than or equal comparison (result is either 0 or some target-specific non-zero value)...
Target - Wrapper for Target specific information.
static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=nullptr, int64_t Val=0, uint32_t RefKind=0)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
References to labels and assigned expressions.
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...
Opcode getOpcode() const
Get the kind of this binary expression.
StringRef getName() const
getName - Get the symbol name.
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
const MCExpr * getSubExpr() const
Get the child of this unary expression.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
Target specific expression.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.