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" |
Dan Gohman | c24a3f8 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 18 | #include <iosfwd> |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
Dan Gohman | 0298311 | 2008-07-11 20:38:31 +0000 | [diff] [blame] | 22 | class GlobalValue; |
Owen Anderson | 35b4707 | 2009-08-13 21:58:54 +0000 | [diff] [blame^] | 23 | class LLVMContext; |
Dan Gohman | 0298311 | 2008-07-11 20:38:31 +0000 | [diff] [blame] | 24 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 25 | namespace ARMCP { |
| 26 | enum ARMCPKind { |
| 27 | CPValue, |
| 28 | CPNonLazyPtr, |
| 29 | CPStub |
| 30 | }; |
| 31 | } |
| 32 | |
| 33 | /// ARMConstantPoolValue - ARM specific constantpool value. This is used to |
| 34 | /// represent PC relative displacement between the address of the load |
| 35 | /// instruction and the global value being loaded, i.e. (&GV-(LPIC+8)). |
| 36 | class ARMConstantPoolValue : public MachineConstantPoolValue { |
| 37 | GlobalValue *GV; // GlobalValue being loaded. |
| 38 | const char *S; // ExtSymbol being loaded. |
| 39 | unsigned LabelId; // Label id of the load. |
| 40 | ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub? |
| 41 | unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative. |
| 42 | // 8 for ARM, 4 for Thumb. |
| 43 | const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8)) |
| 44 | bool AddCurrentAddress; |
| 45 | |
| 46 | public: |
| 47 | ARMConstantPoolValue(GlobalValue *gv, unsigned id, |
| 48 | ARMCP::ARMCPKind Kind = ARMCP::CPValue, |
| 49 | unsigned char PCAdj = 0, const char *Modifier = NULL, |
| 50 | bool AddCurrentAddress = false); |
Owen Anderson | 35b4707 | 2009-08-13 21:58:54 +0000 | [diff] [blame^] | 51 | ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 52 | ARMCP::ARMCPKind Kind = ARMCP::CPValue, |
| 53 | unsigned char PCAdj = 0, const char *Modifier = NULL, |
| 54 | bool AddCurrentAddress = false); |
| 55 | ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind, |
| 56 | 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 | |
| 60 | |
| 61 | GlobalValue *getGV() const { return GV; } |
| 62 | const char *getSymbol() const { return S; } |
| 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; } |
| 67 | bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; } |
| 68 | bool isStub() const { return Kind == ARMCP::CPStub; } |
| 69 | unsigned char getPCAdjustment() const { return PCAdjust; } |
| 70 | |
Chris Lattner | 690b8d5 | 2009-07-21 23:36:01 +0000 | [diff] [blame] | 71 | virtual unsigned getRelocationInfo() const { |
Chris Lattner | 8f3f851 | 2009-07-21 23:34:23 +0000 | [diff] [blame] | 72 | // FIXME: This is conservatively claiming that these entries require a |
| 73 | // relocation, we may be able to do better than this. |
| 74 | return 2; |
| 75 | } |
| 76 | |
Jim Grosbach | 770d718 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 77 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 78 | virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 79 | unsigned Alignment); |
| 80 | |
| 81 | virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID); |
| 82 | |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 83 | void print(std::ostream *O) const { if (O) print(*O); } |
| 84 | void print(std::ostream &O) const; |
| 85 | void print(raw_ostream *O) const { if (O) print(*O); } |
| 86 | void print(raw_ostream &O) const; |
| 87 | void dump() const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 88 | }; |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 89 | |
Bob Wilson | 9b784f0 | 2009-07-14 21:45:58 +0000 | [diff] [blame] | 90 | inline std::ostream &operator<<(std::ostream &O, |
| 91 | const ARMConstantPoolValue &V) { |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 92 | V.print(O); |
| 93 | return O; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 94 | } |
Jim Grosbach | 770d718 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 95 | |
Evan Cheng | f3aaeed | 2008-10-29 23:55:17 +0000 | [diff] [blame] | 96 | inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) { |
| 97 | V.print(O); |
| 98 | return O; |
| 99 | } |
| 100 | |
| 101 | } // End llvm namespace |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 102 | |
| 103 | #endif |