LCOV - code coverage report
Current view: top level - lib/Target/AArch64/MCTargetDesc - AArch64MCExpr.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 70 77 90.9 %
Date: 2018-09-23 13:06:45 Functions: 7 8 87.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- AArch64MCExpr.cpp - AArch64 specific MC expression classes --------===//
       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             : // This file contains the implementation of the assembly expression modifiers
      11             : // accepted by the AArch64 architecture (e.g. ":lo12:", ":gottprel_g1:", ...).
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #include "AArch64MCExpr.h"
      16             : #include "llvm/BinaryFormat/ELF.h"
      17             : #include "llvm/MC/MCContext.h"
      18             : #include "llvm/MC/MCStreamer.h"
      19             : #include "llvm/MC/MCSymbolELF.h"
      20             : #include "llvm/MC/MCValue.h"
      21             : #include "llvm/Support/ErrorHandling.h"
      22             : 
      23             : using namespace llvm;
      24             : 
      25             : #define DEBUG_TYPE "aarch64symbolrefexpr"
      26             : 
      27        9238 : const AArch64MCExpr *AArch64MCExpr::create(const MCExpr *Expr, VariantKind Kind,
      28             :                                        MCContext &Ctx) {
      29        9238 :   return new (Ctx) AArch64MCExpr(Expr, Kind);
      30             : }
      31             : 
      32        8712 : StringRef AArch64MCExpr::getVariantKindName() const {
      33        8712 :   switch (static_cast<uint32_t>(getKind())) {
      34        1641 :   case VK_CALL:                return "";
      35        3273 :   case VK_LO12:                return ":lo12:";
      36          40 :   case VK_ABS_G3:              return ":abs_g3:";
      37           5 :   case VK_ABS_G2:              return ":abs_g2:";
      38           4 :   case VK_ABS_G2_S:            return ":abs_g2_s:";
      39          37 :   case VK_ABS_G2_NC:           return ":abs_g2_nc:";
      40           5 :   case VK_ABS_G1:              return ":abs_g1:";
      41           8 :   case VK_ABS_G1_S:            return ":abs_g1_s:";
      42          37 :   case VK_ABS_G1_NC:           return ":abs_g1_nc:";
      43           5 :   case VK_ABS_G0:              return ":abs_g0:";
      44           8 :   case VK_ABS_G0_S:            return ":abs_g0_s:";
      45          37 :   case VK_ABS_G0_NC:           return ":abs_g0_nc:";
      46          12 :   case VK_DTPREL_G2:           return ":dtprel_g2:";
      47          14 :   case VK_DTPREL_G1:           return ":dtprel_g1:";
      48           8 :   case VK_DTPREL_G1_NC:        return ":dtprel_g1_nc:";
      49          14 :   case VK_DTPREL_G0:           return ":dtprel_g0:";
      50           8 :   case VK_DTPREL_G0_NC:        return ":dtprel_g0_nc:";
      51          12 :   case VK_DTPREL_HI12:         return ":dtprel_hi12:";
      52          78 :   case VK_DTPREL_LO12:         return ":dtprel_lo12:";
      53          95 :   case VK_DTPREL_LO12_NC:      return ":dtprel_lo12_nc:";
      54           8 :   case VK_TPREL_G2:            return ":tprel_g2:";
      55          14 :   case VK_TPREL_G1:            return ":tprel_g1:";
      56           8 :   case VK_TPREL_G1_NC:         return ":tprel_g1_nc:";
      57          14 :   case VK_TPREL_G0:            return ":tprel_g0:";
      58           8 :   case VK_TPREL_G0_NC:         return ":tprel_g0_nc:";
      59          12 :   case VK_TPREL_HI12:          return ":tprel_hi12:";
      60          78 :   case VK_TPREL_LO12:          return ":tprel_lo12:";
      61          92 :   case VK_TPREL_LO12_NC:       return ":tprel_lo12_nc:";
      62          68 :   case VK_TLSDESC_LO12:        return ":tlsdesc_lo12:";
      63        2770 :   case VK_ABS_PAGE:            return "";
      64           0 :   case VK_ABS_PAGE_NC:         return ":pg_hi21_nc:";
      65          26 :   case VK_GOT:                 return ":got:";
      66          78 :   case VK_GOT_PAGE:            return ":got:";
      67          81 :   case VK_GOT_LO12:            return ":got_lo12:";
      68           4 :   case VK_GOTTPREL:            return ":gottprel:";
      69          18 :   case VK_GOTTPREL_PAGE:       return ":gottprel:";
      70          20 :   case VK_GOTTPREL_LO12_NC:    return ":gottprel_lo12:";
      71           6 :   case VK_GOTTPREL_G1:         return ":gottprel_g1:";
      72           6 :   case VK_GOTTPREL_G0_NC:      return ":gottprel_g0_nc:";
      73          22 :   case VK_TLSDESC:             return "";
      74          28 :   case VK_TLSDESC_PAGE:        return ":tlsdesc:";
      75           5 :   case VK_SECREL_LO12:         return ":secrel_lo12:";
      76           5 :   case VK_SECREL_HI12:         return ":secrel_hi12:";
      77           0 :   default:
      78           0 :     llvm_unreachable("Invalid ELF symbol kind");
      79             :   }
      80             : }
      81             : 
      82        8801 : void AArch64MCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
      83        8801 :   if (getKind() != VK_NONE)
      84        8712 :     OS << getVariantKindName();
      85        8801 :   Expr->print(OS, MAI);
      86        8801 : }
      87             : 
      88         773 : void AArch64MCExpr::visitUsedExpr(MCStreamer &Streamer) const {
      89         773 :   Streamer.visitUsedExpr(*getSubExpr());
      90         773 : }
      91             : 
      92           0 : MCFragment *AArch64MCExpr::findAssociatedFragment() const {
      93           0 :   llvm_unreachable("FIXME: what goes here?");
      94             : }
      95             : 
      96         773 : bool AArch64MCExpr::evaluateAsRelocatableImpl(MCValue &Res,
      97             :                                               const MCAsmLayout *Layout,
      98             :                                               const MCFixup *Fixup) const {
      99         773 :   if (!getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup))
     100             :     return false;
     101             : 
     102         773 :   Res =
     103        1546 :       MCValue::get(Res.getSymA(), Res.getSymB(), Res.getConstant(), getKind());
     104             : 
     105         773 :   return true;
     106             : }
     107             : 
     108         380 : static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
     109         391 :   switch (Expr->getKind()) {
     110             :   case MCExpr::Target:
     111             :     llvm_unreachable("Can't handle nested target expression");
     112             :     break;
     113             :   case MCExpr::Constant:
     114             :     break;
     115             : 
     116             :   case MCExpr::Binary: {
     117             :     const MCBinaryExpr *BE = cast<MCBinaryExpr>(Expr);
     118          11 :     fixELFSymbolsInTLSFixupsImpl(BE->getLHS(), Asm);
     119          11 :     fixELFSymbolsInTLSFixupsImpl(BE->getRHS(), Asm);
     120          11 :     break;
     121             :   }
     122             : 
     123             :   case MCExpr::SymbolRef: {
     124             :     // We're known to be under a TLS fixup, so any symbol should be
     125             :     // modified. There should be only one.
     126             :     const MCSymbolRefExpr &SymRef = *cast<MCSymbolRefExpr>(Expr);
     127         369 :     cast<MCSymbolELF>(SymRef.getSymbol()).setType(ELF::STT_TLS);
     128         369 :     break;
     129             :   }
     130             : 
     131             :   case MCExpr::Unary:
     132           0 :     fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
     133           0 :     break;
     134             :   }
     135         380 : }
     136             : 
     137         756 : void AArch64MCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
     138        1512 :   switch (getSymbolLoc(Kind)) {
     139             :   default:
     140             :     return;
     141             :   case VK_DTPREL:
     142             :   case VK_GOTTPREL:
     143             :   case VK_TPREL:
     144             :   case VK_TLSDESC:
     145             :     break;
     146             :   }
     147             : 
     148         369 :   fixELFSymbolsInTLSFixupsImpl(getSubExpr(), Asm);
     149             : }

Generated by: LCOV version 1.13