Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ARMConstantPoolValue.cpp - ARM constantpool value ------------------===//
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 implements the ARM specific constantpool value class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "ARMConstantPoolValue.h"
14
#include "llvm/ADT/FoldingSet.h"
15
#include "llvm/CodeGen/MachineBasicBlock.h"
16
#include "llvm/Config/llvm-config.h"
17
#include "llvm/IR/Constant.h"
18
#include "llvm/IR/Constants.h"
19
#include "llvm/IR/GlobalValue.h"
20
#include "llvm/IR/Type.h"
21
#include "llvm/Support/Casting.h"
22
#include "llvm/Support/Compiler.h"
23
#include "llvm/Support/ErrorHandling.h"
24
#include "llvm/Support/raw_ostream.h"
25
26
using namespace llvm;
27
28
//===----------------------------------------------------------------------===//
29
// ARMConstantPoolValue
30
//===----------------------------------------------------------------------===//
31
32
ARMConstantPoolValue::ARMConstantPoolValue(Type *Ty, unsigned id,
33
                                           ARMCP::ARMCPKind kind,
34
                                           unsigned char PCAdj,
35
                                           ARMCP::ARMCPModifier modifier,
36
                                           bool addCurrentAddress)
37
  : MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
38
    PCAdjust(PCAdj), Modifier(modifier),
39
1.47k
    AddCurrentAddress(addCurrentAddress) {}
40
41
ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C, unsigned id,
42
                                           ARMCP::ARMCPKind kind,
43
                                           unsigned char PCAdj,
44
                                           ARMCP::ARMCPModifier modifier,
45
                                           bool addCurrentAddress)
46
  : MachineConstantPoolValue((Type*)Type::getInt32Ty(C)),
47
    LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier),
48
67
    AddCurrentAddress(addCurrentAddress) {}
49
50
1.54k
ARMConstantPoolValue::~ARMConstantPoolValue() = default;
51
52
8
StringRef ARMConstantPoolValue::getModifierText() const {
53
8
  switch (Modifier) {
54
8
    // FIXME: Are these case sensitive? It'd be nice to lower-case all the
55
8
    // strings if that's legal.
56
8
  case ARMCP::no_modifier:
57
0
    return "none";
58
8
  case ARMCP::TLSGD:
59
0
    return "tlsgd";
60
8
  case ARMCP::GOT_PREL:
61
0
    return "GOT_PREL";
62
8
  case ARMCP::GOTTPOFF:
63
0
    return "gottpoff";
64
8
  case ARMCP::TPOFF:
65
0
    return "tpoff";
66
8
  case ARMCP::SBREL:
67
8
    return "SBREL";
68
8
  case ARMCP::SECREL:
69
0
    return "secrel32";
70
0
  }
71
0
  llvm_unreachable("Unknown modifier!");
72
0
}
73
74
int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
75
0
                                                    unsigned Alignment) {
76
0
  llvm_unreachable("Shouldn't be calling this directly!");
77
0
}
78
79
void
80
307
ARMConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
81
307
  ID.AddInteger(LabelId);
82
307
  ID.AddInteger(PCAdjust);
83
307
}
84
85
bool
86
1
ARMConstantPoolValue::hasSameValue(ARMConstantPoolValue *ACPV) {
87
1
  if (ACPV->Kind == Kind &&
88
1
      ACPV->PCAdjust == PCAdjust &&
89
1
      ACPV->Modifier == Modifier &&
90
1
      ACPV->LabelId == LabelId &&
91
1
      
ACPV->AddCurrentAddress == AddCurrentAddress0
) {
92
0
    // Two PC relative constpool entries containing the same GV address or
93
0
    // external symbols. FIXME: What about blockaddress?
94
0
    if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
95
0
      return true;
96
1
  }
97
1
  return false;
98
1
}
99
100
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
101
LLVM_DUMP_METHOD void ARMConstantPoolValue::dump() const {
102
  errs() << "  " << *this;
103
}
104
#endif
105
106
10
void ARMConstantPoolValue::print(raw_ostream &O) const {
107
10
  if (Modifier) 
O << "(" << getModifierText() << ")"8
;
108
10
  if (PCAdjust != 0) {
109
2
    O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
110
2
    if (AddCurrentAddress) 
O << "-."0
;
111
2
    O << ")";
112
2
  }
113
10
}
114
115
//===----------------------------------------------------------------------===//
116
// ARMConstantPoolConstant
117
//===----------------------------------------------------------------------===//
118
119
ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty,
120
                                                 const Constant *C,
