LLVM  6.0.0svn
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/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"
25 
26 using namespace llvm;
27 
28 //===----------------------------------------------------------------------===//
29 // ARMConstantPoolValue
30 //===----------------------------------------------------------------------===//
31 
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  AddCurrentAddress(addCurrentAddress) {}
40 
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  AddCurrentAddress(addCurrentAddress) {}
49 
51 
53  switch (Modifier) {
54  // FIXME: Are these case sensitive? It'd be nice to lower-case all the
55  // strings if that's legal.
56  case ARMCP::no_modifier:
57  return "none";
58  case ARMCP::TLSGD:
59  return "tlsgd";
60  case ARMCP::GOT_PREL:
61  return "GOT_PREL";
62  case ARMCP::GOTTPOFF:
63  return "gottpoff";
64  case ARMCP::TPOFF:
65  return "tpoff";
66  case ARMCP::SBREL:
67  return "SBREL";
68  case ARMCP::SECREL:
69  return "secrel32";
70  }
71  llvm_unreachable("Unknown modifier!");
72 }
73 
75  unsigned Alignment) {
76  llvm_unreachable("Shouldn't be calling this directly!");
77 }
78 
79 void
81  ID.AddInteger(LabelId);
82  ID.AddInteger(PCAdjust);
83 }
84 
85 bool
87  if (ACPV->Kind == Kind &&
88  ACPV->PCAdjust == PCAdjust &&
89  ACPV->Modifier == Modifier &&
90  ACPV->LabelId == LabelId &&
91  ACPV->AddCurrentAddress == AddCurrentAddress) {
92  // Two PC relative constpool entries containing the same GV address or
93  // external symbols. FIXME: What about blockaddress?
94  if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
95  return true;
96  }
97  return false;
98 }
99 
100 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
102  errs() << " " << *this;
103 }
104 #endif
105 
107  if (Modifier) O << "(" << getModifierText() << ")";
108  if (PCAdjust != 0) {
109  O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
110  if (AddCurrentAddress) O << "-.";
111  O << ")";
112  }
113 }
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  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  CVal(C) {}
138 
139 ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV,
140  const Constant *C)
142  ARMCP::no_modifier, false), CVal(C) {
143  GVars.insert(GV);
144 }
145 
148  return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
149  ARMCP::no_modifier, false);
150 }
151 
154  const Constant *Initializer) {
155  return new ARMConstantPoolConstant(GVar, Initializer);
156 }
157 
160  ARMCP::ARMCPModifier Modifier) {
162  GV, 0, ARMCP::CPValue, 0,
163  Modifier, false);
164 }
165 
168  ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
169  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
170  ARMCP::no_modifier, false);
171 }
172 
175  ARMCP::ARMCPKind Kind, unsigned char PCAdj,
176  ARMCP::ARMCPModifier Modifier,
177  bool AddCurrentAddress) {
178  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
179  AddCurrentAddress);
180 }
181 
183  return dyn_cast_or_null<GlobalValue>(CVal);
184 }
185 
187  return dyn_cast_or_null<BlockAddress>(CVal);
188 }
189 
191  unsigned Alignment) {
192  int index =
193  getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
194  if (index != -1) {
195  auto *CPV = static_cast<ARMConstantPoolValue*>(
196  CP->getConstants()[index].Val.MachineCPVal);
197  auto *Constant = cast<ARMConstantPoolConstant>(CPV);
198  Constant->GVars.insert(GVars.begin(), GVars.end());
199  }
200  return index;
201 }
202 
205  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
206 }
207 
209  ID.AddPointer(CVal);
210  for (const auto *GV : GVars)
211  ID.AddPointer(GV);
213 }
214 
216  O << CVal->getName();
218 }
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  S(s) {}
231 
233  StringRef s, unsigned ID,
234  unsigned char PCAdj) {
235  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
236 }
237 
239  unsigned Alignment) {
240  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
241 }
242 
245  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
246 }
247 
249  ID.AddString(S);
251 }
252 
254  O << S;
256 }
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)
268  Modifier, AddCurrentAddress),
269  MBB(mbb) {}
270 
272  const MachineBasicBlock *mbb,
273  unsigned ID,
274  unsigned char PCAdj) {
275  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
276 }
277 
279  unsigned Alignment) {
280  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
281 }
282 
284  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
285  return ACPMBB && ACPMBB->MBB == MBB &&
287 }
288 
290  ID.AddPointer(MBB);
292 }
293 
295  O << "BB#" << MBB->getNumber();
297 }
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)
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
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:697
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:813
int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) override
void AddInteger(signed I)
Definition: FoldingSet.cpp:61
void print(raw_ostream &O) const override
print - Implement operator<<
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:311
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:44
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)