blob: 6b98d446b003bb5680e12c0ade6466a6057632d4 [file] [log] [blame]
Jia Liu31d157a2012-02-18 12:03:15 +00001//===-- ARMConstantPoolValue.h - ARM constantpool value ---------*- C++ -*-===//
Evan Chenga8e29892007-01-19 07:51:42 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ARM specific constantpool value class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
15#define LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
16
17#include "llvm/CodeGen/MachineConstantPool.h"
Jim Grosbach3a2429a2010-11-09 21:36:17 +000018#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarf4a7bf42010-06-15 14:50:42 +000019#include <cstddef>
Evan Chenga8e29892007-01-19 07:51:42 +000020
21namespace llvm {
22
Bob Wilson28989a82009-11-02 16:59:06 +000023class BlockAddress;
Bill Wendling4dd9b092011-09-29 23:48:44 +000024class Constant;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000025class GlobalValue;
Owen Anderson1d0be152009-08-13 21:58:54 +000026class LLVMContext;
Bill Wendling4dd9b092011-09-29 23:48:44 +000027class MachineBasicBlock;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000028
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000029namespace ARMCP {
30 enum ARMCPKind {
31 CPValue,
Bob Wilson28989a82009-11-02 16:59:06 +000032 CPExtSymbol,
33 CPBlockAddress,
Bill Wendling4dd9b092011-09-29 23:48:44 +000034 CPLSDA,
35 CPMachineBasicBlock
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000036 };
Jim Grosbach3a2429a2010-11-09 21:36:17 +000037
38 enum ARMCPModifier {
39 no_modifier,
40 TLSGD,
41 GOT,
42 GOTOFF,
43 GOTTPOFF,
44 TPOFF
45 };
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000046}
47
Evan Chenga8e29892007-01-19 07:51:42 +000048/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson31ba10b2009-11-02 17:10:37 +000049/// represent PC-relative displacement between the address of the load
Bob Wilson28989a82009-11-02 16:59:06 +000050/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Chenga8e29892007-01-19 07:51:42 +000051class ARMConstantPoolValue : public MachineConstantPoolValue {
Evan Chenga8e29892007-01-19 07:51:42 +000052 unsigned LabelId; // Label id of the load.
Bob Wilson28989a82009-11-02 16:59:06 +000053 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson31ba10b2009-11-02 17:10:37 +000054 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Chenga8e29892007-01-19 07:51:42 +000055 // 8 for ARM, 4 for Thumb.
Jim Grosbach3a2429a2010-11-09 21:36:17 +000056 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000057 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000058
Bill Wendlingf2b76aa2011-10-01 06:40:33 +000059protected:
60 ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
61 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
62 bool AddCurrentAddress);
63
Bill Wendlingff4a8022011-10-01 08:36:59 +000064 ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind,
65 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
66 bool AddCurrentAddress);
Evan Chenga8e29892007-01-19 07:51:42 +000067public:
Bill Wendlingff4a8022011-10-01 08:36:59 +000068 virtual ~ARMConstantPoolValue();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000069
Jim Grosbach3a2429a2010-11-09 21:36:17 +000070 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000071 const char *getModifierText() const;
Jim Grosbach3a2429a2010-11-09 21:36:17 +000072 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000073
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000074 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000075
Evan Chenga8e29892007-01-19 07:51:42 +000076 unsigned getLabelId() const { return LabelId; }
Evan Chenga8e29892007-01-19 07:51:42 +000077 unsigned char getPCAdjustment() const { return PCAdjust; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000078
Bob Wilson28989a82009-11-02 16:59:06 +000079 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
80 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
Bill Wendlingf2b76aa2011-10-01 06:40:33 +000081 bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000082 bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
Bill Wendling9c18f512011-10-01 09:19:10 +000083 bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; }
Evan Chenga8e29892007-01-19 07:51:42 +000084
Jim Grosbachcd3c7cb2010-11-29 23:09:20 +000085 virtual unsigned getRelocationInfo() const { return 2; }
Chris Lattnercb459632009-07-21 23:34:23 +000086
Evan Chenga8e29892007-01-19 07:51:42 +000087 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
88 unsigned Alignment);
89
Jim Grosbach5405d582011-09-27 20:59:33 +000090 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
Evan Chenga8e29892007-01-19 07:51:42 +000091
Bill Wendlingf2b76aa2011-10-01 06:40:33 +000092 /// hasSameValue - Return true if this ARM constpool value can share the same
93 /// constantpool entry as another ARM constpool value.
94 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
Evan Cheng78e5c112009-11-07 03:52:02 +000095
Bill Wendling405ca132011-10-01 12:44:28 +000096 bool equals(const ARMConstantPoolValue *A) const {
97 return this->LabelId == A->LabelId &&
98 this->PCAdjust == A->PCAdjust &&
99 this->Modifier == A->Modifier;
100 }
101
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000102 virtual void print(raw_ostream &O) const;
Evan Cheng5be59ea2008-10-29 23:55:17 +0000103 void print(raw_ostream *O) const { if (O) print(*O); }
Evan Cheng5be59ea2008-10-29 23:55:17 +0000104 void dump() const;
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000105
106 static bool classof(const ARMConstantPoolValue *) { return true; }
Evan Chenga8e29892007-01-19 07:51:42 +0000107};
Evan Cheng5be59ea2008-10-29 23:55:17 +0000108
Evan Cheng5be59ea2008-10-29 23:55:17 +0000109inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
110 V.print(O);
111 return O;
112}
113
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000114/// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
115/// Functions, and BlockAddresses.
116class ARMConstantPoolConstant : public ARMConstantPoolValue {
117 const Constant *CVal; // Constant being loaded.
118
119 ARMConstantPoolConstant(const Constant *C,
120 unsigned ID,
121 ARMCP::ARMCPKind Kind,
122 unsigned char PCAdj,
123 ARMCP::ARMCPModifier Modifier,
124 bool AddCurrentAddress);
Bill Wendling3e944e32011-10-01 07:52:37 +0000125 ARMConstantPoolConstant(Type *Ty, const Constant *C,
126 unsigned ID,
127 ARMCP::ARMCPKind Kind,
128 unsigned char PCAdj,
129 ARMCP::ARMCPModifier Modifier,
130 bool AddCurrentAddress);
131
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000132public:
133 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
Bill Wendling3e944e32011-10-01 07:52:37 +0000134 static ARMConstantPoolConstant *Create(const GlobalValue *GV,
135 ARMCP::ARMCPModifier Modifier);
Bill Wendling029e93882011-10-01 06:44:24 +0000136 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
137 ARMCP::ARMCPKind Kind,
138 unsigned char PCAdj);
Bill Wendling3e944e32011-10-01 07:52:37 +0000139 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
140 ARMCP::ARMCPKind Kind,
141 unsigned char PCAdj,
142 ARMCP::ARMCPModifier Modifier,
143 bool AddCurrentAddress);
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000144
145 const GlobalValue *getGV() const;
Bill Wendling3e944e32011-10-01 07:52:37 +0000146 const BlockAddress *getBlockAddress() const;
147
148 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
149 unsigned Alignment);
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000150
151 /// hasSameValue - Return true if this ARM constpool value can share the same
152 /// constantpool entry as another ARM constpool value.
153 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
154
155 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
156
157 virtual void print(raw_ostream &O) const;
158 static bool classof(const ARMConstantPoolValue *APV) {
159 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
160 }
161 static bool classof(const ARMConstantPoolConstant *) { return true; }
162};
163
Bill Wendlingff4a8022011-10-01 08:36:59 +0000164/// ARMConstantPoolSymbol - ARM-specific constantpool values for external
165/// symbols.
166class ARMConstantPoolSymbol : public ARMConstantPoolValue {
167 const char *S; // ExtSymbol being loaded.
168
169 ARMConstantPoolSymbol(LLVMContext &C, const char *s, unsigned id,
170 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
171 bool AddCurrentAddress);
172
173public:
174 ~ARMConstantPoolSymbol();
175
176 static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s,
Bill Wendlingfe31e672011-10-01 08:58:29 +0000177 unsigned ID, unsigned char PCAdj);
178
Bill Wendlingff4a8022011-10-01 08:36:59 +0000179 const char *getSymbol() const { return S; }
180
181 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
182 unsigned Alignment);
183
184 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
185
186 /// hasSameValue - Return true if this ARM constpool value can share the same
187 /// constantpool entry as another ARM constpool value.
188 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
189
190 virtual void print(raw_ostream &O) const;
191
192 static bool classof(const ARMConstantPoolValue *ACPV) {
193 return ACPV->isExtSymbol();
194 }
195 static bool classof(const ARMConstantPoolSymbol *) { return true; }
196};
197
Bill Wendling9c18f512011-10-01 09:19:10 +0000198/// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
199/// block.
200class ARMConstantPoolMBB : public ARMConstantPoolValue {
Bill Wendling3320f2a2011-10-01 09:30:42 +0000201 const MachineBasicBlock *MBB; // Machine basic block.
Bill Wendling9c18f512011-10-01 09:19:10 +0000202
Bill Wendling3320f2a2011-10-01 09:30:42 +0000203 ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
Bill Wendling9c18f512011-10-01 09:19:10 +0000204 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
205 bool AddCurrentAddress);
206
207public:
Bill Wendling3320f2a2011-10-01 09:30:42 +0000208 static ARMConstantPoolMBB *Create(LLVMContext &C,
209 const MachineBasicBlock *mbb,
Bill Wendling9c18f512011-10-01 09:19:10 +0000210 unsigned ID, unsigned char PCAdj);
211
212 const MachineBasicBlock *getMBB() const { return MBB; }
213
214 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
215 unsigned Alignment);
216
217 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
218
219 /// hasSameValue - Return true if this ARM constpool value can share the same
220 /// constantpool entry as another ARM constpool value.
221 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
222
223 virtual void print(raw_ostream &O) const;
224
225 static bool classof(const ARMConstantPoolValue *ACPV) {
226 return ACPV->isMachineBasicBlock();
227 }
228 static bool classof(const ARMConstantPoolMBB *) { return true; }
229};
230
Evan Cheng5be59ea2008-10-29 23:55:17 +0000231} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +0000232
233#endif