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"
16 #include "llvm/ADT/StringRef.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),
144  CVal(C), GVar(GV) {}
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  return getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
193 }
194 
197  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
198 }
199 
201  ID.AddPointer(CVal);
203 }
204 
206  O << CVal->getName();
208 }
209 
210 //===----------------------------------------------------------------------===//
211 // ARMConstantPoolSymbol
212 //===----------------------------------------------------------------------===//
213 
214 ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, StringRef s,
215  unsigned id, unsigned char PCAdj,
216  ARMCP::ARMCPModifier Modifier,
217  bool AddCurrentAddress)
218  : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
219  AddCurrentAddress),
220  S(s) {}
221 
223  StringRef s, unsigned ID,
224  unsigned char PCAdj) {
225  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
226 }
227 
229  unsigned Alignment) {
230  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
231 }
232 
235  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
236 }
237 
239  ID.AddString(S);
241 }
242 
244  O << S;
246 }
247 
248 //===----------------------------------------------------------------------===//
249 // ARMConstantPoolMBB
250 //===----------------------------------------------------------------------===//
251 
252 ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
253  const MachineBasicBlock *mbb,
254  unsigned id, unsigned char PCAdj,
255  ARMCP::ARMCPModifier Modifier,
256  bool AddCurrentAddress)
258  Modifier, AddCurrentAddress),
259  MBB(mbb) {}
260 
262  const MachineBasicBlock *mbb,
263  unsigned ID,
264  unsigned char PCAdj) {
265  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
266 }
267 
269  unsigned Alignment) {
270  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
271 }
272 
274  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
275  return ACPMBB && ACPMBB->MBB == MBB &&
277 }
278 
280  ID.AddPointer(MBB);
282 }
283 
285  O << "BB#" << MBB->getNumber();
287 }
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:68
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)