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_TARGET_ARM_CONSTANTPOOLVALUE_H
15 #define LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
17 #include "llvm/CodeGen/MachineConstantPool.h"
18 #include "llvm/Support/ErrorHandling.h"
27 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 virtual ~ARMConstantPoolValue();
70 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
71 const char *getModifierText() const;
72 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
74 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
76 unsigned getLabelId() const { return LabelId; }
77 unsigned char getPCAdjustment() const { return PCAdjust; }
79 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
80 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
81 bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
82 bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
83 bool isMachineBasicBlock() const{ return Kind == ARMCP::CPMachineBasicBlock; }
85 virtual unsigned getRelocationInfo() const { return 2; }
87 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
90 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
92 /// hasSameValue - Return true if this ARM constpool value can share the same
93 /// constantpool entry as another ARM constpool value.
94 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
96 bool equals(const ARMConstantPoolValue *A) const {
97 return this->LabelId == A->LabelId &&
98 this->PCAdjust == A->PCAdjust &&
99 this->Modifier == A->Modifier;
102 virtual void print(raw_ostream &O) const;
103 void print(raw_ostream *O) const { if (O) print(*O); }
106 static bool classof(const ARMConstantPoolValue *) { return true; }
109 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
114 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
115 /// Functions, and BlockAddresses.
116 class ARMConstantPoolConstant : public ARMConstantPoolValue {
117 const Constant *CVal; // Constant being loaded.
119 ARMConstantPoolConstant(const Constant *C,
121 ARMCP::ARMCPKind Kind,
123 ARMCP::ARMCPModifier Modifier,
124 bool AddCurrentAddress);
125 ARMConstantPoolConstant(Type *Ty, const Constant *C,
127 ARMCP::ARMCPKind Kind,
129 ARMCP::ARMCPModifier Modifier,
130 bool AddCurrentAddress);
133 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
134 static ARMConstantPoolConstant *Create(const GlobalValue *GV,
135 ARMCP::ARMCPModifier Modifier);
136 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
137 ARMCP::ARMCPKind Kind,
138 unsigned char PCAdj);
139 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
140 ARMCP::ARMCPKind Kind,
142 ARMCP::ARMCPModifier Modifier,
143 bool AddCurrentAddress);
145 const GlobalValue *getGV() const;
146 const BlockAddress *getBlockAddress() const;
148 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
151 /// hasSameValue - Return true if this ARM constpool value can share the same
152 /// constantpool entry as another ARM constpool value.
153 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
155 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
157 virtual void print(raw_ostream &O) const;
158 static bool classof(const ARMConstantPoolValue *APV) {
159 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
161 static bool classof(const ARMConstantPoolConstant *) { return true; }
164 /// ARMConstantPoolSymbol - ARM-specific constantpool values for external
166 class ARMConstantPoolSymbol : public ARMConstantPoolValue {
167 const char *S; // ExtSymbol being loaded.
169 ARMConstantPoolSymbol(LLVMContext &C, const char *s, unsigned id,
170 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
171 bool AddCurrentAddress);
174 ~ARMConstantPoolSymbol();
176 static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s,
177 unsigned ID, unsigned char PCAdj);
179 const char *getSymbol() const { return S; }
181 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
184 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
186 /// hasSameValue - Return true if this ARM constpool value can share the same
187 /// constantpool entry as another ARM constpool value.
188 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
190 virtual void print(raw_ostream &O) const;
192 static bool classof(const ARMConstantPoolValue *ACPV) {
193 return ACPV->isExtSymbol();
195 static bool classof(const ARMConstantPoolSymbol *) { return true; }
198 /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
200 class ARMConstantPoolMBB : public ARMConstantPoolValue {
201 const MachineBasicBlock *MBB; // Machine basic block.
203 ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
204 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
205 bool AddCurrentAddress);
208 static ARMConstantPoolMBB *Create(LLVMContext &C,
209 const MachineBasicBlock *mbb,
210 unsigned ID, unsigned char PCAdj);
212 const MachineBasicBlock *getMBB() const { return MBB; }
214 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
217 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
219 /// hasSameValue - Return true if this ARM constpool value can share the same
220 /// constantpool entry as another ARM constpool value.
221 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
223 virtual void print(raw_ostream &O) const;
225 static bool classof(const ARMConstantPoolValue *ACPV) {
226 return ACPV->isMachineBasicBlock();
228 static bool classof(const ARMConstantPoolMBB *) { return true; }
231 } // End llvm namespace