Jia Liu | 31d157a | 2012-02-18 12:03:15 +0000 | [diff] [blame] | 1 | //===-- ARMConstantPoolValue.h - ARM constantpool value ---------*- C++ -*-===// |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 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" |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | f4a7bf4 | 2010-06-15 14:50:42 +0000 | [diff] [blame] | 19 | #include <cstddef> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 23 | class BlockAddress; |
Bill Wendling | 4dd9b09 | 2011-09-29 23:48:44 +0000 | [diff] [blame] | 24 | class Constant; |
Dan Gohman | dc2fbdd | 2008-07-11 20:38:31 +0000 | [diff] [blame] | 25 | class GlobalValue; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 26 | class LLVMContext; |
Bill Wendling | 4dd9b09 | 2011-09-29 23:48:44 +0000 | [diff] [blame] | 27 | class MachineBasicBlock; |
Dan Gohman | dc2fbdd | 2008-07-11 20:38:31 +0000 | [diff] [blame] | 28 | |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 29 | namespace ARMCP { |
| 30 | enum ARMCPKind { |
| 31 | CPValue, |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 32 | CPExtSymbol, |
| 33 | CPBlockAddress, |
Bill Wendling | 4dd9b09 | 2011-09-29 23:48:44 +0000 | [diff] [blame] | 34 | CPLSDA, |
| 35 | CPMachineBasicBlock |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 36 | }; |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 37 | |
| 38 | enum ARMCPModifier { |
| 39 | no_modifier, |
| 40 | TLSGD, |
| 41 | GOT, |
| 42 | GOTOFF, |
| 43 | GOTTPOFF, |
| 44 | TPOFF |
| 45 | }; |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 48 | /// ARMConstantPoolValue - ARM specific constantpool value. This is used to |
Bob Wilson | 31ba10b | 2009-11-02 17:10:37 +0000 | [diff] [blame] | 49 | /// represent PC-relative displacement between the address of the load |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 50 | /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)). |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 51 | class ARMConstantPoolValue : public MachineConstantPoolValue { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 52 | unsigned LabelId; // Label id of the load. |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 53 | ARMCP::ARMCPKind Kind; // Kind of constant. |
Bob Wilson | 31ba10b | 2009-11-02 17:10:37 +0000 | [diff] [blame] | 54 | unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 55 | // 8 for ARM, 4 for Thumb. |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 56 | ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8)) |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 57 | bool AddCurrentAddress; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 58 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 59 | protected: |
| 60 | ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, |
| 61 | unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, |
| 62 | bool AddCurrentAddress); |
| 63 | |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 64 | ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind, |
| 65 | unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, |
| 66 | bool AddCurrentAddress); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 67 | public: |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 68 | virtual ~ARMConstantPoolValue(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 69 | |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 70 | ARMCP::ARMCPModifier getModifier() const { return Modifier; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 71 | const char *getModifierText() const; |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 72 | bool hasModifier() const { return Modifier != ARMCP::no_modifier; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 73 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 74 | bool mustAddCurrentAddress() const { return AddCurrentAddress; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 75 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 76 | unsigned getLabelId() const { return LabelId; } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 77 | unsigned char getPCAdjustment() const { return PCAdjust; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 78 | |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 79 | bool isGlobalValue() const { return Kind == ARMCP::CPValue; } |
| 80 | bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; } |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 81 | bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 82 | bool isLSDA() const { return Kind == ARMCP::CPLSDA; } |
Bill Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame] | 83 | bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 84 | |
Jim Grosbach | cd3c7cb | 2010-11-29 23:09:20 +0000 | [diff] [blame] | 85 | virtual unsigned getRelocationInfo() const { return 2; } |
Chris Lattner | cb45963 | 2009-07-21 23:34:23 +0000 | [diff] [blame] | 86 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 87 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 88 | unsigned Alignment); |
| 89 | |
Jim Grosbach | 5405d58 | 2011-09-27 20:59:33 +0000 | [diff] [blame] | 90 | virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 91 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 92 | /// 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 Cheng | 78e5c11 | 2009-11-07 03:52:02 +0000 | [diff] [blame] | 95 | |
Bill Wendling | 405ca13 | 2011-10-01 12:44:28 +0000 | [diff] [blame] | 96 | 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 Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 102 | virtual void print(raw_ostream &O) const; |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 103 | void print(raw_ostream *O) const { if (O) print(*O); } |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 104 | void dump() const; |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 105 | |
| 106 | static bool classof(const ARMConstantPoolValue *) { return true; } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 107 | }; |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 108 | |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 109 | inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) { |
| 110 | V.print(O); |
| 111 | return O; |
| 112 | } |
| 113 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 114 | /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants, |
| 115 | /// Functions, and BlockAddresses. |
| 116 | class 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 Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 125 | 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 Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 132 | public: |
| 133 | static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID); |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 134 | static ARMConstantPoolConstant *Create(const GlobalValue *GV, |
| 135 | ARMCP::ARMCPModifier Modifier); |
Bill Wendling | 029e9388 | 2011-10-01 06:44:24 +0000 | [diff] [blame] | 136 | static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID, |
| 137 | ARMCP::ARMCPKind Kind, |
| 138 | unsigned char PCAdj); |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 139 | static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID, |
| 140 | ARMCP::ARMCPKind Kind, |
| 141 | unsigned char PCAdj, |
| 142 | ARMCP::ARMCPModifier Modifier, |
| 143 | bool AddCurrentAddress); |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 144 | |
| 145 | const GlobalValue *getGV() const; |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 146 | const BlockAddress *getBlockAddress() const; |
| 147 | |
| 148 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 149 | unsigned Alignment); |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 150 | |
| 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 Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 164 | /// ARMConstantPoolSymbol - ARM-specific constantpool values for external |
| 165 | /// symbols. |
| 166 | class 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 | |
| 173 | public: |
| 174 | ~ARMConstantPoolSymbol(); |
| 175 | |
| 176 | static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s, |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 177 | unsigned ID, unsigned char PCAdj); |
| 178 | |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 179 | 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 Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame] | 198 | /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic |
| 199 | /// block. |
| 200 | class ARMConstantPoolMBB : public ARMConstantPoolValue { |
Bill Wendling | 3320f2a | 2011-10-01 09:30:42 +0000 | [diff] [blame] | 201 | const MachineBasicBlock *MBB; // Machine basic block. |
Bill Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame] | 202 | |
Bill Wendling | 3320f2a | 2011-10-01 09:30:42 +0000 | [diff] [blame] | 203 | ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id, |
Bill Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame] | 204 | unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, |
| 205 | bool AddCurrentAddress); |
| 206 | |
| 207 | public: |
Bill Wendling | 3320f2a | 2011-10-01 09:30:42 +0000 | [diff] [blame] | 208 | static ARMConstantPoolMBB *Create(LLVMContext &C, |
| 209 | const MachineBasicBlock *mbb, |
Bill Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame] | 210 | 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 Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 231 | } // End llvm namespace |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 232 | |
| 233 | #endif |