1 //===-- ARMConstantPoolValue.h - ARM constantpool value ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the ARM specific constantpool value class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
15 #define LLVM_LIB_TARGET_ARM_ARMCONSTANTPOOLVALUE_H
17 #include "llvm/CodeGen/MachineConstantPool.h"
18 #include "llvm/Support/Casting.h"
19 #include "llvm/Support/ErrorHandling.h"
28 class MachineBasicBlock;
48 /// ARMConstantPoolValue - ARM specific constantpool value. This is used to
49 /// represent PC-relative displacement between the address of the load
50 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
51 class ARMConstantPoolValue : public MachineConstantPoolValue {
52 unsigned LabelId; // Label id of the load.
53 ARMCP::ARMCPKind Kind; // Kind of constant.
54 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
55 // 8 for ARM, 4 for Thumb.
56 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
57 bool AddCurrentAddress;
60 ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
61 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
62 bool AddCurrentAddress);
64 ARMConstantPoolValue(LLVMContext &C, unsigned id, ARMCP::ARMCPKind Kind,
65 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
66 bool AddCurrentAddress);
68 template <typename Derived>
69 int getExistingMachineCPValueImpl(MachineConstantPool *CP,
71 unsigned AlignMask = Alignment - 1;
72 const std::vector<MachineConstantPoolEntry> &Constants = CP->getConstants();
73 for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
74 if (Constants[i].isMachineConstantPoolEntry() &&
75 (Constants[i].getAlignment() & AlignMask) == 0) {
76 ARMConstantPoolValue *CPV =
77 (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal;
78 if (Derived *APC = dyn_cast<Derived>(CPV))
79 if (cast<Derived>(this)->equals(APC))
88 ~ARMConstantPoolValue() override;
90 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
91 const char *getModifierText() const;
92 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
94 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
96 unsigned getLabelId() const { return LabelId; }
97 unsigned char getPCAdjustment() const { return PCAdjust; }
99 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
100 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
101 bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
102 bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
103 bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; }
105 unsigned getRelocationInfo() const override { return 2; }
107 int getExistingMachineCPValue(MachineConstantPool *CP,
108 unsigned Alignment) override;
110 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
112 /// hasSameValue - Return true if this ARM constpool value can share the same
113 /// constantpool entry as another ARM constpool value.
114 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
116 bool equals(const ARMConstantPoolValue *A) const {
117 return this->LabelId == A->LabelId &&
118 this->PCAdjust == A->PCAdjust &&
119 this->Modifier == A->Modifier;
122 void print(raw_ostream &O) const override;
123 void print(raw_ostream *O) const { if (O) print(*O); }
127 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
132 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
133 /// Functions, and BlockAddresses.
134 class ARMConstantPoolConstant : public ARMConstantPoolValue {
135 const Constant *CVal; // Constant being loaded.
137 ARMConstantPoolConstant(const Constant *C,
139 ARMCP::ARMCPKind Kind,
141 ARMCP::ARMCPModifier Modifier,
142 bool AddCurrentAddress);
143 ARMConstantPoolConstant(Type *Ty, const Constant *C,
145 ARMCP::ARMCPKind Kind,
147 ARMCP::ARMCPModifier Modifier,
148 bool AddCurrentAddress);
151 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
152 static ARMConstantPoolConstant *Create(const GlobalValue *GV,
153 ARMCP::ARMCPModifier Modifier);
154 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
155 ARMCP::ARMCPKind Kind,
156 unsigned char PCAdj);
157 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
158 ARMCP::ARMCPKind Kind,
160 ARMCP::ARMCPModifier Modifier,
161 bool AddCurrentAddress);
163 const GlobalValue *getGV() const;
164 const BlockAddress *getBlockAddress() const;
166 int getExistingMachineCPValue(MachineConstantPool *CP,
167 unsigned Alignment) override;
169 /// hasSameValue - Return true if this ARM constpool value can share the same
170 /// constantpool entry as another ARM constpool value.
171 bool hasSameValue(ARMConstantPoolValue *ACPV) override;
173 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
175 void print(raw_ostream &O) const override;
176 static bool classof(const ARMConstantPoolValue *APV) {
177 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
180 bool equals(const ARMConstantPoolConstant *A) const {
181 return CVal == A->CVal && ARMConstantPoolValue::equals(A);
185 /// ARMConstantPoolSymbol - ARM-specific constantpool values for external
187 class ARMConstantPoolSymbol : public ARMConstantPoolValue {
188 const std::string S; // ExtSymbol being loaded.
190 ARMConstantPoolSymbol(LLVMContext &C, const char *s, unsigned id,
191 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
192 bool AddCurrentAddress);
195 static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s,
196 unsigned ID, unsigned char PCAdj);
198 const char *getSymbol() const { return S.c_str(); }
200 int getExistingMachineCPValue(MachineConstantPool *CP,
201 unsigned Alignment) override;
203 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
205 /// hasSameValue - Return true if this ARM constpool value can share the same
206 /// constantpool entry as another ARM constpool value.
207 bool hasSameValue(ARMConstantPoolValue *ACPV) override;
209 void print(raw_ostream &O) const override;
211 static bool classof(const ARMConstantPoolValue *ACPV) {
212 return ACPV->isExtSymbol();
215 bool equals(const ARMConstantPoolSymbol *A) const {
216 return S == A->S && ARMConstantPoolValue::equals(A);
220 /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
222 class ARMConstantPoolMBB : public ARMConstantPoolValue {
223 const MachineBasicBlock *MBB; // Machine basic block.
225 ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
226 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
227 bool AddCurrentAddress);
230 static ARMConstantPoolMBB *Create(LLVMContext &C,
231 const MachineBasicBlock *mbb,
232 unsigned ID, unsigned char PCAdj);
234 const MachineBasicBlock *getMBB() const { return MBB; }
236 int getExistingMachineCPValue(MachineConstantPool *CP,
237 unsigned Alignment) override;
239 void addSelectionDAGCSEId(FoldingSetNodeID &ID) override;
241 /// hasSameValue - Return true if this ARM constpool value can share the same
242 /// constantpool entry as another ARM constpool value.
243 bool hasSameValue(ARMConstantPoolValue *ACPV) override;
245 void print(raw_ostream &O) const override;
247 static bool classof(const ARMConstantPoolValue *ACPV) {
248 return ACPV->isMachineBasicBlock();
251 bool equals(const ARMConstantPoolMBB *A) const {
252 return MBB == A->MBB && ARMConstantPoolValue::equals(A);
256 } // End llvm namespace