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

Generated by: LCOV version 1.13