718ec1828b8507bace4c15700ba1c754bbd69464
[oota-llvm.git] / lib / Target / ARM / ARMConstantPoolValue.h
1 //===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===//
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 #ifndef LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
15 #define LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
16
17 #include "llvm/CodeGen/MachineConstantPool.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include <cstddef>
20
21 namespace llvm {
22
23 class BlockAddress;
24 class Constant;
25 class GlobalValue;
26 class LLVMContext;
27 class MachineBasicBlock;
28
29 namespace ARMCP {
30   enum ARMCPKind {
31     CPValue,
32     CPExtSymbol,
33     CPBlockAddress,
34     CPLSDA,
35     CPMachineBasicBlock
36   };
37
38   enum ARMCPModifier {
39     no_modifier,
40     TLSGD,
41     GOT,
42     GOTOFF,
43     GOTTPOFF,
44     TPOFF
45   };
46 }
47
48 /// ARMConstantPoolValue - ARM specific constantpool value. This is used to
49 /// represent PC-relative displacement between the address of the load
50 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
51 class ARMConstantPoolValue : public MachineConstantPoolValue {
52   const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
53   unsigned LabelId;        // Label id of the load.
54   ARMCP::ARMCPKind Kind;   // Kind of constant.
55   unsigned char PCAdjust;  // Extra adjustment if constantpool is pc-relative.
56                            // 8 for ARM, 4 for Thumb.
57   ARMCP::ARMCPModifier Modifier;   // GV modifier i.e. (&GV(modifier)-(LPIC+8))
58   bool AddCurrentAddress;
59
60 protected:
61   ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
62                        unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
63                        bool AddCurrentAddress);
64
65   ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind,
66                        unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
67                        bool AddCurrentAddress);
68 public:
69   ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id,
70                        ARMCP::ARMCPKind Kind = ARMCP::CPValue,
71                        unsigned char PCAdj = 0,
72                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
73                        bool AddCurrentAddress = false);
74   virtual ~ARMConstantPoolValue();
75
76   const MachineBasicBlock *getMBB() const;
77
78   ARMCP::ARMCPModifier getModifier() const { return Modifier; }
79   const char *getModifierText() const;
80   bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
81
82   bool mustAddCurrentAddress() const { return AddCurrentAddress; }
83
84   unsigned getLabelId() const { return LabelId; }
85   unsigned char getPCAdjustment() const { return PCAdjust; }
86
87   bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
88   bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
89   bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
90   bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
91   bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
92
93   virtual unsigned getRelocationInfo() const { return 2; }
94
95   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
96                                         unsigned Alignment);
97
98   virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
99
100   /// hasSameValue - Return true if this ARM constpool value can share the same
101   /// constantpool entry as another ARM constpool value.
102   virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
103
104   virtual void print(raw_ostream &O) const;
105   void print(raw_ostream *O) const { if (O) print(*O); }
106   void dump() const;
107
108   static bool classof(const ARMConstantPoolValue *) { return true; }
109 };
110
111 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
112   V.print(O);
113   return O;
114 }
115
116 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
117 /// Functions, and BlockAddresses.
118 class ARMConstantPoolConstant : public ARMConstantPoolValue {
119   const Constant *CVal;         // Constant being loaded.
120
121   ARMConstantPoolConstant(const Constant *C,
122                           unsigned ID,
123                           ARMCP::ARMCPKind Kind,
124                           unsigned char PCAdj,
125                           ARMCP::ARMCPModifier Modifier,
126                           bool AddCurrentAddress);
127   ARMConstantPoolConstant(Type *Ty, const Constant *C,
128                           unsigned ID,
129                           ARMCP::ARMCPKind Kind,
130                           unsigned char PCAdj,
131                           ARMCP::ARMCPModifier Modifier,
132                           bool AddCurrentAddress);
133
134 public:
135   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
136   static ARMConstantPoolConstant *Create(const GlobalValue *GV,
137                                          ARMCP::ARMCPModifier Modifier);
138   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
139                                          ARMCP::ARMCPKind Kind,
140                                          unsigned char PCAdj);
141   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
142                                          ARMCP::ARMCPKind Kind,
143                                          unsigned char PCAdj,
144                                          ARMCP::ARMCPModifier Modifier,
145                                          bool AddCurrentAddress);
146
147   const GlobalValue *getGV() const;
148   const BlockAddress *getBlockAddress() const;
149
150   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
151                                         unsigned Alignment);
152
153   /// hasSameValue - Return true if this ARM constpool value can share the same
154   /// constantpool entry as another ARM constpool value.
155   virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
156
157   virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
158
159   virtual void print(raw_ostream &O) const;
160   static bool classof(const ARMConstantPoolValue *APV) {
161     return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
162   }
163   static bool classof(const ARMConstantPoolConstant *) { return true; }
164 };
165
166 /// ARMConstantPoolSymbol - ARM-specific constantpool values for external
167 /// symbols.
168 class ARMConstantPoolSymbol : public ARMConstantPoolValue {
169   const char *S;                // ExtSymbol being loaded.
170
171   ARMConstantPoolSymbol(LLVMContext &C, const char *s, unsigned id,
172                         unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
173                         bool AddCurrentAddress);
174
175 public:
176   ~ARMConstantPoolSymbol();
177
178   static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s,
179                                        unsigned ID, unsigned char PCAdj);
180
181   static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s,
182                                        unsigned ID, unsigned char PCAdj,
183                                        ARMCP::ARMCPModifier Modifier,
184                                        bool AddCurrentAddress);
185
186   const char *getSymbol() const { return S; }
187
188   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
189                                         unsigned Alignment);
190
191   virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
192
193   /// hasSameValue - Return true if this ARM constpool value can share the same
194   /// constantpool entry as another ARM constpool value.
195   virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
196
197   virtual void print(raw_ostream &O) const;
198
199   static bool classof(const ARMConstantPoolValue *ACPV) {
200     return ACPV->isExtSymbol();
201   }
202   static bool classof(const ARMConstantPoolSymbol *) { return true; }
203 };
204
205 } // End llvm namespace
206
207 #endif