OLD | NEW |
1 //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- C++ -*-===// | 1 //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 /// @file | 10 /// @file |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 /// whether or not it may generate a relocation entry. This must be | 48 /// whether or not it may generate a relocation entry. This must be |
49 /// conservative, so if it might codegen to a relocatable entry, it should say | 49 /// conservative, so if it might codegen to a relocatable entry, it should say |
50 /// so. The return values are the same as Constant::getRelocationInfo(). | 50 /// so. The return values are the same as Constant::getRelocationInfo(). |
51 virtual unsigned getRelocationInfo() const = 0; | 51 virtual unsigned getRelocationInfo() const = 0; |
52 ·· | 52 ·· |
53 virtual int getExistingMachineCPValue(MachineConstantPool *CP, | 53 virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
54 unsigned Alignment) = 0; | 54 unsigned Alignment) = 0; |
55 | 55 |
56 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID) = 0; | 56 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID) = 0; |
57 | 57 |
| 58 /// getJumpTableIndex - Check if this is a reference to a jump table. |
| 59 /// If so, return a pointer to the jump table index value that is stored |
| 60 /// in the constant pool, else return 0. |
| 61 /// The default behavior is to indicate that the value is not a jump table |
| 62 /// index. This is used by BranchFolder::runOnMachineFunction() and only in |
| 63 /// conjunction with ARM targets |
| 64 /// TODO: this should be cleaned up as it does tripple duty: tester, setter, g
etter |
| 65 virtual unsigned *getJumpTableIndex() { return 0; } |
| 66 |
58 /// print - Implement operator<< | 67 /// print - Implement operator<< |
59 virtual void print(raw_ostream &O) const = 0; | 68 virtual void print(raw_ostream &O) const = 0; |
60 }; | 69 }; |
61 | 70 |
62 inline raw_ostream &operator<<(raw_ostream &OS, | 71 inline raw_ostream &operator<<(raw_ostream &OS, |
63 const MachineConstantPoolValue &V) { | 72 const MachineConstantPoolValue &V) { |
64 V.print(OS); | 73 V.print(OS); |
65 return OS; | 74 return OS; |
66 } | 75 } |
67 | 76 |
68 | 77 |
69 /// This class is a data container for one entry in a MachineConstantPool. | 78 /// This class is a data container for one entry in a MachineConstantPool. |
70 /// It contains a pointer to the value and an offset from the start of | 79 /// It contains a pointer to the value and an offset from the start of |
71 /// the constant pool. | 80 /// the constant pool. |
72 /// @brief An entry in a MachineConstantPool | 81 /// @brief An entry in a MachineConstantPool |
73 class MachineConstantPoolEntry { | 82 class MachineConstantPoolEntry { |
74 public: | 83 public: |
75 /// The constant itself. | 84 /// The constant itself. |
76 union { | 85 union { |
77 Constant *ConstVal; | 86 Constant *ConstVal; |
78 MachineConstantPoolValue *MachineCPVal; | 87 MachineConstantPoolValue *MachineCPVal; |
79 } Val; | 88 } Val; |
80 | 89 |
81 /// The required alignment for this entry. The top bit is set when Val is | 90 /// The required alignment for this entry. The top bit is set when Val is |
82 /// a MachineConstantPoolValue. | 91 /// a MachineConstantPoolValue. |
83 unsigned Alignment; | 92 unsigned Alignment; |
84 | 93 |
85 MachineConstantPoolEntry(Constant *V, unsigned A) | 94 MachineConstantPoolEntry(Constant *V, unsigned A) |
86 : Alignment(A) { | 95 : Alignment(A) { |
87 Val.ConstVal = V; | 96 Val.ConstVal = V; |
88 } | 97 } |
89 MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A) | 98 MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A) |
90 : Alignment(A) { | 99 : Alignment(A) { |
91 Val.MachineCPVal = V; | 100 Val.MachineCPVal = V; |
92 Alignment |= 1 << (sizeof(unsigned)*CHAR_BIT-1); | 101 Alignment |= 1 << (sizeof(unsigned)*CHAR_BIT-1); |
93 } | 102 } |
94 | 103 |
95 bool isMachineConstantPoolEntry() const { | 104 bool isMachineConstantPoolEntry() const { |
96 return (int)Alignment < 0; | 105 return (int)Alignment < 0; |
97 } | 106 } |
98 | 107 |
99 int getAlignment() const { | 108 int getAlignment() const { |
100 return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1)); | 109 return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1)); |
101 } | 110 } |
102 | 111 |
103 const Type *getType() const; | 112 const Type *getType() const; |
104 ·· | 113 ·· |
105 /// getRelocationInfo - This method classifies the entry according to | 114 /// getRelocationInfo - This method classifies the entry according to |
106 /// whether or not it may generate a relocation entry. This must be | 115 /// whether or not it may generate a relocation entry. This must be |
107 /// conservative, so if it might codegen to a relocatable entry, it should say | 116 /// conservative, so if it might codegen to a relocatable entry, it should say |
108 /// so. The return values are: | 117 /// so. The return values are: |
109 ///· | 118 ///· |
110 /// 0: This constant pool entry is guaranteed to never have a relocation | 119 /// 0: This constant pool entry is guaranteed to never have a relocation |
111 /// applied to it (because it holds a simple constant like '4'). | 120 /// applied to it (because it holds a simple constant like '4'). |
112 /// 1: This entry has relocations, but the entries are guaranteed to be | 121 /// 1: This entry has relocations, but the entries are guaranteed to be |
113 /// resolvable by the static linker, so the dynamic linker will never see | 122 /// resolvable by the static linker, so the dynamic linker will never see |
114 /// them. | 123 /// them. |
115 /// 2: This entry may have arbitrary relocations.· | 124 /// 2: This entry may have arbitrary relocations.· |
116 unsigned getRelocationInfo() const; | 125 unsigned getRelocationInfo() const; |
117 }; | 126 }; |
118 | 127 |
119 /// The MachineConstantPool class keeps track of constants referenced by a | 128 /// The MachineConstantPool class keeps track of constants referenced by a |
120 /// function which must be spilled to memory. This is used for constants which | 129 /// function which must be spilled to memory. This is used for constants which |
121 /// are unable to be used directly as operands to instructions, which typically | 130 /// are unable to be used directly as operands to instructions, which typically |
122 /// include floating point and large integer constants. | 131 /// include floating point and large integer constants. |
123 /// | 132 /// |
124 /// Instructions reference the address of these constant pool constants through | 133 /// Instructions reference the address of these constant pool constants through |
125 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine | 134 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine |
126 /// code, these virtual address references are converted to refer to the | 135 /// code, these virtual address references are converted to refer to the |
127 /// address of the function constant pool values. | 136 /// address of the function constant pool values. |
128 /// @brief The machine constant pool. | 137 /// @brief The machine constant pool. |
129 class MachineConstantPool { | 138 class MachineConstantPool { |
130 const TargetData *TD; ///< The machine's TargetData. | 139 const TargetData *TD; ///< The machine's TargetData. |
131 unsigned PoolAlignment; ///< The alignment for the pool. | 140 unsigned PoolAlignment; ///< The alignment for the pool. |
132 std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants. | 141 std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants. |
133 public: | 142 public: |
134 /// @brief The only constructor. | 143 /// @brief The only constructor. |
135 explicit MachineConstantPool(const TargetData *td) | 144 explicit MachineConstantPool(const TargetData *td) |
136 : TD(td), PoolAlignment(1) {} | 145 : TD(td), PoolAlignment(1) {} |
137 ~MachineConstantPool(); | 146 ~MachineConstantPool(); |
138 | 147 |
139 /// getConstantPoolAlignment - Return the the alignment required by | 148 /// getConstantPoolAlignment - Return the the alignment required by |
140 /// the whole constant pool, of which the first element must be aligned. | 149 /// the whole constant pool, of which the first element must be aligned. |
141 unsigned getConstantPoolAlignment() const { return PoolAlignment; } | 150 unsigned getConstantPoolAlignment() const { return PoolAlignment; } |
142 | 151 |
143 /// getConstantPoolIndex - Create a new entry in the constant pool or return | 152 /// getConstantPoolIndex - Create a new entry in the constant pool or return |
144 /// an existing one. User must specify the minimum required alignment for | 153 /// an existing one. User must specify the minimum required alignment for |
145 /// the object. | 154 /// the object. |
146 unsigned getConstantPoolIndex(Constant *C, unsigned Alignment); | 155 unsigned getConstantPoolIndex(Constant *C, unsigned Alignment); |
147 unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment); | 156 unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment); |
148 | 157 |
149 /// isEmpty - Return true if this constant pool contains no constants. | 158 /// isEmpty - Return true if this constant pool contains no constants. |
150 bool isEmpty() const { return Constants.empty(); } | 159 bool isEmpty() const { return Constants.empty(); } |
151 | 160 |
152 const std::vector<MachineConstantPoolEntry> &getConstants() const { | 161 const std::vector<MachineConstantPoolEntry> &getConstants() const { |
153 return Constants; | 162 return Constants; |
154 } | 163 } |
155 | 164 |
156 /// print - Used by the MachineFunction printer to print information about | 165 /// print - Used by the MachineFunction printer to print information about |
157 /// constant pool objects. Implemented in MachineFunction.cpp | 166 /// constant pool objects. Implemented in MachineFunction.cpp |
158 /// | 167 /// |
159 void print(raw_ostream &OS) const; | 168 void print(raw_ostream &OS) const; |
160 | 169 |
161 /// dump - Call print(cerr) to be called from the debugger. | 170 /// dump - Call print(cerr) to be called from the debugger. |
162 void dump() const; | 171 void dump() const; |
163 }; | 172 }; |
164 | 173 |
165 } // End llvm namespace | 174 } // End llvm namespace |
166 | 175 |
167 #endif | 176 #endif |
OLD | NEW |