Coverage Report

Created: 2019-07-24 05:18

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