121
                                                 unsigned ID,
122
                                                 ARMCP::ARMCPKind Kind,
123
                                                 unsigned char PCAdj,
124
                                                 ARMCP::ARMCPModifier Modifier,
125
                                                 bool AddCurrentAddress)
126
  : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress),
127
351
    CVal(C) {}
128
129
ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
130
                                                 unsigned ID,
131
                                                 ARMCP::ARMCPKind Kind,
132
                                                 unsigned char PCAdj,
133
                                                 ARMCP::ARMCPModifier Modifier,
134
                                                 bool AddCurrentAddress)
135
  : ARMConstantPoolValue((Type*)C->getType(), ID, Kind, PCAdj, Modifier,
136
                         AddCurrentAddress),
137
1.03k
    CVal(C) {}
138
139
ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
140
                                                 const Constant *C)
141
    : ARMConstantPoolValue((Type *)C->getType(), 0, ARMCP::CPPromotedGlobal, 0,
142
86
                           ARMCP::no_modifier, false), CVal(C) {
143
86
  GVars.insert(GV);
144
86
}
145
146
ARMConstantPoolConstant *
147
0
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID) {
148
0
  return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
149
0
                                     ARMCP::no_modifier, false);
150
0
}
151
152
ARMConstantPoolConstant *
153
ARMConstantPoolConstant::Create(const GlobalVariable *GVar,
154
86
                                const Constant *Initializer) {
155
86
  return new ARMConstantPoolConstant(GVar, Initializer);
156
86
}
157
158
ARMConstantPoolConstant *
159
ARMConstantPoolConstant::Create(const GlobalValue *GV,
160
351
                                ARMCP::ARMCPModifier Modifier) {
161
351
  return new ARMConstantPoolConstant((Type*)Type::getInt32Ty(GV->getContext()),
162
351
                                     GV, 0, ARMCP::CPValue, 0,
163
351
                                     Modifier, false);
164
351
}
165
166
ARMConstantPoolConstant *
167
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID,
168
60
                                ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
169
60
  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
170
60
                                     ARMCP::no_modifier, false);
171
60
}
172
173
ARMConstantPoolConstant *
174
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID,
175
                                ARMCP::ARMCPKind Kind, unsigned char PCAdj,
176
                                ARMCP::ARMCPModifier Modifier,
177
976
                                bool AddCurrentAddress) {
178
976
  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
179
976
                                     AddCurrentAddress);
180
976
}
181
182
1.20k
const GlobalValue *ARMConstantPoolConstant::getGV() const {
183
1.20k
  return dyn_cast_or_null<GlobalValue>(CVal);
184
1.20k
}
185
186
18
const BlockAddress *ARMConstantPoolConstant::getBlockAddress() const {
187
18
  return dyn_cast_or_null<BlockAddress>(CVal);
188
18
}
189
190
int ARMConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool *CP,
191
1.47k
                                                       unsigned Alignment) {
192
1.47k
  int index =
193
1.47k
    getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
194
1.47k
  if (index != -1) {
195
132
    auto *CPV = static_cast<ARMConstantPoolValue*>(
196
132
        CP->getConstants()[index].Val.MachineCPVal);
197
132
    auto *Constant = cast<ARMConstantPoolConstant>(CPV);
198
132
    Constant->GVars.insert(GVars.begin(), GVars.end());
199
132
  }
200
1.47k
  return index;
201
1.47k
}
202
203
1
bool ARMConstantPoolConstant::hasSameValue(ARMConstantPoolValue *ACPV) {
204
1
  const ARMConstantPoolConstant *ACPC = dyn_cast<ARMConstantPoolConstant>(ACPV);
205
1
  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
206
1
}
207
208
290
void ARMConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
209
290
  ID.AddPointer(CVal);
