Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- ARMConstantPoolValue.cpp - ARM constantpool value ------------------===//
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 implements the ARM specific constantpool value class.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "ARMConstantPoolValue.h"
15
#include "llvm/ADT/FoldingSet.h"
16
#include "llvm/CodeGen/MachineBasicBlock.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.41k
    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
66
    AddCurrentAddress(addCurrentAddress) {}
49
50
1.48k
ARMConstantPoolValue::~ARMConstantPoolValue() = default;
51
52
4
StringRef ARMConstantPoolValue::getModifierText() const {
53
4
  switch (Modifier) {
54
4
    // FIXME: Are these case sensitive? It'd be nice to lower-case all the
55
4
    // strings if that's legal.
56
0
  case ARMCP::no_modifier:
57
0
    return "none";
58
0
  case ARMCP::TLSGD:
59
0
    return "tlsgd";
60
0
  case ARMCP::GOT_PREL:
61
0
    return "GOT_PREL";
62
0
  case ARMCP::GOTTPOFF:
63
0
    return "gottpoff";
64
0
  case ARMCP::TPOFF:
65
0
    return "tpoff";
66
4
  case ARMCP::SBREL:
67
4
    return "SBREL";
68
0
  case ARMCP::SECREL:
69
0
    return "secrel32";
70
0
  }
71
0
  
llvm_unreachable0
("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
409
ARMConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
81
409
  ID.AddInteger(LabelId);
82
409
  ID.AddInteger(PCAdjust);
83
409
}
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 || 0
Kind == ARMCP::CPExtSymbol0
)
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
6
void ARMConstantPoolValue::print(raw_ostream &O) const {
107
6
  if (
Modifier6
)
O << "(" << getModifierText() << ")"4
;
108
6
  if (
PCAdjust != 06
) {
109
2
    O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
110
2
    if (
AddCurrentAddress2
)
O << "-."0
;
111
2
    O << ")";
112
2
  }
113
6
}
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
337
    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
983
    CVal(C) {}
138
139
ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
140
                                                 const Constant *C)
141
    : ARMConstantPoolValue((Type *)C->getType(), 0, ARMCP::CPPromotedGlobal, 0,
142
94
                           ARMCP::no_modifier, false), CVal(C) {
143
94
  GVars.insert(GV);
144
94
}
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
94
                                const Constant *Initializer) {
155
94
  return new ARMConstantPoolConstant(GVar, Initializer);
156
94
}
157
158
ARMConstantPoolConstant *
159
ARMConstantPoolConstant::Create(const GlobalValue *GV,
160
337
                                ARMCP::ARMCPModifier Modifier) {
161
337
  return new ARMConstantPoolConstant((Type*)Type::getInt32Ty(GV->getContext()),
162
337
                                     GV, 0, ARMCP::CPValue, 0,
163
337
                                     Modifier, false);
164
337
}
165
166
ARMConstantPoolConstant *
167
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID,
168
62
                                ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
169
62
  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
170
62
                                     ARMCP::no_modifier, false);
171
62
}
172
173
ARMConstantPoolConstant *
174
ARMConstantPoolConstant::Create(const Constant *C, unsigned ID,
175
                                ARMCP::ARMCPKind Kind, unsigned char PCAdj,
176
                                ARMCP::ARMCPModifier Modifier,
177
921
                                bool AddCurrentAddress) {
178
921
  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
179
921
                                     AddCurrentAddress);
180
921
}
181
182
1.14k
const GlobalValue *ARMConstantPoolConstant::getGV() const {
183
1.14k
  return dyn_cast_or_null<GlobalValue>(CVal);
184
1.14k
}
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.41k
                                                       unsigned Alignment) {
192
1.41k
  int index =
193
1.41k
    getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
194
1.41k
  if (
index != -11.41k
) {
195
131
    auto *CPV = static_cast<ARMConstantPoolValue*>(
196
131
        CP->getConstants()[index].Val.MachineCPVal);
197
131
    auto *Constant = cast<ARMConstantPoolConstant>(CPV);
198
131
    Constant->GVars.insert(GVars.begin(), GVars.end());
199
131
  }
200
1.41k
  return index;
201
1.41k
}
202
203
1
bool ARMConstantPoolConstant::hasSameValue(ARMConstantPoolValue *ACPV) {
204
1
  const ARMConstantPoolConstant *ACPC = dyn_cast<ARMConstantPoolConstant>(ACPV);
205
1
  return ACPC && 
ACPC->CVal == CVal1
&&
ARMConstantPoolValue::hasSameValue(ACPV)1
;
206
1
}
207
208
395
void ARMConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
209
395
  ID.AddPointer(CVal);
210
395
  for (const auto *GV : GVars)
211
109
    ID.AddPointer(GV);
212
395
  ARMConstantPoolValue::addSelectionDAGCSEId(ID);
213
395
}
214
215
6
void ARMConstantPoolConstant::print(raw_ostream &O) const {
216
6
  O << CVal->getName();
217
6
  ARMConstantPoolValue::print(O);
218
6
}
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 == S0
&&
ARMConstantPoolValue::hasSameValue(ACPV)0
;
246
0
}
247
248
14
void ARMConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID &ID) {
249
14
  ID.AddString(S);
250
14
  ARMConstantPoolValue::addSelectionDAGCSEId(ID);
251
14
}
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
31
    MBB(mbb) {}
270
271
ARMConstantPoolMBB *ARMConstantPoolMBB::Create(LLVMContext &C,
272
                                               const MachineBasicBlock *mbb,
273
                                               unsigned ID,
274
31
                                               unsigned char PCAdj) {
275
31
  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
276
31
}
277
278
int ARMConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool *CP,
279
31
                                                  unsigned Alignment) {
280
31
  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
281
31
}
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 << "BB#" << MBB->getNumber();
296
0
  ARMConstantPoolValue::print(O);
297
0
}