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); }
107 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
112 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
113 /// Functions, and BlockAddresses.
114 class ARMConstantPoolConstant : public ARMConstantPoolValue {
115 const Constant *CVal; // Constant being loaded.
117 ARMConstantPoolConstant(const Constant *C,
119 ARMCP::ARMCPKind Kind,
121 ARMCP::ARMCPModifier Modifier,
122 bool AddCurrentAddress);
123 ARMConstantPoolConstant(Type *Ty, const Constant *C,
125 ARMCP::ARMCPKind Kind,
127 ARMCP::ARMCPModifier Modifier,
128 bool AddCurrentAddress);
131 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
132 static ARMConstantPoolConstant *Create(const GlobalValue *GV,
133 ARMCP::ARMCPModifier Modifier);
134 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
135 ARMCP::ARMCPKind Kind,
136 unsigned char PCAdj);
137 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
138 ARMCP::ARMCPKind Kind,
140 ARMCP::ARMCPModifier Modifier,
141 bool AddCurrentAddress);
143 const GlobalValue *getGV() const;
144 const BlockAddress *getBlockAddress() const;
146 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
149 /// hasSameValue - Return true if this ARM constpool value can share the same
150 /// constantpool entry as another ARM constpool value.
151 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
153 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
155 virtual void print(raw_ostream &O) const;
156 static bool classof(const ARMConstantPoolValue *APV) {
157 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
161 /// ARMConstantPoolSymbol - ARM-specific constantpool values for external
163 class ARMConstantPoolSymbol : public ARMConstantPoolValue {
164 const std::string S; // ExtSymbol being loaded.
166 ARMConstantPoolSymbol(LLVMContext &C, const char *s, unsigned id,
167 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
168 bool AddCurrentAddress);
171 static ARMConstantPoolSymbol *Create(LLVMContext &C, const char *s,
172 unsigned ID, unsigned char PCAdj);
174 const char *getSymbol() const { return S.c_str(); }
176 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
179 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
181 /// hasSameValue - Return true if this ARM constpool value can share the same
182 /// constantpool entry as another ARM constpool value.
183 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
185 virtual void print(raw_ostream &O) const;
187 static bool classof(const ARMConstantPoolValue *ACPV) {
188 return ACPV->isExtSymbol();
192 /// ARMConstantPoolMBB - ARM-specific constantpool value of a machine basic
194 class ARMConstantPoolMBB : public ARMConstantPoolValue {
195 const MachineBasicBlock *MBB; // Machine basic block.
197 ARMConstantPoolMBB(LLVMContext &C, const MachineBasicBlock *mbb, unsigned id,
198 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
199 bool AddCurrentAddress);
202 static ARMConstantPoolMBB *Create(LLVMContext &C,
203 const MachineBasicBlock *mbb,
204 unsigned ID, unsigned char PCAdj);
206 const MachineBasicBlock *getMBB() const { return MBB; }
208 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
211 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
213 /// hasSameValue - Return true if this ARM constpool value can share the same
214 /// constantpool entry as another ARM constpool value.
215 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
217 virtual void print(raw_ostream &O) const;
219 static bool classof(const ARMConstantPoolValue *ACPV) {
220 return ACPV->isMachineBasicBlock();
224 } // End llvm namespace