LCOV - code coverage report
Current view: top level - lib/MC - MCExpr.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 318 365 87.1 %
Date: 2018-09-23 13:06:45 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     1248177 : void MCExpr::print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens) const {
      43     1248177 :   switch (getKind()) {
      44             :   case MCExpr::Target:
      45       53862 :     return cast<MCTargetExpr>(this)->printImpl(OS, MAI);
      46             :   case MCExpr::Constant:
      47      477805 :     OS << cast<MCConstantExpr>(*this).getValue();
      48      477805 :     return;
      49             : 
      50             :   case MCExpr::SymbolRef: {
      51             :     const MCSymbolRefExpr &SRE = cast<MCSymbolRefExpr>(*this);
      52      523668 :     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     1017427 :         !InParens && !Sym.getName().empty() && Sym.getName()[0] == '$';
      57             :     if (UseParens) {
      58             :       OS << '(';
      59        9211 :       Sym.print(OS, MAI);
      60             :       OS << ')';
      61             :     } else
      62      514457 :       Sym.print(OS, MAI);
      63             : 
      64      523668 :     if (SRE.getKind() != MCSymbolRefExpr::VK_None)
      65       16927 :       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      385672 :     if (isa<MCConstantExpr>(BE.getLHS()) || isa<MCSymbolRefExpr>(BE.getLHS())) {
      90      191869 :       BE.getLHS()->print(OS, MAI);
      91             :     } else {
      92             :       OS << '(';
      93         967 :       BE.getLHS()->print(OS, MAI);
      94             :       OS << ')';
      95             :     }
      96             : 
      97      192836 :     switch (BE.getOpcode()) {
      98       11794 :     case MCBinaryExpr::Add:
      99             :       // Print "X-42" instead of "X+-42".
     100       11794 :       if (const MCConstantExpr *RHSC = dyn_cast<MCConstantExpr>(BE.getRHS())) {
     101       11511 :         if (RHSC->getValue() < 0) {
     102        1290 :           OS << RHSC->getValue();
     103        1290 :           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      383092 :     if (isa<MCConstantExpr>(BE.getRHS()) || isa<MCSymbolRefExpr>(BE.getRHS())) {
     131      189308 :       BE.getRHS()->print(OS, MAI);
     132             :     } else {
     133             :       OS << '(';
     134        2238 :       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     9212767 : const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS,
     154             :                                          const MCExpr *RHS, MCContext &Ctx,
     155             :                                          SMLoc Loc) {
     156     9212767 :   return new (Ctx) MCBinaryExpr(Opc, LHS, RHS, Loc);
     157             : }
     158             : 
     159       20139 : const MCUnaryExpr *MCUnaryExpr::create(Opcode Opc, const MCExpr *Expr,
     160             :                                        MCContext &Ctx, SMLoc Loc) {
     161       20139 :   return new (Ctx) MCUnaryExpr(Opc, Expr, Loc);
     162             : }
     163             : 
     164     7907374 : const MCConstantExpr *MCConstantExpr::create(int64_t Value, MCContext &Ctx) {
     165     7907374 :   return new (Ctx) MCConstantExpr(Value);
     166             : }
     167             : 
     168             : /* *** */
     169             : 
     170    14811506 : MCSymbolRefExpr::MCSymbolRefExpr(const MCSymbol *Symbol, VariantKind Kind,
     171    14811506 :                                  const MCAsmInfo *MAI, SMLoc Loc)
     172             :     : MCExpr(MCExpr::SymbolRef, Loc), Kind(Kind),
     173    14811506 :       UseParensForSymbolVariant(MAI->useParensForSymbolVariant()),
     174    14811506 :       HasSubsectionsViaSymbols(MAI->hasSubsectionsViaSymbols()),
     175    44434518 :       Symbol(Symbol) {
     176             :   assert(Symbol);
     177    14811506 : }
     178             : 
     179    14811507 : const MCSymbolRefExpr *MCSymbolRefExpr::create(const MCSymbol *Sym,
     180             :                                                VariantKind Kind,
     181             :                                                MCContext &Ctx, SMLoc Loc) {
     182    14811507 :   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       16934 : StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
     191       16934 :   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         175 :   case VK_GOT: return "GOT";
     198         159 :   case VK_GOTOFF: return "GOTOFF";
     199           0 :   case VK_GOTREL: return "GOTREL";
     200        1063 :   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        1776 :   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          66 :   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        4411 :   case VK_PPC_TOCBASE: return "tocbase";
     252          16 :   case VK_PPC_TOC: return "toc";
     253        2466 :   case VK_PPC_TOC_LO: return "toc@l";
     254           4 :   case VK_PPC_TOC_HI: return "toc@h";
     255        2371 :   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         505 :   case VK_WebAssembly_FUNCTION: return "FUNCTION";
     307         231 :   case VK_WebAssembly_GLOBAL: return "GLOBAL";
     308           1 :   case VK_WebAssembly_TYPEINDEX: return "TYPEINDEX";
     309          19 :   case VK_AMDGPU_GOTPCREL32_LO: return "gotpcrel32@lo";
     310          19 :   case VK_AMDGPU_GOTPCREL32_HI: return "gotpcrel32@hi";
     311         561 :   case VK_AMDGPU_REL32_LO: return "rel32@lo";
     312         561 :   case VK_AMDGPU_REL32_HI: return "rel32@hi";
     313           0 :   case VK_AMDGPU_REL64: return "rel64";
     314             :   }
     315           0 :   llvm_unreachable("Invalid variant kind");
     316             : }
     317             : 
     318             : MCSymbolRefExpr::VariantKind
     319        2142 : MCSymbolRefExpr::getVariantKindForName(StringRef Name) {
     320        4284 :   return StringSwitch<VariantKind>(Name.lower())
     321             :     .Case("dtprel", VK_DTPREL)
     322             :     .Case("dtpoff", VK_DTPOFF)
     323             :     .Case("got", VK_GOT)
     324             :     .Case("gotoff", VK_GOTOFF)
     325             :     .Case("gotrel", VK_GOTREL)
     326             :     .Case("gotpcrel", VK_GOTPCREL)
     327             :     .Case("gottpoff", VK_GOTTPOFF)
     328             :     .Case("indntpoff", VK_INDNTPOFF)
     329             :     .Case("ntpoff", VK_NTPOFF)
     330             :     .Case("gotntpoff", VK_GOTNTPOFF)
     331             :     .Case("plt", VK_PLT)
     332             :     .Case("tlscall", VK_TLSCALL)
     333             :     .Case("tlsdesc", VK_TLSDESC)
     334             :     .Case("tlsgd", VK_TLSGD)
     335             :     .Case("tlsld", VK_TLSLD)
     336             :     .Case("tlsldm", VK_TLSLDM)
     337             :     .Case("tpoff", VK_TPOFF)
     338             :     .Case("tprel", VK_TPREL)
     339             :     .Case("tlvp", VK_TLVP)
     340             :     .Case("tlvppage", VK_TLVPPAGE)
     341             :     .Case("tlvppageoff", VK_TLVPPAGEOFF)
     342             :     .Case("page", VK_PAGE)
     343             :     .Case("pageoff", VK_PAGEOFF)
     344             :     .Case("gotpage", VK_GOTPAGE)
     345             :     .Case("gotpageoff", VK_GOTPAGEOFF)
     346             :     .Case("imgrel", VK_COFF_IMGREL32)
     347             :     .Case("secrel32", VK_SECREL)
     348             :     .Case("size", VK_SIZE)
     349             :     .Case("abs8", VK_X86_ABS8)
     350             :     .Case("l", VK_PPC_LO)
     351             :     .Case("h", VK_PPC_HI)
     352             :     .Case("ha", VK_PPC_HA)
     353             :     .Case("high", VK_PPC_HIGH)
     354             :     .Case("higha", VK_PPC_HIGHA)
     355             :     .Case("higher", VK_PPC_HIGHER)
     356             :     .Case("highera", VK_PPC_HIGHERA)
     357             :     .Case("highest", VK_PPC_HIGHEST)
     358             :     .Case("highesta", VK_PPC_HIGHESTA)
     359             :     .Case("got@l", VK_PPC_GOT_LO)
     360             :     .Case("got@h", VK_PPC_GOT_HI)
     361             :     .Case("got@ha", VK_PPC_GOT_HA)
     362             :     .Case("local", VK_PPC_LOCAL)
     363             :     .Case("tocbase", VK_PPC_TOCBASE)
     364             :     .Case("toc", VK_PPC_TOC)
     365             :     .Case("toc@l", VK_PPC_TOC_LO)
     366             :     .Case("toc@h", VK_PPC_TOC_HI)
     367             :     .Case("toc@ha", VK_PPC_TOC_HA)
     368             :     .Case("tls", VK_PPC_TLS)
     369             :     .Case("dtpmod", VK_PPC_DTPMOD)
     370             :     .Case("tprel@l", VK_PPC_TPREL_LO)
     371             :     .Case("tprel@h", VK_PPC_TPREL_HI)
     372             :     .Case("tprel@ha", VK_PPC_TPREL_HA)
     373             :     .Case("tprel@high", VK_PPC_TPREL_HIGH)
     374             :     .Case("tprel@higha", VK_PPC_TPREL_HIGHA)
     375             :     .Case("tprel@higher", VK_PPC_TPREL_HIGHER)
     376             :     .Case("tprel@highera", VK_PPC_TPREL_HIGHERA)
     377             :     .Case("tprel@highest", VK_PPC_TPREL_HIGHEST)
     378             :     .Case("tprel@highesta", VK_PPC_TPREL_HIGHESTA)
     379             :     .Case("dtprel@l", VK_PPC_DTPREL_LO)
     380             :     .Case("dtprel@h", VK_PPC_DTPREL_HI)
     381             :     .Case("dtprel@ha", VK_PPC_DTPREL_HA)
     382             :     .Case("dtprel@high", VK_PPC_DTPREL_HIGH)
     383             :     .Case("dtprel@higha", VK_PPC_DTPREL_HIGHA)
     384             :     .Case("dtprel@higher", VK_PPC_DTPREL_HIGHER)
     385             :     .Case("dtprel@highera", VK_PPC_DTPREL_HIGHERA)
     386             :     .Case("dtprel@highest", VK_PPC_DTPREL_HIGHEST)
     387             :     .Case("dtprel@highesta", VK_PPC_DTPREL_HIGHESTA)
     388             :     .Case("got@tprel", VK_PPC_GOT_TPREL)
     389             :     .Case("got@tprel@l", VK_PPC_GOT_TPREL_LO)
     390             :     .Case("got@tprel@h", VK_PPC_GOT_TPREL_HI)
     391             :     .Case("got@tprel@ha", VK_PPC_GOT_TPREL_HA)
     392             :     .Case("got@dtprel", VK_PPC_GOT_DTPREL)
     393             :     .Case("got@dtprel@l", VK_PPC_GOT_DTPREL_LO)
     394             :     .Case("got@dtprel@h", VK_PPC_GOT_DTPREL_HI)
     395             :     .Case("got@dtprel@ha", VK_PPC_GOT_DTPREL_HA)
     396             :     .Case("got@tlsgd", VK_PPC_GOT_TLSGD)
     397             :     .Case("got@tlsgd@l", VK_PPC_GOT_TLSGD_LO)
     398             :     .Case("got@tlsgd@h", VK_PPC_GOT_TLSGD_HI)
     399             :     .Case("got@tlsgd@ha", VK_PPC_GOT_TLSGD_HA)
     400             :     .Case("got@tlsld", VK_PPC_GOT_TLSLD)
     401             :     .Case("got@tlsld@l", VK_PPC_GOT_TLSLD_LO)
     402             :     .Case("got@tlsld@h", VK_PPC_GOT_TLSLD_HI)
     403             :     .Case("got@tlsld@ha", VK_PPC_GOT_TLSLD_HA)
     404             :     .Case("gdgot", VK_Hexagon_GD_GOT)
     405             :     .Case("gdplt", VK_Hexagon_GD_PLT)
     406             :     .Case("iegot", VK_Hexagon_IE_GOT)
     407             :     .Case("ie", VK_Hexagon_IE)
     408             :     .Case("ldgot", VK_Hexagon_LD_GOT)
     409             :     .Case("ldplt", VK_Hexagon_LD_PLT)
     410             :     .Case("pcrel", VK_Hexagon_PCREL)
     411             :     .Case("none", VK_ARM_NONE)
     412             :     .Case("got_prel", VK_ARM_GOT_PREL)
     413             :     .Case("target1", VK_ARM_TARGET1)
     414             :     .Case("target2", VK_ARM_TARGET2)
     415             :     .Case("prel31", VK_ARM_PREL31)
     416             :     .Case("sbrel", VK_ARM_SBREL)
     417             :     .Case("tlsldo", VK_ARM_TLSLDO)
     418             :     .Case("lo8", VK_AVR_LO8)
     419             :     .Case("hi8", VK_AVR_HI8)
     420             :     .Case("hlo8", VK_AVR_HLO8)
     421             :     .Case("function", VK_WebAssembly_FUNCTION)
     422             :     .Case("typeindex", VK_WebAssembly_TYPEINDEX)
     423             :     .Case("gotpcrel32@lo", VK_AMDGPU_GOTPCREL32_LO)
     424             :     .Case("gotpcrel32@hi", VK_AMDGPU_GOTPCREL32_HI)
     425             :     .Case("rel32@lo", VK_AMDGPU_REL32_LO)
     426             :     .Case("rel32@hi", VK_AMDGPU_REL32_HI)
     427             :     .Case("rel64", VK_AMDGPU_REL64)
     428        2142 :     .Default(VK_Invalid);
     429             : }
     430             : 
     431       16927 : void MCSymbolRefExpr::printVariantKind(raw_ostream &OS) const {
     432       16927 :   if (UseParensForSymbolVariant)
     433         194 :     OS << '(' << MCSymbolRefExpr::getVariantKindName(getKind()) << ')';
     434             :   else
     435       16733 :     OS << '@' << MCSymbolRefExpr::getVariantKindName(getKind());
     436       16927 : }
     437             : 
     438             : /* *** */
     439             : 
     440           0 : void MCTargetExpr::anchor() {}
     441             : 
     442             : /* *** */
     443             : 
     444      741663 : bool MCExpr::evaluateAsAbsolute(int64_t &Res) const {
     445      741663 :   return evaluateAsAbsolute(Res, nullptr, nullptr, nullptr);
     446             : }
     447             : 
     448      553561 : bool MCExpr::evaluateAsAbsolute(int64_t &Res,
     449             :                                 const MCAsmLayout &Layout) const {
     450      553561 :   return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr);
     451             : }
     452             : 
     453         329 : bool MCExpr::evaluateAsAbsolute(int64_t &Res,
     454             :                                 const MCAsmLayout &Layout,
     455             :                                 const SectionAddrMap &Addrs) const {
     456         329 :   return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, &Addrs);
     457             : }
     458             : 
     459          95 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const {
     460          95 :   return evaluateAsAbsolute(Res, &Asm, nullptr, nullptr);
     461             : }
     462             : 
     463     5384224 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm) const {
     464     5384224 :   return evaluateAsAbsolute(Res, Asm, nullptr, nullptr);
     465             : }
     466             : 
     467     7334970 : bool MCExpr::evaluateKnownAbsolute(int64_t &Res,
     468             :                                    const MCAsmLayout &Layout) const {
     469     7334970 :   return evaluateAsAbsolute(Res, &Layout.getAssembler(), &Layout, nullptr,
     470     7334970 :                             true);
     471             : }
     472             : 
     473     6679872 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
     474             :                                 const MCAsmLayout *Layout,
     475             :                                 const SectionAddrMap *Addrs) const {
     476             :   // FIXME: The use if InSet = Addrs is a hack. Setting InSet causes us
     477             :   // absolutize differences across sections and that is what the MachO writer
     478             :   // uses Addrs for.
     479     6679872 :   return evaluateAsAbsolute(Res, Asm, Layout, Addrs, Addrs);
     480             : }
     481             : 
     482    14014842 : bool MCExpr::evaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
     483             :                                 const MCAsmLayout *Layout,
     484             :                                 const SectionAddrMap *Addrs, bool InSet) const {
     485    14014842 :   MCValue Value;
     486             : 
     487             :   // Fast path constants.
     488             :   if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(this)) {
     489     1557938 :     Res = CE->getValue();
     490     1557938 :     return true;
     491             :   }
     492             : 
     493             :   bool IsRelocatable =
     494    12456904 :       evaluateAsRelocatableImpl(Value, Asm, Layout, nullptr, Addrs, InSet);
     495             : 
     496             :   // Record the current value.
     497    12456904 :   Res = Value.getConstant();
     498             : 
     499    12456904 :   return IsRelocatable && Value.isAbsolute();
     500             : }
     501             : 
     502             : /// Helper method for \see EvaluateSymbolAdd().
     503    54363056 : static void AttemptToFoldSymbolOffsetDifference(
     504             :     const MCAssembler *Asm, const MCAsmLayout *Layout,
     505             :     const SectionAddrMap *Addrs, bool InSet, const MCSymbolRefExpr *&A,
     506             :     const MCSymbolRefExpr *&B, int64_t &Addend) {
     507    54363056 :   if (!A || !B)
     508             :     return;
     509             : 
     510     8259049 :   const MCSymbol &SA = A->getSymbol();
     511     8259049 :   const MCSymbol &SB = B->getSymbol();
     512             : 
     513    16515111 :   if (SA.isUndefined() || SB.isUndefined())
     514        3016 :     return;
     515             : 
     516     8256033 :   if (!Asm->getWriter().isSymbolRefDifferenceFullyResolved(*Asm, A, B, InSet))
     517             :     return;
     518             : 
     519    14462118 :   if (SA.getFragment() == SB.getFragment() && !SA.isVariable() &&
     520    14462107 :       !SA.isUnset() && !SB.isVariable() && !SB.isUnset()) {
     521     6444323 :     Addend += (SA.getOffset() - SB.getOffset());
     522             : 
     523             :     // Pointers to Thumb symbols need to have their low-bit set to allow
     524             :     // for interworking.
     525     6444323 :     if (Asm->isThumbFunc(&SA))
     526           0 :       Addend |= 1;
     527             : 
     528             :     // Clear the symbol expr pointers to indicate we have folded these
     529             :     // operands.
     530     6444323 :     A = B = nullptr;
     531     6444323 :     return;
     532             :   }
     533             : 
     534     1573351 :   if (!Layout)
     535             :     return;
     536             : 
     537     1572352 :   const MCSection &SecA = *SA.getFragment()->getParent();
     538     1572352 :   const MCSection &SecB = *SB.getFragment()->getParent();
     539             : 
     540     1572352 :   if ((&SecA != &SecB) && !Addrs)
     541             :     return;
     542             : 
     543             :   // Eagerly evaluate.
     544     1571704 :   Addend += Layout->getSymbolOffset(A->getSymbol()) -
     545     1571704 :             Layout->getSymbolOffset(B->getSymbol());
     546     1571704 :   if (Addrs && (&SecA != &SecB))
     547         648 :     Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
     548             : 
     549             :   // Pointers to Thumb symbols need to have their low-bit set to allow
     550             :   // for interworking.
     551     1571704 :   if (Asm->isThumbFunc(&SA))
     552           0 :     Addend |= 1;
     553             : 
     554             :   // Clear the symbol expr pointers to indicate we have folded these
     555             :   // operands.
     556     1571704 :   A = B = nullptr;
     557             : }
     558             : 
     559             : /// Evaluate the result of an add between (conceptually) two MCValues.
     560             : ///
     561             : /// This routine conceptually attempts to construct an MCValue:
     562             : ///   Result = (Result_A - Result_B + Result_Cst)
     563             : /// from two MCValue's LHS and RHS where
     564             : ///   Result = LHS + RHS
     565             : /// and
     566             : ///   Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
     567             : ///
     568             : /// This routine attempts to aggresively fold the operands such that the result
     569             : /// is representable in an MCValue, but may not always succeed.
     570             : ///
     571             : /// \returns True on success, false if the result is not representable in an
     572             : /// MCValue.
     573             : 
     574             : /// NOTE: It is really important to have both the Asm and Layout arguments.
     575             : /// They might look redundant, but this function can be used before layout
     576             : /// is done (see the object streamer for example) and having the Asm argument
     577             : /// lets us avoid relaxations early.
     578             : static bool
     579    17400138 : EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
     580             :                     const SectionAddrMap *Addrs, bool InSet, const MCValue &LHS,
     581             :                     const MCSymbolRefExpr *RHS_A, const MCSymbolRefExpr *RHS_B,
     582             :                     int64_t RHS_Cst, MCValue &Res) {
     583             :   // FIXME: This routine (and other evaluation parts) are *incredibly* sloppy
     584             :   // about dealing with modifiers. This will ultimately bite us, one day.
     585    17400138 :   const MCSymbolRefExpr *LHS_A = LHS.getSymA();
     586    17400138 :   const MCSymbolRefExpr *LHS_B = LHS.getSymB();
     587    17400138 :   int64_t LHS_Cst = LHS.getConstant();
     588             : 
     589             :   // Fold the result constant immediately.
     590    17400138 :   int64_t Result_Cst = LHS_Cst + RHS_Cst;
     591             : 
     592             :   assert((!Layout || Asm) &&
     593             :          "Must have an assembler object if layout is given!");
     594             : 
     595             :   // If we have a layout, we can fold resolved differences. Do not do this if
     596             :   // the backend requires this to be emitted as individual relocations, unless
     597             :   // the InSet flag is set to get the current difference anyway (used for
     598             :   // example to calculate symbol sizes).
     599    17400138 :   if (Asm &&
     600     6334003 :       (InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) {
     601             :     // First, fold out any differences which are fully resolved. By
     602             :     // reassociating terms in
     603             :     //   Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).
     604             :     // we have the four possible differences:
     605             :     //   (LHS_A - LHS_B),
     606             :     //   (LHS_A - RHS_B),
     607             :     //   (RHS_A - LHS_B),
     608             :     //   (RHS_A - RHS_B).
     609             :     // Since we are attempting to be as aggressive as possible about folding, we
     610             :     // attempt to evaluate each possible alternative.
     611    13590764 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, LHS_B,
     612             :                                         Result_Cst);
     613    13590764 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, LHS_A, RHS_B,
     614             :                                         Result_Cst);
     615    13590764 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, LHS_B,
     616             :                                         Result_Cst);
     617    13590764 :     AttemptToFoldSymbolOffsetDifference(Asm, Layout, Addrs, InSet, RHS_A, RHS_B,
     618             :                                         Result_Cst);
     619             :   }
     620             : 
     621             :   // We can't represent the addition or subtraction of two symbols.
     622    17400138 :   if ((LHS_A && RHS_A) || (LHS_B && RHS_B))
     623             :     return false;
     624             : 
     625             :   // At this point, we have at most one additive symbol and one subtractive
     626             :   // symbol -- find them.
     627    17399909 :   const MCSymbolRefExpr *A = LHS_A ? LHS_A : RHS_A;
     628    17399909 :   const MCSymbolRefExpr *B = LHS_B ? LHS_B : RHS_B;
     629             : 
     630    17399909 :   Res = MCValue::get(A, B, Result_Cst);
     631    17399909 :   return true;
     632             : }
     633             : 
     634     9154159 : bool MCExpr::evaluateAsRelocatable(MCValue &Res,
     635             :                                    const MCAsmLayout *Layout,
     636             :                                    const MCFixup *Fixup) const {
     637     9154159 :   MCAssembler *Assembler = Layout ? &Layout->getAssembler() : nullptr;
     638     9154159 :   return evaluateAsRelocatableImpl(Res, Assembler, Layout, Fixup, nullptr,
     639     9154159 :                                    false);
     640             : }
     641             : 
     642        2978 : bool MCExpr::evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const {
     643        2978 :   MCAssembler *Assembler = &Layout.getAssembler();
     644        2978 :   return evaluateAsRelocatableImpl(Res, Assembler, &Layout, nullptr, nullptr,
     645        2978 :                                    true);
     646             : }
     647             : 
     648       10221 : static bool canExpand(const MCSymbol &Sym, bool InSet) {
     649             :   const MCExpr *Expr = Sym.getVariableValue();
     650             :   const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr);
     651             :   if (Inner) {
     652         440 :     if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF)
     653             :       return false;
     654             :   }
     655             : 
     656       10192 :   if (InSet)
     657             :     return true;
     658       10164 :   return !Sym.isInSection();
     659             : }
     660             : 
     661    57882599 : bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
     662             :                                        const MCAsmLayout *Layout,
     663             :                                        const MCFixup *Fixup,
     664             :                                        const SectionAddrMap *Addrs,
     665             :                                        bool InSet) const {
     666             :   ++stats::MCExprEvaluate;
     667             : 
     668    57882599 :   switch (getKind()) {
     669             :   case Target:
     670      108983 :     return cast<MCTargetExpr>(this)->evaluateAsRelocatableImpl(Res, Layout,
     671      108983 :                                                                Fixup);
     672             : 
     673             :   case Constant:
     674     6864709 :     Res = MCValue::get(cast<MCConstantExpr>(this)->getValue());
     675     6864709 :     return true;
     676             : 
     677             :   case SymbolRef: {
     678             :     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
     679    32769402 :     const MCSymbol &Sym = SRE->getSymbol();
     680             : 
     681             :     // Evaluate recursively if this is a variable.
     682    32779623 :     if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None &&
     683       10221 :         canExpand(Sym, InSet)) {
     684             :       bool IsMachO = SRE->hasSubsectionsViaSymbols();
     685        9802 :       if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
     686        9802 :               Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
     687        9802 :         if (!IsMachO)
     688             :           return true;
     689             : 
     690        9502 :         const MCSymbolRefExpr *A = Res.getSymA();
     691        9502 :         const MCSymbolRefExpr *B = Res.getSymB();
     692             :         // FIXME: This is small hack. Given
     693             :         // a = b + 4
     694             :         // .long a
     695             :         // the OS X assembler will completely drop the 4. We should probably
     696             :         // include it in the relocation or produce an error if that is not
     697             :         // possible.
     698             :         // Allow constant expressions.
     699        9502 :         if (!A && !B)
     700             :           return true;
     701             :         // Allows aliases with zero offset.
     702        5075 :         if (Res.getConstant() == 0 && (!A || !B))
     703             :           return true;
     704             :       }
     705             :     }
     706             : 
     707    32764662 :     Res = MCValue::get(SRE, nullptr, 0);
     708    32764662 :     return true;
     709             :   }
     710             : 
     711             :   case Unary: {
     712             :     const MCUnaryExpr *AUE = cast<MCUnaryExpr>(this);
     713       20171 :     MCValue Value;
     714             : 
     715       20171 :     if (!AUE->getSubExpr()->evaluateAsRelocatableImpl(Value, Asm, Layout, Fixup,
     716             :                                                       Addrs, InSet))
     717             :       return false;
     718             : 
     719       20169 :     switch (AUE->getOpcode()) {
     720           4 :     case MCUnaryExpr::LNot:
     721           4 :       if (!Value.isAbsolute())
     722             :         return false;
     723           4 :       Res = MCValue::get(!Value.getConstant());
     724           4 :       break;
     725       19986 :     case MCUnaryExpr::Minus:
     726             :       /// -(a - b + const) ==> (b - a - const)
     727       19986 :       if (Value.getSymA() && !Value.getSymB())
     728             :         return false;
     729             : 
     730             :       // The cast avoids undefined behavior if the constant is INT64_MIN.
     731       19725 :       Res = MCValue::get(Value.getSymB(), Value.getSymA(),
     732       19725 :                          -(uint64_t)Value.getConstant());
     733       19725 :       break;
     734         148 :     case MCUnaryExpr::Not:
     735         148 :       if (!Value.isAbsolute())
     736             :         return false;
     737         147 :       Res = MCValue::get(~Value.getConstant());
     738         147 :       break;
     739          31 :     case MCUnaryExpr::Plus:
     740          31 :       Res = Value;
     741          31 :       break;
     742             :     }
     743             : 
     744             :     return true;
     745             :   }
     746             : 
     747             :   case Binary: {
     748             :     const MCBinaryExpr *ABE = cast<MCBinaryExpr>(this);
     749    18119334 :     MCValue LHSValue, RHSValue;
     750             : 
     751    18119334 :     if (!ABE->getLHS()->evaluateAsRelocatableImpl(LHSValue, Asm, Layout, Fixup,
     752    36238585 :                                                   Addrs, InSet) ||
     753    18119251 :         !ABE->getRHS()->evaluateAsRelocatableImpl(RHSValue, Asm, Layout, Fixup,
     754             :                                                   Addrs, InSet)) {
     755             :       // Check if both are Target Expressions, see if we can compare them.
     756          89 :       if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS()))
     757           2 :         if (const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS())) {
     758           2 :           switch (ABE->getOpcode()) {
     759           2 :           case MCBinaryExpr::EQ:
     760           2 :             Res = MCValue::get((L->isEqualTo(R)) ? -1 : 0);
     761           2 :             return true;
     762           0 :           case MCBinaryExpr::NE:
     763           0 :             Res = MCValue::get((R->isEqualTo(R)) ? 0 : -1);
     764           0 :             return true;
     765             :           default: break;
     766             :           }
     767             :         }
     768             :       return false;
     769             :     }
     770             : 
     771             :     // We only support a few operations on non-constant expressions, handle
     772             :     // those first.
     773    18838314 :     if (!LHSValue.isAbsolute() || !RHSValue.isAbsolute()) {
     774    17400367 :       switch (ABE->getOpcode()) {
     775             :       default:
     776             :         return false;
     777    12051766 :       case MCBinaryExpr::Sub:
     778             :         // Negate RHS and add.
     779             :         // The cast avoids undefined behavior if the constant is INT64_MIN.
     780    12051766 :         return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
     781             :                                    RHSValue.getSymB(), RHSValue.getSymA(),
     782    12051766 :                                    -(uint64_t)RHSValue.getConstant(), Res);
     783             : 
     784     5348372 :       case MCBinaryExpr::Add:
     785     5348372 :         return EvaluateSymbolicAdd(Asm, Layout, Addrs, InSet, LHSValue,
     786             :                                    RHSValue.getSymA(), RHSValue.getSymB(),
     787     5348372 :                                    RHSValue.getConstant(), Res);
     788             :       }
     789             :     }
     790             : 
     791             :     // FIXME: We need target hooks for the evaluation. It may be limited in
     792             :     // width, and gas defines the result of comparisons differently from
     793             :     // Apple as.
     794      718878 :     int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
     795             :     int64_t Result = 0;
     796      718878 :     auto Op = ABE->getOpcode();
     797             :     switch (Op) {
     798           1 :     case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
     799         446 :     case MCBinaryExpr::Add:  Result = LHS + RHS; break;
     800          37 :     case MCBinaryExpr::And:  Result = LHS & RHS; break;
     801         149 :     case MCBinaryExpr::Div:
     802             :     case MCBinaryExpr::Mod:
     803             :       // Handle division by zero. gas just emits a warning and keeps going,
     804             :       // we try to be stricter.
     805             :       // FIXME: Currently the caller of this function has no way to understand
     806             :       // we're bailing out because of 'division by zero'. Therefore, it will
     807             :       // emit a 'expected relocatable expression' error. It would be nice to
     808             :       // change this code to emit a better diagnostic.
     809         149 :       if (RHS == 0)
     810             :         return false;
     811         143 :       if (ABE->getOpcode() == MCBinaryExpr::Div)
     812         138 :         Result = LHS / RHS;
     813             :       else
     814           5 :         Result = LHS % RHS;
     815             :       break;
     816          27 :     case MCBinaryExpr::EQ:   Result = LHS == RHS; break;
     817           6 :     case MCBinaryExpr::GT:   Result = LHS > RHS; break;
     818           1 :     case MCBinaryExpr::GTE:  Result = LHS >= RHS; break;
     819           3 :     case MCBinaryExpr::LAnd: Result = LHS && RHS; break;
     820           4 :     case MCBinaryExpr::LOr:  Result = LHS || RHS; break;
     821          27 :     case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break;
     822           4 :     case MCBinaryExpr::LT:   Result = LHS < RHS; break;
     823           1 :     case MCBinaryExpr::LTE:  Result = LHS <= RHS; break;
     824         238 :     case MCBinaryExpr::Mul:  Result = LHS * RHS; break;
     825          42 :     case MCBinaryExpr::NE:   Result = LHS != RHS; break;
     826         108 :     case MCBinaryExpr::Or:   Result = LHS | RHS; break;
     827         266 :     case MCBinaryExpr::Shl:  Result = uint64_t(LHS) << uint64_t(RHS); break;
     828      717516 :     case MCBinaryExpr::Sub:  Result = LHS - RHS; break;
     829           2 :     case MCBinaryExpr::Xor:  Result = LHS ^ RHS; break;
     830             :     }
     831             : 
     832             :     switch (Op) {
     833             :     default:
     834      718791 :       Res = MCValue::get(Result);
     835      718791 :       break;
     836          81 :     case MCBinaryExpr::EQ:
     837             :     case MCBinaryExpr::GT:
     838             :     case MCBinaryExpr::GTE:
     839             :     case MCBinaryExpr::LT:
     840             :     case MCBinaryExpr::LTE:
     841             :     case MCBinaryExpr::NE:
     842             :       // A comparison operator returns a -1 if true and 0 if false.
     843          81 :       Res = MCValue::get(Result ? -1 : 0);
     844          81 :       break;
     845             :     }
     846             : 
     847             :     return true;
     848             :   }
     849             :   }
     850             : 
     851           0 :   llvm_unreachable("Invalid assembly expression kind!");
     852             : }
     853             : 
     854       19399 : MCFragment *MCExpr::findAssociatedFragment() const {
     855       19401 :   switch (getKind()) {
     856             :   case Target:
     857             :     // We never look through target specific expressions.
     858           0 :     return cast<MCTargetExpr>(this)->findAssociatedFragment();
     859             : 
     860        2232 :   case Constant:
     861        2232 :     return MCSymbol::AbsolutePseudoFragment;
     862             : 
     863             :   case SymbolRef: {
     864             :     const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
     865       10468 :     const MCSymbol &Sym = SRE->getSymbol();
     866       10468 :     return Sym.getFragment();
     867             :   }
     868             : 
     869             :   case Unary:
     870           2 :     return cast<MCUnaryExpr>(this)->getSubExpr()->findAssociatedFragment();
     871             : 
     872             :   case Binary: {
     873             :     const MCBinaryExpr *BE = cast<MCBinaryExpr>(this);
     874        6699 :     MCFragment *LHS_F = BE->getLHS()->findAssociatedFragment();
     875        6699 :     MCFragment *RHS_F = BE->getRHS()->findAssociatedFragment();
     876             : 
     877             :     // If either is absolute, return the other.
     878        6699 :     if (LHS_F == MCSymbol::AbsolutePseudoFragment)
     879             :       return RHS_F;
     880        4884 :     if (RHS_F == MCSymbol::AbsolutePseudoFragment)
     881             :       return LHS_F;
     882             : 
     883             :     // Not always correct, but probably the best we can do without more context.
     884        4778 :     if (BE->getOpcode() == MCBinaryExpr::Sub)
     885             :       return MCSymbol::AbsolutePseudoFragment;
     886             : 
     887             :     // Otherwise, return the first non-null fragment.
     888           1 :     return LHS_F ? LHS_F : RHS_F;
     889             :   }
     890             :   }
     891             : 
     892           0 :   llvm_unreachable("Invalid assembly expression kind!");
     893             : }

Generated by: LCOV version 1.13