blob: 504a71e779eac9fd09f752debd8bc455af16b3cf [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"
Dan Gohmand68a0762009-01-05 17:59:02 +000018#include <iosfwd>
Jim Grosbach3034e8f2009-08-11 00:20:00 +000019#include <stdlib.h>
Evan Chenga8e29892007-01-19 07:51:42 +000020
21namespace llvm {
22
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000023class GlobalValue;
24
Evan Chengc60e76d2007-01-30 20:37:08 +000025namespace ARMCP {
26 enum ARMCPKind {
27 CPValue,
28 CPNonLazyPtr,
29 CPStub
30 };
31}
32
Evan Chenga8e29892007-01-19 07:51:42 +000033/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
34/// represent PC relative displacement between the address of the load
35/// instruction and the global value being loaded, i.e. (&GV-(LPIC+8)).
36class ARMConstantPoolValue : public MachineConstantPoolValue {
37 GlobalValue *GV; // GlobalValue being loaded.
Evan Chengc60e76d2007-01-30 20:37:08 +000038 const char *S; // ExtSymbol being loaded.
Evan Chenga8e29892007-01-19 07:51:42 +000039 unsigned LabelId; // Label id of the load.
Evan Chengc60e76d2007-01-30 20:37:08 +000040 ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub?
Evan Chenga8e29892007-01-19 07:51:42 +000041 unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
42 // 8 for ARM, 4 for Thumb.
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000043 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000044 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000045
46public:
Evan Chengc60e76d2007-01-30 20:37:08 +000047 ARMConstantPoolValue(GlobalValue *gv, unsigned id,
48 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000049 unsigned char PCAdj = 0, const char *Modifier = NULL,
50 bool AddCurrentAddress = false);
Evan Chengc60e76d2007-01-30 20:37:08 +000051 ARMConstantPoolValue(const char *s, unsigned id,
52 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000053 unsigned char PCAdj = 0, const char *Modifier = NULL,
54 bool AddCurrentAddress = false);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000055 ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind,
56 const char *Modifier);
Jim Grosbach1b747ad2009-08-11 00:09:57 +000057 ARMConstantPoolValue();
58 ~ARMConstantPoolValue() {free((void*)S);}
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000059
Evan Chenga8e29892007-01-19 07:51:42 +000060
61 GlobalValue *getGV() const { return GV; }
Evan Chengc60e76d2007-01-30 20:37:08 +000062 const char *getSymbol() const { return S; }
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000063 const char *getModifier() const { return Modifier; }
64 bool hasModifier() const { return Modifier != NULL; }
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000065 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Chenga8e29892007-01-19 07:51:42 +000066 unsigned getLabelId() const { return LabelId; }
Evan Chengc60e76d2007-01-30 20:37:08 +000067 bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; }
68 bool isStub() const { return Kind == ARMCP::CPStub; }
Evan Chenga8e29892007-01-19 07:51:42 +000069 unsigned char getPCAdjustment() const { return PCAdjust; }
70
Chris Lattner354c0162009-07-21 23:36:01 +000071 virtual unsigned getRelocationInfo() const {
Chris Lattnercb459632009-07-21 23:34:23 +000072 // FIXME: This is conservatively claiming that these entries require a
73 // relocation, we may be able to do better than this.
74 return 2;
75 }
76
77
Evan Chenga8e29892007-01-19 07:51:42 +000078 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
79 unsigned Alignment);
80
81 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
82
Evan Cheng5be59ea2008-10-29 23:55:17 +000083 void print(std::ostream *O) const { if (O) print(*O); }
84 void print(std::ostream &O) const;
85 void print(raw_ostream *O) const { if (O) print(*O); }
86 void print(raw_ostream &O) const;
87 void dump() const;
Evan Chenga8e29892007-01-19 07:51:42 +000088};
Evan Cheng5be59ea2008-10-29 23:55:17 +000089
Bob Wilson8718bc42009-07-14 21:45:58 +000090inline std::ostream &operator<<(std::ostream &O,
91 const ARMConstantPoolValue &V) {
Evan Cheng5be59ea2008-10-29 23:55:17 +000092 V.print(O);
93 return O;
Evan Chenga8e29892007-01-19 07:51:42 +000094}
Evan Cheng5be59ea2008-10-29 23:55:17 +000095
96inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
97 V.print(O);
98 return O;
99}
100
101} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +0000102
103#endif