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 Constant *CVal; // Constant being loaded.
53 const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
54 const char *S; // ExtSymbol being loaded.
55 unsigned LabelId; // Label id of the load.
56 ARMCP::ARMCPKind Kind; // Kind of constant.
57 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
58 // 8 for ARM, 4 for Thumb.
59 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
60 bool AddCurrentAddress;
63 ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
64 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
65 bool AddCurrentAddress);
68 ARMConstantPoolValue(const Constant *cval, unsigned id,
69 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
70 unsigned char PCAdj = 0,
71 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
72 bool AddCurrentAddress = false);
73 ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id,
74 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
75 unsigned char PCAdj = 0,
76 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
77 bool AddCurrentAddress = false);
78 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
79 unsigned char PCAdj = 0,
80 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
81 bool AddCurrentAddress = false);
82 ARMConstantPoolValue(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier);
83 ARMConstantPoolValue();
84 ~ARMConstantPoolValue();
86 const GlobalValue *getGV() const;
87 const char *getSymbol() const { return S; }
88 const BlockAddress *getBlockAddress() const;
89 const MachineBasicBlock *getMBB() const;
91 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
92 const char *getModifierText() const;
93 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
95 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
97 unsigned getLabelId() const { return LabelId; }
98 unsigned char getPCAdjustment() const { return PCAdjust; }
100 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
101 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
102 bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
103 bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
104 bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
106 virtual unsigned getRelocationInfo() const { return 2; }
108 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
111 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
113 /// hasSameValue - Return true if this ARM constpool value can share the same
114 /// constantpool entry as another ARM constpool value.
115 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
117 virtual void print(raw_ostream &O) const;
118 void print(raw_ostream *O) const { if (O) print(*O); }
121 static bool classof(const ARMConstantPoolValue *) { return true; }
124 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
129 /// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
130 /// Functions, and BlockAddresses.
131 class ARMConstantPoolConstant : public ARMConstantPoolValue {
132 const Constant *CVal; // Constant being loaded.
134 ARMConstantPoolConstant(const Constant *C,
136 ARMCP::ARMCPKind Kind,
138 ARMCP::ARMCPModifier Modifier,
139 bool AddCurrentAddress);
141 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
143 const GlobalValue *getGV() const;
145 /// hasSameValue - Return true if this ARM constpool value can share the same
146 /// constantpool entry as another ARM constpool value.
147 virtual bool hasSameValue(ARMConstantPoolValue *ACPV);
149 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
151 virtual void print(raw_ostream &O) const;
152 static bool classof(const ARMConstantPoolValue *APV) {
153 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
155 static bool classof(const ARMConstantPoolConstant *) { return true; }
158 } // End llvm namespace