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 const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
53 const char *S; // ExtSymbol being loaded.
54 unsigned LabelId; // Label id of the load.
55 ARMCP::ARMCPKind Kind; // Kind of constant.
56 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
57 // 8 for ARM, 4 for Thumb.
58 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
59 bool AddCurrentAddress;
62 ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
63 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
64 bool AddCurrentAddress);
67 ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id,
68 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
69 unsigned char PCAdj = 0,
70 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
71 bool AddCurrentAddress = false);
72 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
73 unsigned char PCAdj = 0,
74 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
75 bool AddCurrentAddress = false);
76 ~ARMConstantPoolValue();
78 const char *getSymbol() const { return S; }
79 const MachineBasicBlock *getMBB() const;
81 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
82 const char *getModifierText() const;
83 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
85 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
87 unsigned getLabelId() const { return LabelId; }
88 unsigned char getPCAdjustment() const { return PCAdjust; }
90 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
91 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
92 bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
93 bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
94 bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
96 virtual unsigned getRelocationInfo() const { return 2; }
98 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
101 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
103 /// hasSameValue - Return true if this ARM constpool value can share the same
104 /// constantpool entry as another ARM constpool value.
105 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
107 virtual void print(raw_ostream &O) const;
108 void print(raw_ostream *O) const { if (O) print(*O); }
111 static bool classof(const ARMConstantPoolValue *) { return true; }
114 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
119 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
120 /// Functions, and BlockAddresses.
121 class ARMConstantPoolConstant : public ARMConstantPoolValue {
122 const Constant *CVal; // Constant being loaded.
124 ARMConstantPoolConstant(const Constant *C,
126 ARMCP::ARMCPKind Kind,
128 ARMCP::ARMCPModifier Modifier,
129 bool AddCurrentAddress);
130 ARMConstantPoolConstant(Type *Ty, const Constant *C,
132 ARMCP::ARMCPKind Kind,
134 ARMCP::ARMCPModifier Modifier,
135 bool AddCurrentAddress);
138 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
139 static ARMConstantPoolConstant *Create(const GlobalValue *GV,
140 ARMCP::ARMCPModifier Modifier);
141 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
142 ARMCP::ARMCPKind Kind,
143 unsigned char PCAdj);
144 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID,
145 ARMCP::ARMCPKind Kind,
147 ARMCP::ARMCPModifier Modifier,
148 bool AddCurrentAddress);
150 const GlobalValue *getGV() const;
151 const BlockAddress *getBlockAddress() const;
153 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
156 /// hasSameValue - Return true if this ARM constpool value can share the same
157 /// constantpool entry as another ARM constpool value.
158 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
160 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
162 virtual void print(raw_ostream &O) const;
163 static bool classof(const ARMConstantPoolValue *APV) {
164 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
166 static bool classof(const ARMConstantPoolConstant *) { return true; }
169 } // End llvm namespace