Remove now dead methods and ivar from ARMConstantPoolValue.
[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   const char *S;           // ExtSymbol being loaded.
54   unsigned LabelId;        // Label id of the load.
55   ARMCP::ARMCPKind Kind;   // Kind of constant.
56   unsigned char PCAdjust;  // Extra adjustment if constantpool is pc-relative.
57                            // 8 for ARM, 4 for Thumb.
58   ARMCP::ARMCPModifier Modifier;   // GV modifier i.e. (&GV(modifier)-(LPIC+8))
59   bool AddCurrentAddress;
60
61 protected:
62   ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
63                        unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
64                        bool AddCurrentAddress);
65
66 public:
67   ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id,
68                        ARMCP::ARMCPKind Kind = ARMCP::CPValue,
69                        unsigned char PCAdj = 0,
70                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
71                        bool AddCurrentAddress = false);
72   ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
73                        unsigned char PCAdj = 0,
74                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
75                        bool AddCurrentAddress = false);
76   ~ARMConstantPoolValue();
77
78   const char *getSymbol() const { return S; }
79   const MachineBasicBlock *getMBB() const;
80
81   ARMCP::ARMCPModifier getModifier() const { return Modifier; }
82   const char *getModifierText() const;
83   bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
84
85   bool mustAddCurrentAddress() const { return AddCurrentAddress; }
86
87   unsigned getLabelId() const { return LabelId; }
88   unsigned char getPCAdjustment() const { return PCAdjust; }
89
90   bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
91   bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
92   bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
93   bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
94   bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
95
96   virtual unsigned getRelocationInfo() const { return 2; }
97
98   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
99                                         unsigned Alignment);
100
101   virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
102
103   /// hasSameValue - Return true if this ARM constpool value can share the same
104   /// constantpool entry as another ARM constpool value.
105   virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
106
107   virtual void print(raw_ostream &O) const;
108   void print(raw_ostream *O) const { if (O) print(*O); }
109   void dump() const;
110
111   static bool classof(const ARMConstantPoolValue *) { return true; }
112 };
113
114 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
115   V.print(O);
116   return O;
117 }
118
119 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
120 /// Functions, and BlockAddresses.
121 class ARMConstantPoolConstant : public ARMConstantPoolValue {
122   const Constant *CVal;         // Constant being loaded.
123
124   ARMConstantPoolConstant(const Constant *C,
125                           unsigned ID,
126                           ARMCP::ARMCPKind Kind,
127                           unsigned char PCAdj,
128                           ARMCP::ARMCPModifier Modifier,
129                           bool AddCurrentAddress);
130   ARMConstantPoolConstant(Type *Ty, const Constant *C,
131                           unsigned ID,
132                           ARMCP::ARMCPKind Kind,
133                           unsigned char PCAdj,
134                           ARMCP::ARMCPModifier Modifier,
135                           bool AddCurrentAddress);
136
137 public:
138   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
139   static ARMConstantPoolConstant *Create(const GlobalValue *GV,
140                                          ARMCP::ARMCPModifier Modifier);
141   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
142                                          ARMCP::ARMCPKind Kind,
143                                          unsigned char PCAdj);
144   static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
145                                          ARMCP::ARMCPKind Kind,
146                                          unsigned char PCAdj,
147                                          ARMCP::ARMCPModifier Modifier,
148                                          bool AddCurrentAddress);
149
150   const GlobalValue *getGV() const;
151   const BlockAddress *getBlockAddress() const;
152
153   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
154                                         unsigned Alignment);
155
156   /// hasSameValue - Return true if this ARM constpool value can share the same
157   /// constantpool entry as another ARM constpool value.
158   virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
159
160   virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
161
162   virtual void print(raw_ostream &O) const;
163   static bool classof(const ARMConstantPoolValue *APV) {
164     return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
165   }
166   static bool classof(const ARMConstantPoolConstant *) { return true; }
167 };
168
169 } // End llvm namespace
170
171 #endif