LLVM  8.0.1
ARMConstantPoolValue.cpp
Go to the documentation of this file.
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"
17 #include "llvm/Config/llvm-config.h"
18 #include "llvm/IR/Constant.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/GlobalValue.h"
21 #include "llvm/IR/Type.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/Compiler.h"
26 
27 using namespace llvm;
28 
29 //===----------------------------------------------------------------------===//
30 // ARMConstantPoolValue
31 //===----------------------------------------------------------------------===//
32 
34  ARMCP::ARMCPKind kind,
35  unsigned char PCAdj,
36  ARMCP::ARMCPModifier modifier,
37  bool addCurrentAddress)
38  : MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
39  PCAdjust(PCAdj), Modifier(modifier),
40  AddCurrentAddress(addCurrentAddress) {}
41 
43  ARMCP::ARMCPKind kind,
44  unsigned char PCAdj,
45  ARMCP::ARMCPModifier modifier,
46  bool addCurrentAddress)
47  : MachineConstantPoolValue((Type*)Type::getInt32Ty(C)),
48  LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier),
49  AddCurrentAddress(addCurrentAddress) {}
50 
52 
54  switch (Modifier) {
55  // FIXME: Are these case sensitive? It'd be nice to lower-case all the
56  // strings if that's legal.
57  case ARMCP::no_modifier:
58  return "none";
59  case ARMCP::TLSGD:
60  return "tlsgd";
61  case ARMCP::GOT_PREL:
62  return "GOT_PREL";
63  case ARMCP::GOTTPOFF:
64  return "gottpoff";
65  case ARMCP::TPOFF:
66  return "tpoff";
67  case ARMCP::SBREL:
68  return "SBREL";
69  case ARMCP::SECREL:
70  return "secrel32";
71  }
72  llvm_unreachable("Unknown modifier!");
73 }
74 
76  unsigned Alignment) {
77  llvm_unreachable("Shouldn't be calling this directly!");
78 }
79 
80 void
82  ID.AddInteger(LabelId);
83  ID.AddInteger(PCAdjust);
84 }
85 
86 bool
88  if (ACPV->Kind == Kind &&
89  ACPV->PCAdjust == PCAdjust &&
90  ACPV->Modifier == Modifier &&
91  ACPV->LabelId == LabelId &&
92  ACPV->AddCurrentAddress == AddCurrentAddress) {
93  // Two PC relative constpool entries containing the same GV address or
94  // external symbols. FIXME: What about blockaddress?
95  if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
96  return true;
97  }
98  return false;
99 }
100 
101 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
103  errs() << " " << *this;
104 }
105 #endif
106 
108  if (Modifier) O << "(" << getModifierText() << ")";
109  if (PCAdjust != 0) {
110  O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
111  if (AddCurrentAddress) O << "-.";
112  O << ")";
113  }
114 }
115 
116 //===----------------------------------------------------------------------===//
117 // ARMConstantPoolConstant
118 //===----------------------------------------------------------------------===//
119 
120 ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty,
121  const Constant *C,
122  unsigned ID,
123  ARMCP::ARMCPKind Kind,
124  unsigned char PCAdj,
125  ARMCP::ARMCPModifier Modifier,
126  bool AddCurrentAddress)
127  : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress),
128  CVal(C) {}
129 
130 ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
131  unsigned ID,
132  ARMCP::ARMCPKind Kind,
133  unsigned char PCAdj,
134  ARMCP::ARMCPModifier Modifier,
135  bool AddCurrentAddress)
136  : ARMConstantPoolValue((Type*)C->getType(), ID, Kind, PCAdj, Modifier,
137  AddCurrentAddress),
138  CVal(C) {}
139 
140 ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
141  const Constant *C)
143  ARMCP::no_modifier, false), CVal(C) {
144  GVars.insert(GV);
145 }
146 
149  return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
150  ARMCP::no_modifier, false);
151 }
152 
155  const Constant *Initializer) {
156  return new ARMConstantPoolConstant(GVar, Initializer);
157 }
158 
161  ARMCP::ARMCPModifier Modifier) {
163  GV, 0, ARMCP::CPValue, 0,
164  Modifier, false);
165 }
166 
169  ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
170  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
171  ARMCP::no_modifier, false);
172 }
173 
176  ARMCP::ARMCPKind Kind, unsigned char PCAdj,
177  ARMCP::ARMCPModifier Modifier,
178  bool AddCurrentAddress) {
179  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
180  AddCurrentAddress);
181 }
182 
184  return dyn_cast_or_null<GlobalValue>(CVal);
185 }
186 
188  return dyn_cast_or_null<BlockAddress>(CVal);
189 }
190 
192  unsigned Alignment) {
193  int index =
194  getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
195  if (index != -1) {
196  auto *CPV = static_cast<ARMConstantPoolValue*>(
197  CP->getConstants()[index].Val.MachineCPVal);
198  auto *Constant = cast<ARMConstantPoolConstant>(CPV);
199  Constant->GVars.insert(GVars.begin(), GVars.end());
200  }
201  return index;
202 }
203 
206  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
207 }
208 
210  ID.AddPointer(CVal);
211  for (const auto *GV : GVars)
212  ID.AddPointer(GV);
214 }
215 
217  O << CVal->getName();
219 }
220 
221 //===----------------------------------------------------------------------===//
222 // ARMConstantPoolSymbol
223 //===----------------------------------------------------------------------===//
224 
225 ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, StringRef s,
226  unsigned id, unsigned char PCAdj,
227  ARMCP::ARMCPModifier Modifier,
228  bool AddCurrentAddress)
229  : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
230  AddCurrentAddress),
231  S(s) {}
232 
234  StringRef s, unsigned ID,
235  unsigned char PCAdj) {
236  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
237 }
238 
240  unsigned Alignment) {
241  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
242 }
243 
246  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
247 }
248 
250  ID.AddString(S);
252 }
253 
255  O << S;
257 }
258 
259 //===----------------------------------------------------------------------===//
260 // ARMConstantPoolMBB
261 //===----------------------------------------------------------------------===//
262 
263 ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
264  const MachineBasicBlock *mbb,
265  unsigned id, unsigned char PCAdj,
266  ARMCP::ARMCPModifier Modifier,
267  bool AddCurrentAddress)
269  Modifier, AddCurrentAddress),
270  MBB(mbb) {}
271 
273  const MachineBasicBlock *mbb,
274  unsigned ID,
275  unsigned char PCAdj) {
276  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
277 }
278 
280  unsigned Alignment) {
281  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
282 }
283 
285  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
286  return ACPMBB && ACPMBB->MBB == MBB &&
288 }
289 
291  ID.AddPointer(MBB);
293 }
294 
296  O << printMBBReference(*MBB);
298 }
uint64_t CallInst * C
void AddPointer(const void *Ptr)
Add* - Add various data types to Bit data.
Definition: FoldingSet.cpp:52
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static ARMConstantPoolSymbol * Create(LLVMContext &C, StringRef s, unsigned ID, unsigned char PCAdj)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
ARMConstantPoolValue - ARM specific constantpool value.
Global Offset Table, Thread Pointer Offset.
const BlockAddress * getBlockAddress() const
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:705
Global Offset Table, PC Relative.
Thread Pointer Offset.
void print(raw_ostream &O) const override
print - Implement operator<<
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress)
The address of a basic block.
Definition: Constants.h:840
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
void AddInteger(signed I)
Definition: FoldingSet.cpp:61
void print(raw_ostream &O) const override
print - Implement operator<<
#define LLVM_DUMP_METHOD
Definition: Compiler.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:306
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
This is an important base class in LLVM.
Definition: Constant.h:42
This file contains the declarations for the subclasses of Constant, which represent the different fla...
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
Thread Local Storage (General Dynamic Mode)
Abstract base class for all machine specific constantpool value subclasses.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
static ARMConstantPoolMBB * Create(LLVMContext &C, const MachineBasicBlock *mbb, unsigned ID, unsigned char PCAdj)
void print(raw_ostream &O) const override
print - Implement operator<<
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const GlobalValue * getGV() const
ARMConstantPoolConstant - ARM-specific constant pool values for Constants, Functions, and BlockAddresses.
ARMConstantPoolSymbol - ARM-specific constantpool values for external symbols.
bool hasSameValue(ARMConstantPoolValue *ACPV) override
hasSameValue - Return true if this ARM constpool value can share the same constantpool entry as anoth...
ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic block.
void addSelectionDAGCSEId(FoldingSetNodeID &ID) override
void print(raw_ostream &O) const override
print - Implement operator<<
Section Relative (Windows TLS)
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:176
void AddString(StringRef String)
Definition: FoldingSet.cpp:87
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
const unsigned Kind
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
static ARMConstantPoolConstant * Create(const Constant *C, unsigned ID)