Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 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. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +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" |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 21 | class Constant; |
| 22 | class BlockAddress; |
Dan Gohman | 0298311 | 2008-07-11 20:38:31 +0000 | [diff] [blame] | 23 | class GlobalValue; |
Owen Anderson | 35b4707 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 24 | class LLVMContext; |
Dan Gohman | 0298311 | 2008-07-11 20:38:31 +0000 | [diff] [blame] | 25 | |
Jim Grosbach | 5e0257f | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 26 | namespace ARMCP { |
| 27 | enum ARMCPKind { |
| 28 | CPValue, |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 29 | CPExtSymbol, |
| 30 | CPBlockAddress, |
Jim Grosbach | 5e0257f | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 31 | CPLSDA |
| 32 | }; |
| 33 | } |
| 34 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 35 | /// ARMConstantPoolValue - ARM specific constantpool value. This is used to |
Bob Wilson | a07d68f | 2009-11-02 17:10:37 +0000 | [diff] [blame^] | 36 | /// represent PC-relative displacement between the address of the load |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 37 | /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)). |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 38 | class ARMConstantPoolValue : public MachineConstantPoolValue { |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 39 | Constant *CVal; // Constant being loaded. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 40 | const char *S; // ExtSymbol being loaded. |
| 41 | unsigned LabelId; // Label id of the load. |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 42 | ARMCP::ARMCPKind Kind; // Kind of constant. |
Bob Wilson | a07d68f | 2009-11-02 17:10:37 +0000 | [diff] [blame^] | 43 | unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 44 | // 8 for ARM, 4 for Thumb. |
| 45 | const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8)) |
| 46 | bool AddCurrentAddress; |
| 47 | |
| 48 | public: |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 49 | ARMConstantPoolValue(Constant *cval, unsigned id, |
Jim Grosbach | 5e0257f | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 50 | ARMCP::ARMCPKind Kind = ARMCP::CPValue, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 51 | unsigned char PCAdj = 0, const char *Modifier = NULL, |
| 52 | bool AddCurrentAddress = false); |
Owen Anderson | 35b4707 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 53 | ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 54 | unsigned char PCAdj = 0, const char *Modifier = NULL, |
| 55 | bool AddCurrentAddress = false); |
Evan Cheng | c299914 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 56 | ARMConstantPoolValue(GlobalValue *GV, const char *Modifier); |
Jim Grosbach | 29feb6a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 57 | ARMConstantPoolValue(); |
Jim Grosbach | 3fe420b | 2009-08-11 15:26:27 +0000 | [diff] [blame] | 58 | ~ARMConstantPoolValue(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 59 | |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 60 | GlobalValue *getGV() const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 61 | const char *getSymbol() const { return S; } |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 62 | BlockAddress *getBlockAddress() const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 63 | const char *getModifier() const { return Modifier; } |
| 64 | bool hasModifier() const { return Modifier != NULL; } |
| 65 | bool mustAddCurrentAddress() const { return AddCurrentAddress; } |
| 66 | unsigned getLabelId() const { return LabelId; } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 67 | unsigned char getPCAdjustment() const { return PCAdjust; } |
Bob Wilson | 62acbf1 | 2009-11-02 16:59:06 +0000 | [diff] [blame] | 68 | bool isGlobalValue() const { return Kind == ARMCP::CPValue; } |
| 69 | bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; } |
| 70 | bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; } |
Jim Grosbach | 5e0257f | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 71 | bool isLSDA() { return Kind == ARMCP::CPLSDA; } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 690b8d5 | 2009-07-21 23:36:01 +0000 | [diff] [blame] | 73 | virtual unsigned getRelocationInfo() const { |
Chris Lattner | 8f3f851 | 2009-07-21 23:34:23 +0000 | [diff] [blame] | 74 | // FIXME: This is conservatively claiming that these entries require a |
| 75 | // relocation, we may be able to do better than this. |
| 76 | return 2; |
| 77 | } |
| 78 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 79 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 80 | unsigned Alignment); |
| 81 | |
| 82 | virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID); |
| 83 | |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 84 | void print(raw_ostream *O) const { if (O) print(*O); } |
| 85 | void print(raw_ostream &O) const; |
| 86 | void dump() const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 87 | }; |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 88 | |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 89 | inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) { |
| 90 | V.print(O); |
| 91 | return O; |
| 92 | } |
| 93 | |
| 94 | } // End llvm namespace |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 95 | |
| 96 | #endif |