Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===// |
| 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 { |
Bill Wendling | 4dd9b09 | 2011-09-29 23:48:44 +0000 | [diff] [blame] | 52 | const MachineBasicBlock *MBB; // MachineBasicBlock being loaded. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 53 | unsigned LabelId; // Label id of the load. |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 54 | ARMCP::ARMCPKind Kind; // Kind of constant. |
Bob Wilson | 31ba10b | 2009-11-02 17:10:37 +0000 | [diff] [blame] | 55 | unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 56 | // 8 for ARM, 4 for Thumb. |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 57 | ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8)) |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 58 | bool AddCurrentAddress; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 59 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 60 | protected: |
| 61 | ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind, |
| 62 | unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, |
| 63 | bool AddCurrentAddress); |
| 64 | |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 65 | ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind, |
| 66 | unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, |
| 67 | bool AddCurrentAddress); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 68 | public: |
Bill Wendling | 4dd9b09 | 2011-09-29 23:48:44 +0000 | [diff] [blame] | 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); |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 74 | virtual ~ARMConstantPoolValue(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 75 | |
Bill Wendling | 4dd9b09 | 2011-09-29 23:48:44 +0000 | [diff] [blame] | 76 | const MachineBasicBlock *getMBB() const; |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 77 | |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 78 | ARMCP::ARMCPModifier getModifier() const { return Modifier; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 79 | const char *getModifierText() const; |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 80 | bool hasModifier() const { return Modifier != ARMCP::no_modifier; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 81 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 82 | bool mustAddCurrentAddress() const { return AddCurrentAddress; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 83 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 84 | unsigned getLabelId() const { return LabelId; } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 85 | unsigned char getPCAdjustment() const { return PCAdjust; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 86 | |
Bob Wilson | 28989a8 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 87 | bool isGlobalValue() const { return Kind == ARMCP::CPValue; } |
| 88 | bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; } |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 89 | bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; } |
Bill Wendling | d98f838 | 2011-09-30 18:42:06 +0000 | [diff] [blame] | 90 | bool isLSDA() const { return Kind == ARMCP::CPLSDA; } |
Bill Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame^] | 91 | bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 92 | |
Jim Grosbach | cd3c7cb | 2010-11-29 23:09:20 +0000 | [diff] [blame] | 93 | virtual unsigned getRelocationInfo() const { return 2; } |
Chris Lattner | cb45963 | 2009-07-21 23:34:23 +0000 | [diff] [blame] | 94 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 95 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 96 | unsigned Alignment); |
| 97 | |
Jim Grosbach | 5405d58 | 2011-09-27 20:59:33 +0000 | [diff] [blame] | 98 | virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 99 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 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); |
Evan Cheng | 78e5c11 | 2009-11-07 03:52:02 +0000 | [diff] [blame] | 103 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 104 | virtual void print(raw_ostream &O) const; |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 105 | void print(raw_ostream *O) const { if (O) print(*O); } |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 106 | void dump() const; |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 107 | |
| 108 | static bool classof(const ARMConstantPoolValue *) { return true; } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 109 | }; |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 110 | |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 111 | inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) { |
| 112 | V.print(O); |
| 113 | return O; |
| 114 | } |
| 115 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 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); |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 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 | |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 134 | public: |
| 135 | static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID); |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 136 | static ARMConstantPoolConstant *Create(const GlobalValue *GV, |
| 137 | ARMCP::ARMCPModifier Modifier); |
Bill Wendling | 029e9388 | 2011-10-01 06:44:24 +0000 | [diff] [blame] | 138 | static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID, |
| 139 | ARMCP::ARMCPKind Kind, |
| 140 | unsigned char PCAdj); |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 141 | static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID, |
| 142 | ARMCP::ARMCPKind Kind, |
| 143 | unsigned char PCAdj, |
| 144 | ARMCP::ARMCPModifier Modifier, |
| 145 | bool AddCurrentAddress); |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 146 | |
| 147 | const GlobalValue *getGV() const; |
Bill Wendling | 3e944e3 | 2011-10-01 07:52:37 +0000 | [diff] [blame] | 148 | const BlockAddress *getBlockAddress() const; |
| 149 | |
| 150 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 151 | unsigned Alignment); |
Bill Wendling | f2b76aa | 2011-10-01 06:40:33 +0000 | [diff] [blame] | 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 | |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 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, |
Bill Wendling | fe31e67 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 179 | unsigned ID, unsigned char PCAdj); |
| 180 | |
Bill Wendling | ff4a802 | 2011-10-01 08:36:59 +0000 | [diff] [blame] | 181 | const char *getSymbol() const { return S; } |
| 182 | |
| 183 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 184 | unsigned Alignment); |
| 185 | |
| 186 | virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID); |
| 187 | |
| 188 | /// hasSameValue - Return true if this ARM constpool value can share the same |
| 189 | /// constantpool entry as another ARM constpool value. |
| 190 | virtual bool hasSameValue(ARMConstantPoolValue *ACPV); |
| 191 | |
| 192 | virtual void print(raw_ostream &O) const; |
| 193 | |
| 194 | static bool classof(const ARMConstantPoolValue *ACPV) { |
| 195 | return ACPV->isExtSymbol(); |
| 196 | } |
| 197 | static bool classof(const ARMConstantPoolSymbol *) { return true; } |
| 198 | }; |
| 199 | |
Bill Wendling | 9c18f51 | 2011-10-01 09:19:10 +0000 | [diff] [blame^] | 200 | /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic |
| 201 | /// block. |
| 202 | class ARMConstantPoolMBB : public ARMConstantPoolValue { |
| 203 | MachineBasicBlock *MBB; // Machine basic block. |
| 204 | |
| 205 | ARMConstantPoolMBB(LLVMContext &C, MachineBasicBlock *mbb, unsigned id, |
| 206 | unsigned char PCAdj, ARMCP::ARMCPModifier Modifier, |
| 207 | bool AddCurrentAddress); |
| 208 | |
| 209 | public: |
| 210 | static ARMConstantPoolMBB *Create(LLVMContext &C, MachineBasicBlock *mbb, |
| 211 | unsigned ID, unsigned char PCAdj); |
| 212 | |
| 213 | const MachineBasicBlock *getMBB() const { return MBB; } |
| 214 | |
| 215 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 216 | unsigned Alignment); |
| 217 | |
| 218 | virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID); |
| 219 | |
| 220 | /// hasSameValue - Return true if this ARM constpool value can share the same |
| 221 | /// constantpool entry as another ARM constpool value. |
| 222 | virtual bool hasSameValue(ARMConstantPoolValue *ACPV); |
| 223 | |
| 224 | virtual void print(raw_ostream &O) const; |
| 225 | |
| 226 | static bool classof(const ARMConstantPoolValue *ACPV) { |
| 227 | return ACPV->isMachineBasicBlock(); |
| 228 | } |
| 229 | static bool classof(const ARMConstantPoolMBB *) { return true; } |
| 230 | }; |
| 231 | |
Evan Cheng | 5be59ea | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 232 | } // End llvm namespace |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 233 | |
| 234 | #endif |