blob: 5a6180830bc95d7bc0e555de5cb433d42807f6ff [file] [log] [blame]
Evan Chenga8e29892007-01-19 07:51:42 +00001//===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Chenga8e29892007-01-19 07:51:42 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the ARM specific constantpool value class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
15#define LLVM_TARGET_ARM_CONSTANTPOOLVALUE_H
16
17#include "llvm/CodeGen/MachineConstantPool.h"
Jim Grosbach3a2429a2010-11-09 21:36:17 +000018#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarf4a7bf42010-06-15 14:50:42 +000019#include <cstddef>
Evan Chenga8e29892007-01-19 07:51:42 +000020
21namespace llvm {
22
Bob Wilson28989a82009-11-02 16:59:06 +000023class BlockAddress;
Bill Wendling4dd9b092011-09-29 23:48:44 +000024class Constant;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000025class GlobalValue;
Owen Anderson1d0be152009-08-13 21:58:54 +000026class LLVMContext;
Bill Wendling4dd9b092011-09-29 23:48:44 +000027class MachineBasicBlock;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000028
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000029namespace ARMCP {
30 enum ARMCPKind {
31 CPValue,
Bob Wilson28989a82009-11-02 16:59:06 +000032 CPExtSymbol,
33 CPBlockAddress,
Bill Wendling4dd9b092011-09-29 23:48:44 +000034 CPLSDA,
35 CPMachineBasicBlock
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000036 };
Jim Grosbach3a2429a2010-11-09 21:36:17 +000037
38 enum ARMCPModifier {
39 no_modifier,
40 TLSGD,
41 GOT,
42 GOTOFF,
43 GOTTPOFF,
44 TPOFF
45 };
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000046}
47
Evan Chenga8e29892007-01-19 07:51:42 +000048/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson31ba10b2009-11-02 17:10:37 +000049/// represent PC-relative displacement between the address of the load
Bob Wilson28989a82009-11-02 16:59:06 +000050/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Chenga8e29892007-01-19 07:51:42 +000051class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohman46510a72010-04-15 01:51:59 +000052 const Constant *CVal; // Constant being loaded.
Bill Wendling4dd9b092011-09-29 23:48:44 +000053 const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
Evan Chengc60e76d2007-01-30 20:37:08 +000054 const char *S; // ExtSymbol being loaded.
Evan Chenga8e29892007-01-19 07:51:42 +000055 unsigned LabelId; // Label id of the load.
Bob Wilson28989a82009-11-02 16:59:06 +000056 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson31ba10b2009-11-02 17:10:37 +000057 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Chenga8e29892007-01-19 07:51:42 +000058 // 8 for ARM, 4 for Thumb.
Jim Grosbach3a2429a2010-11-09 21:36:17 +000059 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000060 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000061
Bill Wendlingf2b76aa2011-10-01 06:40:33 +000062protected:
63 ARMConstantPoolValue(Type *Ty, unsigned id, ARMCP::ARMCPKind Kind,
64 unsigned char PCAdj, ARMCP::ARMCPModifier Modifier,
65 bool AddCurrentAddress);
66
Evan Chenga8e29892007-01-19 07:51:42 +000067public:
Dan Gohman46510a72010-04-15 01:51:59 +000068 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000069 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Jim Grosbach3a2429a2010-11-09 21:36:17 +000070 unsigned char PCAdj = 0,
71 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000072 bool AddCurrentAddress = false);
Bill Wendling4dd9b092011-09-29 23:48:44 +000073 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);
Owen Anderson1d0be152009-08-13 21:58:54 +000078 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Jim Grosbach3a2429a2010-11-09 21:36:17 +000079 unsigned char PCAdj = 0,
80 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000081 bool AddCurrentAddress = false);
Jim Grosbach3a2429a2010-11-09 21:36:17 +000082 ARMConstantPoolValue(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier);
Jim Grosbach1b747ad2009-08-11 00:09:57 +000083 ARMConstantPoolValue();
Jim Grosbachf1287872009-08-11 15:26:27 +000084 ~ARMConstantPoolValue();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000085
Dan Gohman46510a72010-04-15 01:51:59 +000086 const GlobalValue *getGV() const;
Evan Chengc60e76d2007-01-30 20:37:08 +000087 const char *getSymbol() const { return S; }
Dan Gohman46510a72010-04-15 01:51:59 +000088 const BlockAddress *getBlockAddress() const;
Bill Wendling4dd9b092011-09-29 23:48:44 +000089 const MachineBasicBlock *getMBB() const;
Bill Wendlingd98f8382011-09-30 18:42:06 +000090
Jim Grosbach3a2429a2010-11-09 21:36:17 +000091 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000092 const char *getModifierText() const;
Jim Grosbach3a2429a2010-11-09 21:36:17 +000093 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000094
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000095 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000096
Evan Chenga8e29892007-01-19 07:51:42 +000097 unsigned getLabelId() const { return LabelId; }
Evan Chenga8e29892007-01-19 07:51:42 +000098 unsigned char getPCAdjustment() const { return PCAdjust; }
Bill Wendlingd98f8382011-09-30 18:42:06 +000099
Bob Wilson28989a82009-11-02 16:59:06 +0000100 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
101 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000102 bool isBlockAddress() const { return Kind == ARMCP::CPBlockAddress; }
Bill Wendlingd98f8382011-09-30 18:42:06 +0000103 bool isLSDA() const { return Kind == ARMCP::CPLSDA; }
Bill Wendling4dd9b092011-09-29 23:48:44 +0000104 bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
Evan Chenga8e29892007-01-19 07:51:42 +0000105
Jim Grosbachcd3c7cb2010-11-29 23:09:20 +0000106 virtual unsigned getRelocationInfo() const { return 2; }
Chris Lattnercb459632009-07-21 23:34:23 +0000107
Evan Chenga8e29892007-01-19 07:51:42 +0000108 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
109 unsigned Alignment);
110
Jim Grosbach5405d582011-09-27 20:59:33 +0000111 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
Evan Chenga8e29892007-01-19 07:51:42 +0000112
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000113 /// 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);
Evan Cheng78e5c112009-11-07 03:52:02 +0000116
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000117 virtual void print(raw_ostream &O) const;
Evan Cheng5be59ea2008-10-29 23:55:17 +0000118 void print(raw_ostream *O) const { if (O) print(*O); }
Evan Cheng5be59ea2008-10-29 23:55:17 +0000119 void dump() const;
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000120
121 static bool classof(const ARMConstantPoolValue *) { return true; }
Evan Chenga8e29892007-01-19 07:51:42 +0000122};
Evan Cheng5be59ea2008-10-29 23:55:17 +0000123
Evan Cheng5be59ea2008-10-29 23:55:17 +0000124inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
125 V.print(O);
126 return O;
127}
128
Bill Wendlingf2b76aa2011-10-01 06:40:33 +0000129/// ARMConstantPoolConstant - ARM-specific constant pool values for Constants,
130/// Functions, and BlockAddresses.
131class ARMConstantPoolConstant : public ARMConstantPoolValue {
132 const Constant *CVal; // Constant being loaded.
133
134 ARMConstantPoolConstant(const Constant *C,
135 unsigned ID,
136 ARMCP::ARMCPKind Kind,
137 unsigned char PCAdj,
138 ARMCP::ARMCPModifier Modifier,
139 bool AddCurrentAddress);
140public:
141 static ARMConstantPoolConstant *Create(const Constant *C, unsigned ID);
142
143 const GlobalValue *getGV() const;
144
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);
148
149 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
150
151 virtual void print(raw_ostream &O) const;
152 static bool classof(const ARMConstantPoolValue *APV) {
153 return APV->isGlobalValue() || APV->isBlockAddress() || APV->isLSDA();
154 }
155 static bool classof(const ARMConstantPoolConstant *) { return true; }
156};
157
Evan Cheng5be59ea2008-10-29 23:55:17 +0000158} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +0000159
160#endif