blob: bb5232a53bbe8aa197c17f27699f68ba7459bc5e [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>
Evan Chenga8e29892007-01-19 07:51:42 +000019
20namespace llvm {
21
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000022class GlobalValue;
23
Evan Chengc60e76d2007-01-30 20:37:08 +000024namespace ARMCP {
25 enum ARMCPKind {
26 CPValue,
27 CPNonLazyPtr,
28 CPStub
29 };
30}
31
Evan Chenga8e29892007-01-19 07:51:42 +000032/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
33/// represent PC relative displacement between the address of the load
34/// instruction and the global value being loaded, i.e. (&GV-(LPIC+8)).
35class ARMConstantPoolValue : public MachineConstantPoolValue {
36 GlobalValue *GV; // GlobalValue being loaded.
Evan Chengc60e76d2007-01-30 20:37:08 +000037 const char *S; // ExtSymbol being loaded.
Evan Chenga8e29892007-01-19 07:51:42 +000038 unsigned LabelId; // Label id of the load.
Evan Chengc60e76d2007-01-30 20:37:08 +000039 ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub?
Evan Chenga8e29892007-01-19 07:51:42 +000040 unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
41 // 8 for ARM, 4 for Thumb.
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000042 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000043 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000044
45public:
Evan Chengc60e76d2007-01-30 20:37:08 +000046 ARMConstantPoolValue(GlobalValue *gv, unsigned id,
47 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000048 unsigned char PCAdj = 0, const char *Modifier = NULL,
49 bool AddCurrentAddress = false);
Evan Chengc60e76d2007-01-30 20:37:08 +000050 ARMConstantPoolValue(const char *s, unsigned id,
51 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000052 unsigned char PCAdj = 0, const char *Modifier = NULL,
53 bool AddCurrentAddress = false);
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000054 ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind,
55 const char *Modifier);
Jim Grosbach1b747ad2009-08-11 00:09:57 +000056 ARMConstantPoolValue();
Jim Grosbachf1287872009-08-11 15:26:27 +000057 ~ARMConstantPoolValue();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000058
Evan Chenga8e29892007-01-19 07:51:42 +000059
60 GlobalValue *getGV() const { return GV; }
Evan Chengc60e76d2007-01-30 20:37:08 +000061 const char *getSymbol() const { return S; }
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000062 const char *getModifier() const { return Modifier; }
63 bool hasModifier() const { return Modifier != NULL; }
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000064 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Chenga8e29892007-01-19 07:51:42 +000065 unsigned getLabelId() const { return LabelId; }
Evan Chengc60e76d2007-01-30 20:37:08 +000066 bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; }
67 bool isStub() const { return Kind == ARMCP::CPStub; }
Evan Chenga8e29892007-01-19 07:51:42 +000068 unsigned char getPCAdjustment() const { return PCAdjust; }
69
Chris Lattner354c0162009-07-21 23:36:01 +000070 virtual unsigned getRelocationInfo() const {
Chris Lattnercb459632009-07-21 23:34:23 +000071 // FIXME: This is conservatively claiming that these entries require a
72 // relocation, we may be able to do better than this.
73 return 2;
74 }
75
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
78 unsigned Alignment);
79
80 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
81
Evan Cheng5be59ea2008-10-29 23:55:17 +000082 void print(std::ostream *O) const { if (O) print(*O); }
83 void print(std::ostream &O) const;
84 void print(raw_ostream *O) const { if (O) print(*O); }
85 void print(raw_ostream &O) const;
86 void dump() const;
Evan Chenga8e29892007-01-19 07:51:42 +000087};
Evan Cheng5be59ea2008-10-29 23:55:17 +000088
Bob Wilson8718bc42009-07-14 21:45:58 +000089inline std::ostream &operator<<(std::ostream &O,
90 const ARMConstantPoolValue &V) {
Evan Cheng5be59ea2008-10-29 23:55:17 +000091 V.print(O);
92 return O;
Evan Chenga8e29892007-01-19 07:51:42 +000093}
Evan Cheng5be59ea2008-10-29 23:55:17 +000094
95inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
96 V.print(O);
97 return O;
98}
99
100} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +0000101
102#endif