1 //===-- ARMConstantPoolValue.cpp - ARM constantpool value -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the ARM specific constantpool value class.
12 //===----------------------------------------------------------------------===//
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/raw_ostream.h"
25 //===----------------------------------------------------------------------===//
26 // ARMConstantPoolValue
27 //===----------------------------------------------------------------------===//
29 ARMConstantPoolValue::ARMConstantPoolValue(Type
*Ty
, unsigned id
,
30 ARMCP::ARMCPKind kind
,
32 ARMCP::ARMCPModifier modifier
,
33 bool addCurrentAddress
)
34 : MachineConstantPoolValue(Ty
), LabelId(id
), Kind(kind
),
35 PCAdjust(PCAdj
), Modifier(modifier
),
36 AddCurrentAddress(addCurrentAddress
) {}
38 ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext
&C
, unsigned id
,
39 ARMCP::ARMCPKind kind
,
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
) {}
47 ARMConstantPoolValue::~ARMConstantPoolValue() {}
49 const char *ARMConstantPoolValue::getModifierText() const {
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
:
68 llvm_unreachable("Unknown modifier!");
71 int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool
*CP
,
73 llvm_unreachable("Shouldn't be calling this directly!");
77 ARMConstantPoolValue::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
78 ID
.AddInteger(LabelId
);
79 ID
.AddInteger(PCAdjust
);
83 ARMConstantPoolValue::hasSameValue(ARMConstantPoolValue
*ACPV
) {
84 if (ACPV
->Kind
== Kind
&&
85 ACPV
->PCAdjust
== PCAdjust
&&
86 ACPV
->Modifier
== Modifier
&&
87 ACPV
->LabelId
== LabelId
&&
88 ACPV
->AddCurrentAddress
== AddCurrentAddress
) {
89 // Two PC relative constpool entries containing the same GV address or
90 // external symbols. FIXME: What about blockaddress?
91 if (Kind
== ARMCP::CPValue
|| Kind
== ARMCP::CPExtSymbol
)
97 LLVM_DUMP_METHOD
void ARMConstantPoolValue::dump() const {
98 errs() << " " << *this;
101 void ARMConstantPoolValue::print(raw_ostream
&O
) const {
102 if (Modifier
) O
<< "(" << getModifierText() << ")";
104 O
<< "-(LPC" << LabelId
<< "+" << (unsigned)PCAdjust
;
105 if (AddCurrentAddress
) O
<< "-.";
110 //===----------------------------------------------------------------------===//
111 // ARMConstantPoolConstant
112 //===----------------------------------------------------------------------===//
114 ARMConstantPoolConstant::ARMConstantPoolConstant(Type
*Ty
,
117 ARMCP::ARMCPKind Kind
,
119 ARMCP::ARMCPModifier Modifier
,
120 bool AddCurrentAddress
)
121 : ARMConstantPoolValue(Ty
, ID
, Kind
, PCAdj
, Modifier
, AddCurrentAddress
),
124 ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant
*C
,
126 ARMCP::ARMCPKind Kind
,
128 ARMCP::ARMCPModifier Modifier
,
129 bool AddCurrentAddress
)
130 : ARMConstantPoolValue((Type
*)C
->getType(), ID
, Kind
, PCAdj
, Modifier
,
134 ARMConstantPoolConstant
*
135 ARMConstantPoolConstant::Create(const Constant
*C
, unsigned ID
) {
136 return new ARMConstantPoolConstant(C
, ID
, ARMCP::CPValue
, 0,
137 ARMCP::no_modifier
, false);
140 ARMConstantPoolConstant
*
141 ARMConstantPoolConstant::Create(const GlobalValue
*GV
,
142 ARMCP::ARMCPModifier Modifier
) {
143 return new ARMConstantPoolConstant((Type
*)Type::getInt32Ty(GV
->getContext()),
144 GV
, 0, ARMCP::CPValue
, 0,
148 ARMConstantPoolConstant
*
149 ARMConstantPoolConstant::Create(const Constant
*C
, unsigned ID
,
150 ARMCP::ARMCPKind Kind
, unsigned char PCAdj
) {
151 return new ARMConstantPoolConstant(C
, ID
, Kind
, PCAdj
,
152 ARMCP::no_modifier
, false);
155 ARMConstantPoolConstant
*
156 ARMConstantPoolConstant::Create(const Constant
*C
, unsigned ID
,
157 ARMCP::ARMCPKind Kind
, unsigned char PCAdj
,
158 ARMCP::ARMCPModifier Modifier
,
159 bool AddCurrentAddress
) {
160 return new ARMConstantPoolConstant(C
, ID
, Kind
, PCAdj
, Modifier
,
164 const GlobalValue
*ARMConstantPoolConstant::getGV() const {
165 return dyn_cast_or_null
<GlobalValue
>(CVal
);
168 const BlockAddress
*ARMConstantPoolConstant::getBlockAddress() const {
169 return dyn_cast_or_null
<BlockAddress
>(CVal
);
172 int ARMConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool
*CP
,
173 unsigned Alignment
) {
174 return getExistingMachineCPValueImpl
<ARMConstantPoolConstant
>(CP
, Alignment
);
177 bool ARMConstantPoolConstant::hasSameValue(ARMConstantPoolValue
*ACPV
) {
178 const ARMConstantPoolConstant
*ACPC
= dyn_cast
<ARMConstantPoolConstant
>(ACPV
);
179 return ACPC
&& ACPC
->CVal
== CVal
&& ARMConstantPoolValue::hasSameValue(ACPV
);
182 void ARMConstantPoolConstant::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
184 ARMConstantPoolValue::addSelectionDAGCSEId(ID
);
187 void ARMConstantPoolConstant::print(raw_ostream
&O
) const {
188 O
<< CVal
->getName();
189 ARMConstantPoolValue::print(O
);
192 //===----------------------------------------------------------------------===//
193 // ARMConstantPoolSymbol
194 //===----------------------------------------------------------------------===//
196 ARMConstantPoolSymbol::ARMConstantPoolSymbol(LLVMContext
&C
, const char *s
,
199 ARMCP::ARMCPModifier Modifier
,
200 bool AddCurrentAddress
)
201 : ARMConstantPoolValue(C
, id
, ARMCP::CPExtSymbol
, PCAdj
, Modifier
,
205 ARMConstantPoolSymbol
*
206 ARMConstantPoolSymbol::Create(LLVMContext
&C
, const char *s
,
207 unsigned ID
, unsigned char PCAdj
) {
208 return new ARMConstantPoolSymbol(C
, s
, ID
, PCAdj
, ARMCP::no_modifier
, false);
211 int ARMConstantPoolSymbol::getExistingMachineCPValue(MachineConstantPool
*CP
,
212 unsigned Alignment
) {
213 return getExistingMachineCPValueImpl
<ARMConstantPoolSymbol
>(CP
, Alignment
);
216 bool ARMConstantPoolSymbol::hasSameValue(ARMConstantPoolValue
*ACPV
) {
217 const ARMConstantPoolSymbol
*ACPS
= dyn_cast
<ARMConstantPoolSymbol
>(ACPV
);
218 return ACPS
&& ACPS
->S
== S
&& ARMConstantPoolValue::hasSameValue(ACPV
);
221 void ARMConstantPoolSymbol::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
223 ARMConstantPoolValue::addSelectionDAGCSEId(ID
);
226 void ARMConstantPoolSymbol::print(raw_ostream
&O
) const {
228 ARMConstantPoolValue::print(O
);
231 //===----------------------------------------------------------------------===//
232 // ARMConstantPoolMBB
233 //===----------------------------------------------------------------------===//
235 ARMConstantPoolMBB::ARMConstantPoolMBB(LLVMContext
&C
,
236 const MachineBasicBlock
*mbb
,
237 unsigned id
, unsigned char PCAdj
,
238 ARMCP::ARMCPModifier Modifier
,
239 bool AddCurrentAddress
)
240 : ARMConstantPoolValue(C
, id
, ARMCP::CPMachineBasicBlock
, PCAdj
,
241 Modifier
, AddCurrentAddress
),
244 ARMConstantPoolMBB
*ARMConstantPoolMBB::Create(LLVMContext
&C
,
245 const MachineBasicBlock
*mbb
,
247 unsigned char PCAdj
) {
248 return new ARMConstantPoolMBB(C
, mbb
, ID
, PCAdj
, ARMCP::no_modifier
, false);
251 int ARMConstantPoolMBB::getExistingMachineCPValue(MachineConstantPool
*CP
,
252 unsigned Alignment
) {
253 return getExistingMachineCPValueImpl
<ARMConstantPoolMBB
>(CP
, Alignment
);
256 bool ARMConstantPoolMBB::hasSameValue(ARMConstantPoolValue
*ACPV
) {
257 const ARMConstantPoolMBB
*ACPMBB
= dyn_cast
<ARMConstantPoolMBB
>(ACPV
);
258 return ACPMBB
&& ACPMBB
->MBB
== MBB
&&
259 ARMConstantPoolValue::hasSameValue(ACPV
);
262 void ARMConstantPoolMBB::addSelectionDAGCSEId(FoldingSetNodeID
&ID
) {
264 ARMConstantPoolValue::addSelectionDAGCSEId(ID
);
267 void ARMConstantPoolMBB::print(raw_ostream
&O
) const {
268 O
<< "BB#" << MBB
->getNumber();
269 ARMConstantPoolValue::print(O
);