Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCExpr.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- PPCMCExpr.cpp - PPC 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
#include "PPCMCExpr.h"
10
#include "PPCFixupKinds.h"
11
#include "llvm/MC/MCAsmInfo.h"
12
#include "llvm/MC/MCAssembler.h"
13
#include "llvm/MC/MCContext.h"
14
#include "llvm/MC/MCObjectStreamer.h"
15
16
using namespace llvm;
17
18
#define DEBUG_TYPE "ppcmcexpr"
19
20
const PPCMCExpr*
21
PPCMCExpr::create(VariantKind Kind, const MCExpr *Expr,
22
4.00k
                  bool isDarwin, MCContext &Ctx) {
23
4.00k
  return new (Ctx) PPCMCExpr(Kind, Expr, isDarwin);
24
4.00k
}
25
26
3.67k
void PPCMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
27
3.67k
  if (isDarwinSyntax()) {
28
0
    switch (Kind) {
29
0
    default: llvm_unreachable("Invalid kind!");
30
0
    case VK_PPC_LO: OS << "lo16"; break;
31
0
    case VK_PPC_HI: OS << "hi16"; break;
32
0
    case VK_PPC_HA: OS << "ha16"; break;
33
0
    }
34
0
35
0
    OS << '(';
36
0
    getSubExpr()->print(OS, MAI);
37
0
    OS << ')';
38
3.67k
  } else {
39
3.67k
    getSubExpr()->print(OS, MAI);
40
3.67k
41
3.67k
    switch (Kind) {
42
3.67k
    
default: 0
llvm_unreachable0
("Invalid kind!");
43
3.67k
    
case VK_PPC_LO: OS << "@l"; break1.82k
;
44
3.67k
    
case VK_PPC_HI: OS << "@h"; break16
;
45
3.67k
    
case VK_PPC_HA: OS << "@ha"; break1.81k
;
46
3.67k
    
case VK_PPC_HIGH: OS << "@high"; break4
;
47
3.67k
    
case VK_PPC_HIGHA: OS << "@higha"; break4
;
48
3.67k
    
case VK_PPC_HIGHER: OS << "@higher"; break4
;
49
3.67k
    
case VK_PPC_HIGHERA: OS << "@highera"; break4
;
50
3.67k
    
case VK_PPC_HIGHEST: OS << "@highest"; break4
;
51
3.67k
    
case VK_PPC_HIGHESTA: OS << "@highesta"; break4
;
52
3.67k
    }
53
3.67k
  }
54
3.67k
}
55
56
bool
57
381
PPCMCExpr::evaluateAsConstant(int64_t &Res) const {
58
381
  MCValue Value;
59
381
60
381
  if (!getSubExpr()->evaluateAsRelocatable(Value, nullptr, nullptr))
61
4
    return false;
62
377
63
377
  if (!Value.isAbsolute())
64
362
    return false;
65
15
66
15
  Res = evaluateAsInt64(Value.getConstant());
67
15
  return true;
68
15
}
69
70
int64_t
71
86
PPCMCExpr::evaluateAsInt64(int64_t Value) const {
72
86
  switch (Kind) {
73
86
    case VK_PPC_LO:
74
36
      return Value & 0xffff;
75
86
    case VK_PPC_HI:
76
20
      return (Value >> 16) & 0xffff;
77
86
    case VK_PPC_HA:
78
18
      return ((Value + 0x8000) >> 16) & 0xffff;
79
86
    case VK_PPC_HIGH:
80
2
      return (Value >> 16) & 0xffff;
81
86
    case VK_PPC_HIGHA:
82
2
      return ((Value + 0x8000) >> 16) & 0xffff;
83
86
    case VK_PPC_HIGHER:
84
2
      return (Value >> 32) & 0xffff;
85
86
    case VK_PPC_HIGHERA:
86
2
      return ((Value + 0x8000) >> 32) & 0xffff;
87
86
    case VK_PPC_HIGHEST:
88
2
      return (Value >> 48) & 0xffff;
89
86
    case VK_PPC_HIGHESTA:
90
2
      return ((Value + 0x8000) >> 48) & 0xffff;
91
86
    case VK_PPC_None:
92
0
      break;
93
0
  }
94
0
  llvm_unreachable("Invalid kind!");
95
0
}
96
97
bool
98
PPCMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
99
                                     const MCAsmLayout *Layout,
100
375
                                     const MCFixup *Fixup) const {
101
375
  MCValue Value;
102
375
103
375
  if (!getSubExpr()->evaluateAsRelocatable(Value, Layout, Fixup))
104
0
    return false;
105
375
106
375
  if (Value.isAbsolute()) {
107
71
    int64_t Result = evaluateAsInt64(Value.getConstant());
108
71
    if ((Fixup == nullptr || 
(unsigned)Fixup->getKind() != PPC::fixup_ppc_half1636
) &&
109
71
        
(Result >= 0x8000)35
)
110
13
      return false;
111
58
    Res = MCValue::get(Result);
112
304
  } else {
113
304
    if (!Layout)
114
8
      return false;
115
296
116
296
    MCContext &Context = Layout->getAssembler().getContext();
117
296
    const MCSymbolRefExpr *Sym = Value.getSymA();
118
296
    MCSymbolRefExpr::VariantKind Modifier = Sym->getKind();
119
296
    if (Modifier != MCSymbolRefExpr::VK_None)
120
0
      return false;
121
296
    switch (Kind) {
122
296
      default:
123
0
        llvm_unreachable("Invalid kind!");
124
296
      case VK_PPC_LO:
125
135
        Modifier = MCSymbolRefExpr::VK_PPC_LO;
126
135
        break;
127
296
      case VK_PPC_HI:
128
11
        Modifier = MCSymbolRefExpr::VK_PPC_HI;
129
11
        break;
130
296
      case VK_PPC_HA:
131
130
        Modifier = MCSymbolRefExpr::VK_PPC_HA;
132
130
        break;
133
296
      case VK_PPC_HIGH:
134
2
        Modifier = MCSymbolRefExpr::VK_PPC_HIGH;
135
2
        break;
136
296
      case VK_PPC_HIGHA:
137
2
        Modifier = MCSymbolRefExpr::VK_PPC_HIGHA;
138
2
        break;
139
296
      case VK_PPC_HIGHERA:
140
4
        Modifier = MCSymbolRefExpr::VK_PPC_HIGHERA;
141
4
        break;
142
296
      case VK_PPC_HIGHER:
143
4
        Modifier = MCSymbolRefExpr::VK_PPC_HIGHER;
144
4
        break;
145
296
      case VK_PPC_HIGHEST:
146
4
        Modifier = MCSymbolRefExpr::VK_PPC_HIGHEST;
147
4
        break;
148
296
      case VK_PPC_HIGHESTA:
149
4
        Modifier = MCSymbolRefExpr::VK_PPC_HIGHESTA;
150
4
        break;
151
296
    }
152
296
    Sym = MCSymbolRefExpr::create(&Sym->getSymbol(), Modifier, Context);
153
296
    Res = MCValue::get(Sym, Value.getSymB(), Value.getConstant());
154
296
  }
155
375
156
375
  
return true354
;
157
375
}
158
159
332
void PPCMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
160
332
  Streamer.visitUsedExpr(*getSubExpr());
161
332
}