LCOV - code coverage report
Current view: top level - lib/MC - MCExpr.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 307 352 87.2 %
Date: 2018-06-17 00:07:59 Functions: 25 26 96.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- MCExpr.cpp - Assembly Level Expression Implementation --------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #include "llvm/MC/MCExpr.h"
      11             : #include "llvm/ADT/Statistic.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"
      25             : #include "llvm/Support/ErrorHandling.h"
      26             : #include "llvm/Support/raw_ostream.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     1185918 : void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
      43     1185918 :   switch (getKind()) {
      44             :   case MCExpr::Target:
      45       52154 :     return cast<MCTargetExpr>(this)->printImpl(OS, MAI);
      46             :   case MCExpr::Constant:
      47      458173 :     OS << cast<MCConstantExpr>(*this).getValue();
      48      458173 :     return;
      49             : 
      50             :   case MCExpr::SymbolRef: {
      51             :     const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
      52      494362 :     const MCSymbol &Sym = SRE.getSymbol();
      53             :     // Parenthesize names that start with $ so that they don't look like
      54             :     // absolute names.
      55             :     bool UseParens =
      56     1425382 :         !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$';
      57             :     if (UseParens) {
      58             :       OS << '(';
      59        9016 :       Sym.print(OS, MAI);
      60             :       OS << ')';
      61             :     } else
      62      485346 :       Sym.print(OS, MAI);
      63             : 
      64      494362 :     if (SRE.getKind() != MCSymbolRefExpr::VK_None)
      65       15908 :       SRE.printVariantKind(OS);
      66             : 
      67             :     return;
      68             :   }
      69             : 
      70             :   case MCExpr::Unary: {
      71             :     const MCUnaryExpr &UE = cast<MCUnaryExpr>(*this);
      72           6 :     switch (UE.getOpcode()) {
      73             :     case MCUnaryExpr::LNot:  OS << '!'; break;
      74             :     case MCUnaryExpr::Minus: OS << '-'; break;
      75             :     case MCUnaryExpr::Not:   OS << '~'; break;
      76             :     case MCUnaryExpr::Plus:  OS << '+'; break;
      77             :     }
      78           6 :     bool Binary = UE.getSubExpr()->getKind() == MCExpr::Binary;
      79           6 :     if (Binary) OS << "(";
      80           6 :     UE.getSubExpr()->print(OS, MAI);
      81           6 :     if (Binary) OS << ")";
      82             :     return;
      83             :   }
      84             : 
      85             :   case MCExpr::Binary: {
      86             :     const MCBinaryExpr &BE = cast<MCBinaryExpr>(*this);
      87             : 
      88             :     // Only print parens around the LHS if it is non-trivial.
      89      362446 :     if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) {
      90      180261 :       BE.getLHS()->print(OS, MAI);
      91             :     } else {
      92             :       OS << '(';
      93         962 :       BE.getLHS()->print(OS, MAI);
      94             :       OS << ')';
      95             :     }
      96             : 
      97      181223 :     switch (BE.getOpcode()) {
      98       11453 :     case MCBinaryExpr::Add:
      99             :       // Print "X-42" instead of "X+-42".
     100       11453 :       if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) {
     101       11170 :         if (RHSC->getValue() < 0) {
     102        1260 :           OS << RHSC->getValue();
     103        1260 :           return;
     104             :         }
     105             :       }
     106             : 
     107             :       OS <<  '+';
     108             :       break;
     109           0 :     case MCBinaryExpr::AShr: OS << ">>"; break;
     110             :     case MCBinaryExpr::And:  OS <<  '&'; break;
     111             :     case MCBinaryExpr::Div:  OS <<  '/'; break;
     112           0 :     case MCBinaryExpr::EQ:   OS << "=="; break;
     113             :     case MCBinaryExpr::GT:   OS <<  '>'; break;
     114           0 :     case MCBinaryExpr::GTE:  OS << ">="; break;
     115           0 :     case MCBinaryExpr::LAnd: OS << "&&"; break;
     116           0 :     case MCBinaryExpr::LOr:  OS << "||"; break;
     117           2 :     case MCBinaryExpr::LShr: OS << ">>"; break;
     118             :     case MCBinaryExpr::LT:   OS <<  '<'; break;
     119           0 :     case MCBinaryExpr::LTE:  OS << "<="; break;
     120             :     case MCBinaryExpr::Mod:  OS <<  '%'; break;
     121             :     case MCBinaryExpr::Mul:  OS <<  '*'; break;
     122           0 :     case MCBinaryExpr::NE:   OS << "!="; break;
     123             :     case MCBinaryExpr::Or:   OS <<  '|'; break;
     124           0 :     case MCBinaryExpr::Shl:  OS << "<<"; break;
     125             :     case MCBinaryExpr::Sub:  OS <<  '-'; break;
     126             :     case MCBinaryExpr::Xor:  OS <<  '^'; break;
     127             :     }
     128             : 
     129             :     // Only print parens around the LHS if it is non-trivial.
     130      359926 :     if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {
     131      177734 :       BE.getRHS()->print(OS, MAI);
     132             :     } else {
     133             :       OS << '(';
     134        2229 :       BE.getRHS()->print(OS, MAI);
     135             :       OS << ')';
     136             :     }
     137             :     return;
     138             :   }
     139             :   }
     140             : 
     141           0 :   llvm_unreachable("Invalid expression kind!");
     142             : }
     143             : 
     144             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
     145             : LLVM_DUMP_METHOD void MCExpr::dump() const {
     146             :   dbgs() << *this;
     147             :   dbgs() << '\n';
     148             : }
     149             : #endif
     150             : 
     151             : /* *** */
     152             : 
     153     2472463 : const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS,
     154             :                                          const MCExpr *RHS, MCContext &Ctx,
     155             :                                          SMLoc Loc) {
     156     4944926 :   return new (Ctx) MCBinaryExpr(Opc, LHS, RHS, Loc);
     157             : }
     158             : 
     159       19270 : const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
     160             :                                        MCContext &Ctx, SMLoc Loc) {
     161       38540 :   return new (Ctx) MCUnaryExpr(Opc, Expr, Loc);
     162             : }
     163             : 
     164     2847674 : const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) {
     165     2847674 :   return new (Ctx) MCConstantExpr(Value);
     166             : }
     167             : 
     168             : /* *** */
     169             : 
     170     5478094 : MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind,
     171     5478094 :                                  const MCAsmInfo *MAI, SMLoc Loc)
     172             :     : MCExpr(MCExpr::SymbolRef, Loc), Kind(Kind),
     173     5478094 :       UseParensForSymbolVariant(MAI->useParensForSymbolVariant()),
     174     5478094 :       HasSubsectionsViaSymbols(MAI->hasSubsectionsViaSymbols()),
     175    16434282 :       Symbol(Symbol) {
     176             :   assert(Symbol);
     177     5478094 : }
     178             : 
     179     5478094 : const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym,
     180             :                                                VariantKind Kind,
     181             :                                                MCContext &Ctx, SMLoc Loc) {
     182    10956188 :   return new (Ctx) MCSymbolRefExpr(Sym, Kind, Ctx.getAsmInfo(), Loc);
     183             : }
     184             : 
     185          22 : const MCSymbolRefExpr *MCSymbolRefExpr::create(StringRef Name, VariantKind Kind,
     186             :                                                MCContext &Ctx) {
     187          44 :   return create(Ctx.getOrCreateSymbol(Name), Kind, Ctx);
     188             : }
     189             : 
     190       15915 : StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
     191       15915 :   switch (Kind) {
     192           0 :   case VK_Invalid: return "<<invalid>>";
     193           0 :   case VK_None: return "<<none>>";
     194             : 
     195          33 :   case VK_DTPOFF: return "DTPOFF";
     196          12 :   case VK_DTPREL: return "DTPREL";
     197         171 :   case VK_GOT: return "GOT";
     198         150 :   case VK_GOTOFF: return "GOTOFF";
     199           0 :   case VK_GOTREL: return "GOTREL";
     200        1050 :   case VK_GOTPCREL: return "GOTPCREL";
     201          41 :   case VK_GOTTPOFF: return "GOTTPOFF";
     202          13 :   case VK_INDNTPOFF: return "INDNTPOFF";
     203          42 :   case VK_NTPOFF: return "NTPOFF";
     204           7 :   case VK_GOTNTPOFF: return "GOTNTPOFF";
     205        1657 :   case VK_PLT: return "PLT";
     206          59 :   case VK_TLSGD: return "TLSGD";
     207           8 :   case VK_TLSLD: return "TLSLD";
     208          17 :   case VK_TLSLDM: return "TLSLDM";
     209          61 :   case VK_TPOFF: return "TPOFF";
     210          18 :   case VK_TPREL: return "TPREL";
     211           0 :   case VK_TLSCALL: return "tlscall";
     212           1 :   case VK_TLSDESC: return "tlsdesc";
     213          48 :   case VK_TLVP: return "TLVP";
     214          26 :   case VK_TLVPPAGE: return "TLVPPAGE";
     215          27 :   case VK_TLVPPAGEOFF: return "TLVPPAGEOFF";
     216         206 :   case VK_PAGE: return "PAGE";
     217         346 :   case VK_PAGEOFF: return "PAGEOFF";
     218         178 :   case VK_GOTPAGE: return "GOTPAGE";
     219         178 :   case VK_GOTPAGEOFF: return "GOTPAGEOFF";
     220          74 :   case VK_SECREL: return "SECREL32";
     221           0 :   case VK_SIZE: return "SIZE";
     222           0 :   case VK_WEAKREF: return "WEAKREF";
     223           4 :   case VK_X86_ABS8: return "ABS8";
     224           0 :   case VK_ARM_NONE: return "none";
     225          63 :   case VK_ARM_GOT_PREL: return "GOT_PREL";
     226           8 :   case VK_ARM_TARGET1: return "target1";
     227           4 :   case VK_ARM_TARGET2: return "target2";
     228           2 :   case VK_ARM_PREL31: return "prel31";
     229          54 :   case VK_ARM_SBREL: return "sbrel";
     230           1 :   case VK_ARM_TLSLDO: return "tlsldo";
     231           0 :   case VK_ARM_TLSDESCSEQ: return "tlsdescseq";
     232           0 :   case VK_AVR_NONE: return "none";
     233           0 :   case VK_AVR_LO8: return "lo8";
     234           0 :   case VK_AVR_HI8: return "hi8";
     235           0 :   case VK_AVR_HLO8: return "hlo8";
     236           0 :   case VK_AVR_DIFF8: return "diff8";
     237           0 :   case VK_AVR_DIFF16: return "diff16";
     238           0 :   case VK_AVR_DIFF32: return "diff32";
     239           1 :   case VK_PPC_LO: return "l";
     240           0 :   case VK_PPC_HI: return "h";
     241           1 :   case VK_PPC_HA: return "ha";
     242           0 :   case VK_PPC_HIGH: return "high";
     243           0 :   case VK_PPC_HIGHA: return "higha";
     244           0 :   case VK_PPC_HIGHER: return "higher";
     245           0 :   case VK_PPC_HIGHERA: return "highera";
     246           0 :   case VK_PPC_HIGHEST: return "highest";
     247           0 :   case VK_PPC_HIGHESTA: return "highesta";
     248          24 :   case VK_PPC_GOT_LO: return "got@l";
     249           8 :   case VK_PPC_GOT_HI: return "got@h";
     250           8 :   case VK_PPC_GOT_HA: return "got@ha";
     251        4328 :   case VK_PPC_TOCBASE: return "tocbase";
     252          16 :   case VK_PPC_TOC: return "toc";
     253        2323 :   case VK_PPC_TOC_LO: return "toc@l";
     254           4 :   case VK_PPC_TOC_HI: return "toc@h";
     255        2228 :   case VK_PPC_TOC_HA: return "toc@ha";
     256           2 :   case VK_PPC_DTPMOD: return "dtpmod";
     257          18 :   case VK_PPC_TPREL_LO: return "tprel@l";
     258           4 :   case VK_PPC_TPREL_HI: return "tprel@h";
     259          13 :   case VK_PPC_TPREL_HA: return "tprel@ha";
     260           4 :   case VK_PPC_TPREL_HIGH: return "tprel@high";
     261           4 :   case VK_PPC_TPREL_HIGHA: return "tprel@higha";
     262           4 :   case VK_PPC_TPREL_HIGHER: return "tprel@higher";
     263           4 :   case VK_PPC_TPREL_HIGHERA: return "tprel@highera";
     264           4 :   case VK_PPC_TPREL_HIGHEST: return "tprel@highest";
     265           4 :   case VK_PPC_TPREL_HIGHESTA: return "tprel@highesta";
     266          19 :   case VK_PPC_DTPREL_LO: return "dtprel@l";
     267           4 :   case VK_PPC_DTPREL_HI: return "dtprel@h";
     268          13 :   case VK_PPC_DTPREL_HA: return "dtprel@ha";
     269           4 :   case VK_PPC_DTPREL_HIGH: return "dtprel@high";
     270           4 :   case VK_PPC_DTPREL_HIGHA: return "dtprel@higha";
     271           4 :   case VK_PPC_DTPREL_HIGHER: return "dtprel@higher";
     272           4 :   case VK_PPC_DTPREL_HIGHERA: return "dtprel@highera";
     273           4 :   case VK_PPC_DTPREL_HIGHEST: return "dtprel@highest";
     274           4 :   case VK_PPC_DTPREL_HIGHESTA: return "dtprel@highesta";
     275           8 :   case VK_PPC_GOT_TPREL: return "got@tprel";
     276          23 :   case VK_PPC_GOT_TPREL_LO: return "got@tprel@l";
     277           4 :   case VK_PPC_GOT_TPREL_HI: return "got@tprel@h";
     278          18 :   case VK_PPC_GOT_TPREL_HA: return "got@tprel@ha";
     279           8 :   case VK_PPC_GOT_DTPREL: return "got@dtprel";
     280           8 :   case VK_PPC_GOT_DTPREL_LO: return "got@dtprel@l";
     281           4 :   case VK_PPC_GOT_DTPREL_HI: return "got@dtprel@h";
     282           4 :   case VK_PPC_GOT_DTPREL_HA: return "got@dtprel@ha";
     283          23 :   case VK_PPC_TLS: return "tls";
     284           8 :   case VK_PPC_GOT_TLSGD: return "got@tlsgd";
     285          17 :   case VK_PPC_GOT_TLSGD_LO: return "got@tlsgd@l";
     286           4 :   case VK_PPC_GOT_TLSGD_HI: return "got@tlsgd@h";
     287          17 :   case VK_PPC_GOT_TLSGD_HA: return "got@tlsgd@ha";
     288          21 :   case VK_PPC_TLSGD: return "tlsgd";
     289           7 :   case VK_PPC_GOT_TLSLD: return "got@tlsld";
     290          10 :   case VK_PPC_GOT_TLSLD_LO: return "got@tlsld@l";
     291           4 :   case VK_PPC_GOT_TLSLD_HI: return "got@tlsld@h";
     292          10 :   case VK_PPC_GOT_TLSLD_HA: return "got@tlsld@ha";
     293          13 :   case VK_PPC_TLSLD: return "tlsld";
     294           1 :   case VK_PPC_LOCAL: return "local";
     295         561 :   case VK_COFF_IMGREL32: return "IMGREL";
     296          68 :   case VK_Hexagon_PCREL: return "PCREL";
     297           0 :   case VK_Hexagon_LO16: return "LO16";
     298           0 :   case VK_Hexagon_HI16: return "HI16";
     299           0 :   case VK_Hexagon_GPREL: return "GPREL";
     300          24 :   case VK_Hexagon_GD_GOT: return "GDGOT";
     301           0 :   case VK_Hexagon_LD_GOT: return "LDGOT";
     302          22 :   case VK_Hexagon_GD_PLT: return "GDPLT";
     303           0 :   case VK_Hexagon_LD_PLT: return "LDPLT";
     304           8 :   case VK_Hexagon_IE: return "IE";
     305           4 :   case VK_Hexagon_IE_GOT: return "IEGOT";
     306         415 :   case VK_WebAssembly_FUNCTION: return "FUNCTION";
     307           0 :   case VK_WebAssembly_TYPEINDEX: return "TYPEINDEX";
     308          19 :   case VK_AMDGPU_GOTPCREL32_LO: return "gotpcrel32@lo";
     309          19 :   case VK_AMDGPU_GOTPCREL32_HI: return "gotpcrel32@hi";
     310         471 :   case VK_AMDGPU_REL32_LO: return "rel32@lo";
     311         471 :   case VK_AMDGPU_REL32_HI: return "rel32@hi";
     312           0 :   case VK_AMDGPU_REL64: return "rel64";
     313             :   }
     314           0 :   llvm_unreachable("Invalid variant kind");
     315             : }
     316             : 
     317             : MCSymbolRefExpr::VariantKind
     318        1923 : MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
     319        5769 :   return StringSwitch<VariantKind>(Name.lower())
     320             :     .Case("dtprel", VK_DTPREL)
     321             :     .Case("dtpoff", VK_DTPOFF)
     322             :     .Case("got", VK_GOT)
     323             :     .Case("gotoff", VK_GOTOFF)
     324             :     .Case("gotrel", VK_GOTREL)
     325             :     .Case("gotpcrel", VK_GOTPCREL)
     326             :     .Case("gottpoff", VK_GOTTPOFF)
     327             :     .Case("indntpoff", VK_INDNTPOFF)
     328             :     .Case("ntpoff", VK_NTPOFF)
     329             :     .Case("gotntpoff", VK_GOTNTPOFF)
     330             :     .Case("plt", VK_PLT)
     331             :     .Case("tlscall", VK_TLSCALL)
     332             :     .Case("tlsdesc", VK_TLSDESC)
     333             :     .Case("tlsgd", VK_TLSGD)
     334             :     .Case("tlsld", VK_TLSLD)
     335             :     .Case("tlsldm", VK_TLSLDM)
     336             :     .Case("tpoff", VK_TPOFF)
     337             :     .Case("tprel", VK_TPREL)
     338             :     .Case("tlvp", VK_TLVP)
     339             :     .Case("tlvppage", VK_TLVPPAGE)
     340             :     .Case("tlvppageoff", VK_TLVPPAGEOFF)
     341             :     .Case("page", VK_PAGE)
     342             :     .Case("pageoff", VK_PAGEOFF)
     343             :     .Case("gotpage", VK_GOTPAGE)
     344             :     .Case("gotpageoff", VK_GOTPAGEOFF)
     345             :     .Case("imgrel", VK_COFF_IMGREL32)
     346             :     .Case("secrel32", VK_SECREL)
     347             :     .Case("size", VK_SIZE)
     348             :     .Case("abs8", VK_X86_ABS8)
     349             :     .Case("l", VK_PPC_LO)
     350             :     .Case("h", VK_PPC_HI)
     351             :     .Case("ha", VK_PPC_HA)
     352             :     .Case("high", VK_PPC_HIGH)
     353             :     .Case("higha", VK_PPC_HIGHA)
     354             :     .Case("higher", VK_PPC_HIGHER)
     355             :     .Case("highera", VK_PPC_HIGHERA)
     356             :     .Case("highest", VK_PPC_HIGHEST)
     357             :     .Case("highesta", VK_PPC_HIGHESTA)
     358             :     .Case("got@l", VK_PPC_GOT_LO)
     359             :     .Case("got@h", VK_PPC_GOT_HI)
     360             :     .Case("got@ha", VK_PPC_GOT_HA)
     361             :     .Case("local", VK_PPC_LOCAL)
     362             :     .Case("tocbase", VK_PPC_TOCBASE)
     363             :     .Case("toc", VK_PPC_TOC)
     364             :     .Case("toc@l", VK_PPC_TOC_LO)
     365             :     .Case("toc@h", VK_PPC_TOC_HI)
     366             :     .Case("toc@ha", VK_PPC_TOC_HA)
     367             :     .Case("tls", VK_PPC_TLS)
     368             :     .Case("dtpmod", VK_PPC_DTPMOD)
     369             :     .Case("tprel@l", VK_PPC_TPREL_LO)
     370             :     .Case("tprel@h", VK_PPC_TPREL_HI)
     371             :     .Case("tprel@ha", VK_PPC_TPREL_HA)
     372             :     .Case("tprel@high", VK_PPC_TPREL_HIGH)
     373             :     .Case("tprel@higha", VK_PPC_TPREL_HIGHA)
     374             :     .Case("tprel@higher", VK_PPC_TPREL_HIGHER)
     375             :     .Case("tprel@highera", VK_PPC_TPREL_HIGHERA)
     376             :     .Case("tprel@highest", VK_PPC_TPREL_HIGHEST)
     377             :     .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA)
     378             :     .Case("dtprel@l", VK_PPC_DTPREL_LO)
     379             :     .Case("dtprel@h", VK_PPC_DTPREL_HI)
     380             :     .Case("dtprel@ha", VK_PPC_DTPREL_HA)
     381             :     .Case("dtprel@high", VK_PPC_DTPREL_HIGH)
     382             :     .Case("dtprel@higha", VK_PPC_DTPREL_HIGHA)
     383             :     .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER)
     384             :     .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA)
     385             :     .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST)
     386             :     .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA)
     387             :     .Case("got@tprel", VK_PPC_GOT_TPREL)
     388             :     .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO)
     389             :     .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI)
     390             :     .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA)
     391             :     .Case("got@dtprel", VK_PPC_GOT_DTPREL)
     392             :     .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO)
     393             :     .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI)
     394             :     .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA)
     395             :     .Case("got@tlsgd", VK_PPC_GOT_TLSGD)
     396             :     .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO)
     397             :     .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI)
     398             :     .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
     399             :     .Case("got@tlsld", VK_PPC_GOT_TLSLD)
     400             :     .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO)
     401             :     .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI)
     402             :     .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA)
     403             :     .Case("gdgot", VK_Hexagon_GD_GOT)
     404             :     .Case("gdplt", VK_Hexagon_GD_PLT)
     405             :     .Case("iegot", VK_Hexagon_IE_GOT)
     406             :     .Case("ie", VK_Hexagon_IE)
     407             :     .Case("ldgot", VK_Hexagon_LD_GOT)
     408             :     .Case("ldplt", VK_Hexagon_LD_PLT)
     409             :     .Case("pcrel", VK_Hexagon_PCREL)
     410             :     .Case("none", VK_ARM_NONE)
     411             :     .Case("got_prel", VK_ARM_GOT_PREL)
     412             :     .Case("target1", VK_ARM_TARGET1)
     413             :     .Case("target2", VK_ARM_TARGET2)
     414             :     .Case("prel31", VK_ARM_PREL31)
     415             :     .Case("sbrel", VK_ARM_SBREL)
     416             :     .Case("tlsldo", VK_ARM_TLSLDO)
     417             :     .Case("lo8", VK_AVR_LO8)
     418             :     .Case("hi8", VK_AVR_HI8)
     419             :     .Case("hlo8", VK_AVR_HLO8)
     420             :     .Case("function", VK_WebAssembly_FUNCTION)
     421             :     .Case("typeindex", VK_WebAssembly_TYPEINDEX)
     422             :     .Case("gotpcrel32@lo", VK_AMDGPU_GOTPCREL32_LO)
     423             :     .Case("gotpcrel32@hi", VK_AMDGPU_GOTPCREL32_HI)
     424             :     .Case("rel32@lo", VK_AMDGPU_REL32_LO)
     425             :     .Case("rel32@hi", VK_AMDGPU_REL32_HI)
     426             :     .Case("rel64", VK_AMDGPU_REL64)
     427        1923 :     .Default(VK_Invalid);
     428             : }
     429             : 
     430       15908 : void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const {
     431       15908 :   if (UseParensForSymbolVariant)
     432         191 :     OS << '(' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')';
     433             :   else
     434       15717 :     OS << '@' << MCSymbolRefExpr::getVariantKindName(getKind());
     435       15908 : }
     436             : 
     437             : /* *** */
     438             : 
     439           0 : void MCTargetExpr::anchor() {}
     440             : 
     441             : /* *** */
     442             : 
     443      724378 : bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
     444      724378 :   return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr);
     445             : }
     446             : 
     447      400233 : bool MCExpr::evaluateAsAbsolute(int64_t &Res,
     448             :                                 const MCAsmLayout &Layout) const {
     449      400233 :   return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr);
     450             : }
     451             : 
     452         316 : bool MCExpr::evaluateAsAbsolute(int64_t &Res,
     453             :                                 const MCAsmLayout &Layout,
     454             :                                 const SectionAddrMap &Addrs) const {
     455         316 :   return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs);
     456             : }
     457             : 
     458          72 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
     459          72 :   return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
     460             : }
     461             : 
     462     3101680 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
     463     3101680 :   return evaluateAsAbsolute(Res, Asm, nullptr, nullptr);
     464             : }
     465             : 
     466     3554763 : bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
     467             :                                    const MCAsmLayout &Layout) const {
     468     3554763 :   return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr,
     469     3554763 :                             true);
     470             : }
     471             : 
     472     4226679 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
     473             :                                 const MCAsmLayout *Layout,
     474             :                                 const SectionAddrMap *Addrs) const {
     475             :   // FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us
     476             :   // absolutize differences across sections and that is what the MachO writer
     477             :   // uses Addrs for.
     478     4226679 :   return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs);
     479             : }
     480             : 
     481     7781442 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
     482             :                                 const MCAsmLayout *Layout,
     483             :                                 const SectionAddrMap *Addrs, bool InSet) const {
     484     7781442 :   MCValue Value;
     485             : 
     486             :   // Fast path constants.
     487             :   if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) {
     488     1343088 :     Res = CE->getValue();
     489     1343088 :     return true;
     490             :   }
     491             : 
     492             :   bool IsRelocatable =
     493     6438354 :       evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
     494             : 
     495             :   // Record the current value.
     496     6438354 :   Res = Value.getConstant();
     497             : 
     498     6438354 :   return IsRelocatable && Value.isAbsolute();
     499             : }
     500             : 
     501             : /// Helper method for \see EvaluateSymbolAdd().
     502    18751524 : static void AttemptToFoldSymbolOffsetDifference(
     503             :     const MCAssembler *Asm, const MCAsmLayout *Layout,
     504             :     const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A,
     505             :     const MCSymbolRefExpr *&B, int64_t &Addend) {
     506    18751524 :   if (!A || !B)
     507             :     return;
     508             : 
     509     3734283 :   const MCSymbol &SA = A->getSymbol();
     510     3734283 :   const MCSymbol &SB = B->getSymbol();
     511             : 
     512     7465807 :   if (SA.isUndefined() || SB.isUndefined())
     513             :     return;
     514             : 
     515     3731495 :   if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
     516             :     return;
     517             : 
     518     6759743 :   if (SA.getFragment() == SB.getFragment() && !SA.isVariable() &&
     519     6759732 :       !SA.isUnset() && !SB.isVariable() && !SB.isUnset()) {
     520     3076697 :     Addend += (SA.getOffset() - SB.getOffset());
     521             : 
     522             :     // Pointers to Thumb symbols need to have their low-bit set to allow
     523             :     // for interworking.
     524     3076697 :     if (Asm->isThumbFunc(&SA))
     525           0 :       Addend |= 1;
     526             : 
     527             :     // Clear the symbol expr pointers to indicate we have folded these
     528             :     // operands.
     529     3076697 :     A = B = nullptr;
     530     3076697 :     return;
     531             :   }
     532             : 
     533      606227 :   if (!Layout)
     534             :     return;
     535             : 
     536      605289 :   const MCSection &SecA = *SA.getFragment()->getParent();
     537      605289 :   const MCSection &SecB = *SB.getFragment()->getParent();
     538             : 
     539      605289 :   if ((&SecA != &SecB) && !Addrs)
     540             :     return;
     541             : 
     542             :   // Eagerly evaluate.
     543     1209334 :   Addend += Layout->getSymbolOffset(A->getSymbol()) -
     544      604667 :             Layout->getSymbolOffset(B->getSymbol());
     545      604667 :   if (Addrs && (&SecA != &SecB))
     546         311 :     Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
     547             : 
     548             :   // Pointers to Thumb symbols need to have their low-bit set to allow
     549             :   // for interworking.
     550      604667 :   if (Asm->isThumbFunc(&SA))
     551           0 :     Addend |= 1;
     552             : 
     553             :   // Clear the symbol expr pointers to indicate we have folded these
     554             :   // operands.
     555      604667 :   A = B = nullptr;
     556             : }
     557             : 
     558             : /// Evaluate the result of an add between (conceptually) two MCValues.
     559             : ///
     560             : /// This routine conceptually attempts to construct an MCValue:
     561             : ///   Result = (Result_A - Result_B + Result_Cst)
     562             : /// from two MCValue's LHS and RHS where
     563             : ///   Result = LHS + RHS
     564             : /// and
     565             : ///   Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
     566             : ///
     567             : /// This routine attempts to aggresively fold the operands such that the result
     568             : /// is representable in an MCValue, but may not always succeed.
     569             : ///
     570             : /// \returns True on success, false if the result is not representable in an
     571             : /// MCValue.
     572             : 
     573             : /// NOTE: It is really important to have both the Asm and Layout arguments.
     574             : /// They might look redundant, but this function can be used before layout
     575             : /// is done (see the object streamer for example) and having the Asm argument
     576             : /// lets us avoid relaxations early.
     577             : static bool
     578     6156377 : EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
     579             :                     const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS,
     580             :                     const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B,
     581             :                     int64_t RHS_Cst, MCValue &Res) {
     582             :   // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
     583             :   // about dealing with modifiers. This will ultimately bite us, one day.
     584     6156377 :   const MCSymbolRefExpr *LHS_A = LHS.getSymA();
     585     6156377 :   const MCSymbolRefExpr *LHS_B = LHS.getSymB();
     586     6156377 :   int64_t LHS_Cst = LHS.getConstant();
     587             : 
     588             :   // Fold the result constant immediately.
     589     6156377 :   int64_t Result_Cst = LHS_Cst + RHS_Cst;
     590             : 
     591             :   assert((!Layout || Asm) &&
     592             :          "Must have an assembler object if layout is given!");
     593             : 
     594             :   // If we have a layout, we can fold resolved differences. Do not do this if
     595             :   // the backend requires this to be emitted as individual relocations, unless
     596             :   // the InSet flag is set to get the current difference anyway (used for
     597             :   // example to calculate symbol sizes).
     598     6156377 :   if (Asm &&
     599     1179631 :       (InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) {
     600             :     // First, fold out any differences which are fully resolved. By
     601             :     // reassociating terms in
     602             :     //   Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
     603             :     // we have the four possible differences:
     604             :     //   (LHS_A - LHS_B),
     605             :     //   (LHS_A - RHS_B),
     606             :     //   (RHS_A - LHS_B),
     607             :     //   (RHS_A - RHS_B).
     608             :     // Since we are attempting to be as aggressive as possible about folding, we
     609             :     // attempt to evaluate each possible alternative.
     610     4687881 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B,
     611             :                                         Result_Cst);
     612     4687881 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B,
     613             :                                         Result_Cst);
     614     4687881 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B,
     615             :                                         Result_Cst);
     616     4687881 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B,
     617             :                                         Result_Cst);
     618             :   }
     619             : 
     620             :   // We can't represent the addition or subtraction of two symbols.
     621     6156377 :   if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
     622             :     return false;
     623             : 
     624             :   // At this point, we have at most one additive symbol and one subtractive
     625             :   // symbol -- find them.
     626     6156162 :   const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
     627     6156162 :   const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
     628             : 
     629     6156162 :   Res = MCValue::get(A, B, Result_Cst);
     630     6156162 :   return true;
     631             : }
     632             : 
     633     2832133 : bool MCExpr::evaluateAsRelocatable(MCValue &Res,
     634             :                                    const MCAsmLayout *Layout,
     635             :                                    const MCFixup *Fixup) const {
     636     2832133 :   MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr;
     637             :   return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
     638     2832133 :                                    false);
     639             : }
     640             : 
     641        1876 : bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
     642        1876 :   MCAssembler *Assembler = &Layout.getAssembler();
     643             :   return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
     644        1876 :                                    true);
     645             : }
     646             : 
     647        9625 : static bool canExpand(const MCSymbol &Sym, bool InSet) {
     648             :   const MCExpr *Expr = Sym.getVariableValue();
     649             :   const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
     650             :   if (Inner) {
     651         409 :     if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
     652             :       return false;
     653             :   }
     654             : 
     655        9596 :   if (InSet)
     656             :     return true;
     657        9566 :   return !Sym.isInSection();
     658             : }
     659             : 
     660    21912832 : bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
     661             :                                        const MCAsmLayout *Layout,
     662             :                                        const MCFixup *Fixup,
     663             :                                        const SectionAddrMap *Addrs,
     664             :                                        bool InSet) const {
     665             :   ++stats::MCExprEvaluate;
     666             : 
     667    21912832 :   switch (getKind()) {
     668             :   case Target:
     669             :     return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout,
     670      108703 :                                                                Fixup);
     671             : 
     672             :   case Constant:
     673     1380891 :     Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
     674     1380891 :     return true;
     675             : 
     676             :   case SymbolRef: {
     677             :     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
     678    14097934 :     const MCSymbol &Sym = SRE->getSymbol();
     679             : 
     680             :     // Evaluate recursively if this is a variable.
     681    14107559 :     if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None &&
     682        9625 :         canExpand(Sym, InSet)) {
     683             :       bool IsMachO = SRE->hasSubsectionsViaSymbols();
     684        9240 :       if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
     685        9240 :               Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
     686        9240 :         if (!IsMachO)
     687             :           return true;
     688             : 
     689        8940 :         const MCSymbolRefExpr *A = Res.getSymA();
     690        8940 :         const MCSymbolRefExpr *B = Res.getSymB();
     691             :         // FIXME: This is small hack. Given
     692             :         // a = b + 4
     693             :         // .long a
     694             :         // the OS X assembler will completely drop the 4. We should probably
     695             :         // include it in the relocation or produce an error if that is not
     696             :         // possible.
     697             :         // Allow constant expressions.
     698        8940 :         if (!A && !B)
     699             :           return true;
     700             :         // Allows aliases with zero offset.
     701        4777 :         if (Res.getConstant() == 0 && (!A || !B))
     702             :           return true;
     703             :       }
     704             :     }
     705             : 
     706    14093458 :     Res = MCValue::get(SRE, nullptr, 0);
     707    14093458 :     return true;
     708             :   }
     709             : 
     710             :   case Unary: {
     711             :     const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
     712       19298 :     MCValue Value;
     713             : 
     714       19298 :     if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
     715             :                                                       Addrs, InSet))
     716             :       return false;
     717             : 
     718       19296 :     switch (AUE->getOpcode()) {
     719           4 :     case MCUnaryExpr::LNot:
     720           4 :       if (!Value.isAbsolute())
     721             :         return false;
     722           4 :       Res = MCValue::get(!Value.getConstant());
     723           4 :       break;
     724       19115 :     case MCUnaryExpr::Minus:
     725             :       /// -(a - b + const) ==> (b - a - const)
     726       19115 :       if (Value.getSymA() && !Value.getSymB())
     727             :         return false;
     728             : 
     729             :       // The cast avoids undefined behavior if the constant is INT64_MIN.
     730       18861 :       Res = MCValue::get(Value.getSymB(), Value.getSymA(),
     731       18861 :                          -(uint64_t)Value.getConstant());
     732       18861 :       break;
     733         148 :     case MCUnaryExpr::Not:
     734         148 :       if (!Value.isAbsolute())
     735             :         return false;
     736         147 :       Res = MCValue::get(~Value.getConstant());
     737         147 :       break;
     738          29 :     case MCUnaryExpr::Plus:
     739          29 :       Res = Value;
     740          29 :       break;
     741             :     }
     742             : 
     743             :     return true;
     744             :   }
     745             : 
     746             :   case Binary: {
     747             :     const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
     748     6306006 :     MCValue LHSValue, RHSValue;
     749             : 
     750     6306006 :     if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
     751    12611931 :                                                   Addrs, InSet) ||
     752     6305925 :         !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
     753             :                                                   Addrs, InSet))
     754             :       return false;
     755             : 
     756             :     // We only support a few operations on non-constant expressions, handle
     757             :     // those first.
     758     6455433 :     if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
     759     6156582 :       switch (ABE->getOpcode()) {
     760             :       default:
     761             :         return false;
     762     5151752 :       case MCBinaryExpr::Sub:
     763             :         // Negate RHS and add.
     764             :         // The cast avoids undefined behavior if the constant is INT64_MIN.
     765     5151752 :         return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
     766             :                                    RHSValue.getSymB(), RHSValue.getSymA(),
     767    10303504 :                                    -(uint64_t)RHSValue.getConstant(), Res);
     768             : 
     769     1004625 :       case MCBinaryExpr::Add:
     770     1004625 :         return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
     771             :                                    RHSValue.getSymA(), RHSValue.getSymB(),
     772     1004625 :                                    RHSValue.getConstant(), Res);
     773             :       }
     774             :     }
     775             : 
     776             :     // FIXME: We need target hooks for the evaluation. It may be limited in
     777             :     // width, and gas defines the result of comparisons differently from
     778             :     // Apple as.
     779      149337 :     int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
     780             :     int64_t Result = 0;
     781      149337 :     auto Op = ABE->getOpcode();
     782      149337 :     switch (Op) {
     783           1 :     case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
     784         445 :     case MCBinaryExpr::Add:  Result = LHS + RHS; break;
     785          37 :     case MCBinaryExpr::And:  Result = LHS & RHS; break;
     786         149 :     case MCBinaryExpr::Div:
     787             :     case MCBinaryExpr::Mod:
     788             :       // Handle division by zero. gas just emits a warning and keeps going,
     789             :       // we try to be stricter.
     790             :       // FIXME: Currently the caller of this function has no way to understand
     791             :       // we're bailing out because of 'division by zero'. Therefore, it will
     792             :       // emit a 'expected relocatable expression' error. It would be nice to
     793             :       // change this code to emit a better diagnostic.
     794         149 :       if (RHS == 0)
     795             :         return false;
     796         143 :       if (ABE->getOpcode() == MCBinaryExpr::Div)
     797         138 :         Result = LHS / RHS;
     798             :       else
     799           5 :         Result = LHS % RHS;
     800             :       break;
     801          29 :     case MCBinaryExpr::EQ:   Result = LHS == RHS; break;
     802           6 :     case MCBinaryExpr::GT:   Result = LHS > RHS; break;
     803           1 :     case MCBinaryExpr::GTE:  Result = LHS >= RHS; break;
     804           3 :     case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
     805           4 :     case MCBinaryExpr::LOr:  Result = LHS || RHS; break;
     806          27 :     case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break;
     807           4 :     case MCBinaryExpr::LT:   Result = LHS < RHS; break;
     808           1 :     case MCBinaryExpr::LTE:  Result = LHS <= RHS; break;
     809         232 :     case MCBinaryExpr::Mul:  Result = LHS * RHS; break;
     810          42 :     case MCBinaryExpr::NE:   Result = LHS != RHS; break;
     811         108 :     case MCBinaryExpr::Or:   Result = LHS | RHS; break;
     812         266 :     case MCBinaryExpr::Shl:  Result = uint64_t(LHS) << uint64_t(RHS); break;
     813      147980 :     case MCBinaryExpr::Sub:  Result = LHS - RHS; break;
     814           2 :     case MCBinaryExpr::Xor:  Result = LHS ^ RHS; break;
     815             :     }
     816             : 
     817             :     switch (Op) {
     818             :     default:
     819      149248 :       Res = MCValue::get(Result);
     820      149248 :       break;
     821          83 :     case MCBinaryExpr::EQ:
     822             :     case MCBinaryExpr::GT:
     823             :     case MCBinaryExpr::GTE:
     824             :     case MCBinaryExpr::LT:
     825             :     case MCBinaryExpr::LTE:
     826             :     case MCBinaryExpr::NE:
     827             :       // A comparison operator returns a -1 if true and 0 if false.
     828          83 :       Res = MCValue::get(Result ? -1 : 0);
     829          83 :       break;
     830             :     }
     831             : 
     832             :     return true;
     833             :   }
     834             :   }
     835             : 
     836           0 :   llvm_unreachable("Invalid assembly expression kind!");
     837             : }
     838             : 
     839       18009 : MCFragment *MCExpr::findAssociatedFragment() const {
     840       18011 :   switch (getKind()) {
     841             :   case Target:
     842             :     // We never look through target specific expressions.
     843           0 :     return cast<MCTargetExpr>(this)->findAssociatedFragment();
     844             : 
     845        2132 :   case Constant:
     846        2132 :     return MCSymbol::AbsolutePseudoFragment;
     847             : 
     848             :   case SymbolRef: {
     849             :     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
     850        9536 :     const MCSymbol &Sym = SRE->getSymbol();
     851        9536 :     return Sym.getFragment();
     852             :   }
     853             : 
     854             :   case Unary:
     855           2 :     return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedFragment();
     856             : 
     857             :   case Binary: {
     858             :     const MCBinaryExpr *BE = cast<MCBinaryExpr>(this);
     859        6341 :     MCFragment *LHS_F = BE->getLHS()->findAssociatedFragment();
     860        6341 :     MCFragment *RHS_F = BE->getRHS()->findAssociatedFragment();
     861             : 
     862             :     // If either is absolute, return the other.
     863        6341 :     if (LHS_F == MCSymbol::AbsolutePseudoFragment)
     864             :       return RHS_F;
     865        4595 :     if (RHS_F == MCSymbol::AbsolutePseudoFragment)
     866             :       return LHS_F;
     867             : 
     868             :     // Not always correct, but probably the best we can do without more context.
     869        4501 :     if (BE->getOpcode() == MCBinaryExpr::Sub)
     870             :       return MCSymbol::AbsolutePseudoFragment;
     871             : 
     872             :     // Otherwise, return the first non-null fragment.
     873           1 :     return LHS_F ? LHS_F : RHS_F;
     874             :   }
     875             :   }
     876             : 
     877           0 :   llvm_unreachable("Invalid assembly expression kind!");
     878             : }

Generated by: LCOV version 1.13