210
290
  for (const auto *GV : GVars)
211
100
    ID.AddPointer(GV);
212
290
  ARMConstantPoolValue::addSelectionDAGCSEId(ID);
213
290
}
214
215
10
void ARMConstantPoolConstant::print(raw_ostream &O) const {
216
10
  O << CVal->getName();
217
10
  ARMConstantPoolValue::print(O);
218
10
}
219
220
//===----------------------------------------------------------------------===//
221
// ARMConstantPoolSymbol
222
//===----------------------------------------------------------------------===//
223
224
ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, StringRef s,
225
                                             unsigned id, unsigned char PCAdj,
226
                                             ARMCP::ARMCPModifier Modifier,
227
                                             bool AddCurrentAddress)
228
    : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
229
                           AddCurrentAddress),
230
35
      S(s) {}
231
232
ARMConstantPoolSymbol *ARMConstantPoolSymbol::Create(LLVMContext &C,
233
                                                     StringRef s, unsigned ID,
234
35
                                                     unsigned char PCAdj) {
235
35
  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
236
35
}
237
238
int ARMConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool *CP,
239
35
                                                     unsigned Alignment) {
240
35
  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
241
35
}
242
243
0
bool ARMConstantPoolSymbol::hasSameValue(ARMConstantPoolValue *ACPV) {
244
0
  const ARMConstantPoolSymbol *ACPS = dyn_cast<ARMConstantPoolSymbol>(ACPV);
245
0
  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
246
0
}
247
248
17
void ARMConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
249
17
  ID.AddString(S);
250
17
  ARMConstantPoolValue::addSelectionDAGCSEId(ID);
251
17
}
252
253
0
void ARMConstantPoolSymbol::print(raw_ostream &O) const {
254
0
  O << S;
255
0
  ARMConstantPoolValue::print(O);
256
0
}
257
258
//===----------------------------------------------------------------------===//
259
// ARMConstantPoolMBB
260
//===----------------------------------------------------------------------===//
261
262
ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
263
                                       const MachineBasicBlock *mbb,
264
                                       unsigned id, unsigned char PCAdj,
265
                                       ARMCP::ARMCPModifier Modifier,
266
                                       bool AddCurrentAddress)
267
  : ARMConstantPoolValue(C, id, ARMCP::CPMachineBasicBlock, PCAdj,
268
                         Modifier, AddCurrentAddress),
269
32
    MBB(mbb) {}
270
271
ARMConstantPoolMBB *ARMConstantPoolMBB::Create(LLVMContext &C,
272
                                               const MachineBasicBlock *mbb,
273
                                               unsigned ID,
274
32
                                               unsigned char PCAdj) {
275
32
  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
276
32
}
277
278
int ARMConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
279
32
                                                  unsigned Alignment) {
280
32
  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
281
32
}
282
283
0
bool ARMConstantPoolMBB::hasSameValue(ARMConstantPoolValue *ACPV) {
284
0
  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
285
0
  return ACPMBB && ACPMBB->MBB == MBB &&
286
0
    ARMConstantPoolValue::hasSameValue(ACPV);
287
0
}
288
289
0
void ARMConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
290
0
  ID.AddPointer(MBB);
291
0
  ARMConstantPoolValue::addSelectionDAGCSEId(ID);
292
0
}
293
294
0
void ARMConstantPoolMBB::print(raw_ostream &O) const {
295
0
  O << printMBBReference(*MBB);
296
0
  ARMConstantPoolValue::print(O);
297
0
}