blob: 525346dd41fa1ed09b95e94b9b7e8d1a51ce7e7b [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"
18
19namespace llvm {
20
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000021class GlobalValue;
Owen Anderson1d0be152009-08-13 21:58:54 +000022class LLVMContext;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000023
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000024namespace ARMCP {
25 enum ARMCPKind {
26 CPValue,
27 CPLSDA
28 };
29}
30
Evan Chenga8e29892007-01-19 07:51:42 +000031/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
32/// represent PC relative displacement between the address of the load
33/// instruction and the global value being loaded, i.e. (&GV-(LPIC+8)).
34class ARMConstantPoolValue : public MachineConstantPoolValue {
35 GlobalValue *GV; // GlobalValue being loaded.
Evan Chengc60e76d2007-01-30 20:37:08 +000036 const char *S; // ExtSymbol being loaded.
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000037 ARMCP::ARMCPKind Kind; // Value or LSDA?
Evan Chenga8e29892007-01-19 07:51:42 +000038 unsigned LabelId; // Label id of the load.
Evan Chenga8e29892007-01-19 07:51:42 +000039 unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
40 // 8 for ARM, 4 for Thumb.
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000041 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000042 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000043
44public:
Evan Chengc60e76d2007-01-30 20:37:08 +000045 ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000046 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000047 unsigned char PCAdj = 0, const char *Modifier = NULL,
48 bool AddCurrentAddress = false);
Owen Anderson1d0be152009-08-13 21:58:54 +000049 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000050 unsigned char PCAdj = 0, const char *Modifier = NULL,
51 bool AddCurrentAddress = false);
Evan Chenge4e4ed32009-08-28 23:18:09 +000052 ARMConstantPoolValue(GlobalValue *GV, const char *Modifier);
Jim Grosbach1b747ad2009-08-11 00:09:57 +000053 ARMConstantPoolValue();
Jim Grosbachf1287872009-08-11 15:26:27 +000054 ~ARMConstantPoolValue();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000055
Evan Chenga8e29892007-01-19 07:51:42 +000056
57 GlobalValue *getGV() const { return GV; }
Evan Chengc60e76d2007-01-30 20:37:08 +000058 const char *getSymbol() const { return S; }
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000059 const char *getModifier() const { return Modifier; }
60 bool hasModifier() const { return Modifier != NULL; }
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000061 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Chenga8e29892007-01-19 07:51:42 +000062 unsigned getLabelId() const { return LabelId; }
Evan Chenga8e29892007-01-19 07:51:42 +000063 unsigned char getPCAdjustment() const { return PCAdjust; }
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000064 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Evan Chenga8e29892007-01-19 07:51:42 +000065
Chris Lattner354c0162009-07-21 23:36:01 +000066 virtual unsigned getRelocationInfo() const {
Chris Lattnercb459632009-07-21 23:34:23 +000067 // FIXME: This is conservatively claiming that these entries require a
68 // relocation, we may be able to do better than this.
69 return 2;
70 }
71
Jim Grosbach764ab522009-08-11 15:33:49 +000072
Evan Chenga8e29892007-01-19 07:51:42 +000073 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
74 unsigned Alignment);
75
76 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
77
Evan Cheng5be59ea2008-10-29 23:55:17 +000078 void print(raw_ostream *O) const { if (O) print(*O); }
79 void print(raw_ostream &O) const;
80 void dump() const;
Evan Chenga8e29892007-01-19 07:51:42 +000081};
Evan Cheng5be59ea2008-10-29 23:55:17 +000082
Jim Grosbach764ab522009-08-11 15:33:49 +000083
Evan Cheng5be59ea2008-10-29 23:55:17 +000084inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
85 V.print(O);
86 return O;
87}
88
89} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +000090
91#endif