LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
22 #include <cstdlib>
23 using namespace llvm;
24 
25 //===----------------------------------------------------------------------===//
26 // ARMConstantPoolValue
27 //===----------------------------------------------------------------------===//
28 
30  ARMCP::ARMCPKind kind,
31  unsigned char PCAdj,
32  ARMCP::ARMCPModifier modifier,
33  bool addCurrentAddress)
34  : MachineConstantPoolValue(Ty), LabelId(id), Kind(kind),
35  PCAdjust(PCAdj), Modifier(modifier),
36  AddCurrentAddress(addCurrentAddress) {}
37 
39  ARMCP::ARMCPKind kind,
40  unsigned char PCAdj,
41  ARMCP::ARMCPModifier modifier,
42  bool addCurrentAddress)
43  : MachineConstantPoolValue((Type*)Type::getInt32Ty(C)),
44  LabelId(id), Kind(kind), PCAdjust(PCAdj), Modifier(modifier),
45  AddCurrentAddress(addCurrentAddress) {}
46 
48 
50  switch (Modifier) {
51  // FIXME: Are these case sensitive? It'd be nice to lower-case all the
52  // strings if that's legal.
53  case ARMCP::no_modifier: return "none";
54  case ARMCP::TLSGD: return "tlsgd";
55  case ARMCP::GOT: return "GOT";
56  case ARMCP::GOTOFF: return "GOTOFF";
57  case ARMCP::GOTTPOFF: return "gottpoff";
58  case ARMCP::TPOFF: return "tpoff";
59  }
60  llvm_unreachable("Unknown modifier!");
61 }
62 
64  unsigned Alignment) {
65  llvm_unreachable("Shouldn't be calling this directly!");
66 }
67 
68 void
70  ID.AddInteger(LabelId);
71  ID.AddInteger(PCAdjust);
72 }
73 
74 bool
76  if (ACPV->Kind == Kind &&
77  ACPV->PCAdjust == PCAdjust &&
78  ACPV->Modifier == Modifier) {
79  if (ACPV->LabelId == LabelId)
80  return true;
81  // Two PC relative constpool entries containing the same GV address or
82  // external symbols. FIXME: What about blockaddress?
83  if (Kind == ARMCP::CPValue || Kind == ARMCP::CPExtSymbol)
84  return true;
85  }
86  return false;
87 }
88 
90  errs() << " " << *this;
91 }
92 
94  if (Modifier) O << "(" << getModifierText() << ")";
95  if (PCAdjust != 0) {
96  O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
97  if (AddCurrentAddress) O << "-.";
98  O << ")";
99  }
100 }
101 
102 //===----------------------------------------------------------------------===//
103 // ARMConstantPoolConstant
104 //===----------------------------------------------------------------------===//
105 
106 ARMConstantPoolConstant::ARMConstantPoolConstant(Type *Ty,
107  const Constant *C,
108  unsigned ID,
110  unsigned char PCAdj,
111  ARMCP::ARMCPModifier Modifier,
112  bool AddCurrentAddress)
113  : ARMConstantPoolValue(Ty, ID, Kind, PCAdj, Modifier, AddCurrentAddress),
114  CVal(C) {}
115 
116 ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C,
117  unsigned ID,
119  unsigned char PCAdj,
120  ARMCP::ARMCPModifier Modifier,
121  bool AddCurrentAddress)
122  : ARMConstantPoolValue((Type*)C->getType(), ID, Kind, PCAdj, Modifier,
123  AddCurrentAddress),
124  CVal(C) {}
125 
128  return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0,
129  ARMCP::no_modifier, false);
130 }
131 
134  ARMCP::ARMCPModifier Modifier) {
136  GV, 0, ARMCP::CPValue, 0,
137  Modifier, false);
138 }
139 
142  ARMCP::ARMCPKind Kind, unsigned char PCAdj) {
143  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj,
144  ARMCP::no_modifier, false);
145 }
146 
149  ARMCP::ARMCPKind Kind, unsigned char PCAdj,
150  ARMCP::ARMCPModifier Modifier,
151  bool AddCurrentAddress) {
152  return new ARMConstantPoolConstant(C, ID, Kind, PCAdj, Modifier,
153  AddCurrentAddress);
154 }
155 
157  return dyn_cast_or_null<GlobalValue>(CVal);
158 }
159 
161  return dyn_cast_or_null<BlockAddress>(CVal);
162 }
163 
165  unsigned Alignment) {
166  return getExistingMachineCPValueImpl<ARMConstantPoolConstant>(CP, Alignment);
167 }
168 
171  return ACPC && ACPC->CVal == CVal && ARMConstantPoolValue::hasSameValue(ACPV);
172 }
173 
175  ID.AddPointer(CVal);
177 }
178 
180  O << CVal->getName();
182 }
183 
184 //===----------------------------------------------------------------------===//
185 // ARMConstantPoolSymbol
186 //===----------------------------------------------------------------------===//
187 
188 ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext &C, const char *s,
189  unsigned id,
190  unsigned char PCAdj,
191  ARMCP::ARMCPModifier Modifier,
192  bool AddCurrentAddress)
193  : ARMConstantPoolValue(C, id, ARMCP::CPExtSymbol, PCAdj, Modifier,
194  AddCurrentAddress),
195  S(s) {}
196 
199  unsigned ID, unsigned char PCAdj) {
200  return new ARMConstantPoolSymbol(C, s, ID, PCAdj, ARMCP::no_modifier, false);
201 }
202 
204  unsigned Alignment) {
205  return getExistingMachineCPValueImpl<ARMConstantPoolSymbol>(CP, Alignment);
206 }
207 
210  return ACPS && ACPS->S == S && ARMConstantPoolValue::hasSameValue(ACPV);
211 }
212 
214  ID.AddString(S);
216 }
217 
219  O << S;
221 }
222 
223 //===----------------------------------------------------------------------===//
224 // ARMConstantPoolMBB
225 //===----------------------------------------------------------------------===//
226 
227 ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext &C,
228  const MachineBasicBlock *mbb,
229  unsigned id, unsigned char PCAdj,
230  ARMCP::ARMCPModifier Modifier,
231  bool AddCurrentAddress)
232  : ARMConstantPoolValue(C, id, ARMCP::CPMachineBasicBlock, PCAdj,
233  Modifier, AddCurrentAddress),
234  MBB(mbb) {}
235 
237  const MachineBasicBlock *mbb,
238  unsigned ID,
239  unsigned char PCAdj) {
240  return new ARMConstantPoolMBB(C, mbb, ID, PCAdj, ARMCP::no_modifier, false);
241 }
242 
244  unsigned Alignment) {
245  return getExistingMachineCPValueImpl<ARMConstantPoolMBB>(CP, Alignment);
246 }
247 
249  const ARMConstantPoolMBB *ACPMBB = dyn_cast<ARMConstantPoolMBB>(ACPV);
250  return ACPMBB && ACPMBB->MBB == MBB &&
252 }
253 
255  ID.AddPointer(MBB);
257 }
258 
260  O << "BB#" << MBB->getNumber();
262 }
void AddPointer(const void *Ptr)
Definition: FoldingSet.cpp:52
The machine constant pool.
raw_ostream & errs()
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:266
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
const char * getModifierText() const
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Definition: Function.cpp:657
const GlobalValue * getGV() const
ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, bool AddCurrentAddress)
StringRef getName() const
Definition: Value.cpp:167
#define llvm_unreachable(msg)
void AddInteger(signed I)
Definition: FoldingSet.cpp:60
virtual void print(raw_ostream &O) const
print - Implement operator<<
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
const BlockAddress * getBlockAddress() const
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)
virtual void print(raw_ostream &O) const
print - Implement operator<<
LLVM Constant Representation.
Definition: Constant.h:41
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
virtual bool hasSameValue(ARMConstantPoolValue *ACPV)
LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:517
static ARMConstantPoolMBB * Create(LLVMContext &C, const MachineBasicBlock *mbb, unsigned ID, unsigned char PCAdj)
static ARMConstantPoolSymbol * Create(LLVMContext &C, const char *s, unsigned ID, unsigned char PCAdj)
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:241
void AddString(StringRef String)
Definition: FoldingSet.cpp:87
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)
virtual void print(raw_ostream &O) const
print - Implement operator<<
virtual void print(raw_ostream &O) const
print - Implement operator<<
static ARMConstantPoolConstant * Create(const Constant *C, unsigned ID)