blob: 13683a3007805d81f854006fd070e7d3dad2f8f0 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Gohmanc24a3f82009-01-05 17:59:02 +000018#include <iosfwd>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000019
20namespace llvm {
21
Dan Gohman02983112008-07-11 20:38:31 +000022class GlobalValue;
Owen Anderson35b47072009-08-13 21:58:54 +000023class LLVMContext;
Dan Gohman02983112008-07-11 20:38:31 +000024
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025namespace ARMCP {
26 enum ARMCPKind {
27 CPValue,
28 CPNonLazyPtr,
29 CPStub
30 };
31}
32
33/// 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.
38 const char *S; // ExtSymbol being loaded.
39 unsigned LabelId; // Label id of the load.
40 ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub?
41 unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
42 // 8 for ARM, 4 for Thumb.
43 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
44 bool AddCurrentAddress;
45
46public:
47 ARMConstantPoolValue(GlobalValue *gv, unsigned id,
48 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
49 unsigned char PCAdj = 0, const char *Modifier = NULL,
50 bool AddCurrentAddress = false);
Owen Anderson35b47072009-08-13 21:58:54 +000051 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
53 unsigned char PCAdj = 0, const char *Modifier = NULL,
54 bool AddCurrentAddress = false);
55 ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind,
56 const char *Modifier);
Jim Grosbach29feb6a2009-08-11 00:09:57 +000057 ARMConstantPoolValue();
Jim Grosbach3fe420b2009-08-11 15:26:27 +000058 ~ARMConstantPoolValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059
60
61 GlobalValue *getGV() const { return GV; }
62 const char *getSymbol() const { return S; }
63 const char *getModifier() const { return Modifier; }
64 bool hasModifier() const { return Modifier != NULL; }
65 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
66 unsigned getLabelId() const { return LabelId; }
67 bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; }
68 bool isStub() const { return Kind == ARMCP::CPStub; }
69 unsigned char getPCAdjustment() const { return PCAdjust; }
70
Chris Lattner690b8d52009-07-21 23:36:01 +000071 virtual unsigned getRelocationInfo() const {
Chris Lattner8f3f8512009-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
Jim Grosbach770d7182009-08-11 15:33:49 +000077
Dan Gohmanf17a25c2007-07-18 16:29:46 +000078 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
79 unsigned Alignment);
80
81 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
82
Evan Chengf3aaeed2008-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;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088};
Evan Chengf3aaeed2008-10-29 23:55:17 +000089
Bob Wilson9b784f02009-07-14 21:45:58 +000090inline std::ostream &operator<<(std::ostream &O,
91 const ARMConstantPoolValue &V) {
Evan Chengf3aaeed2008-10-29 23:55:17 +000092 V.print(O);
93 return O;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000094}
Jim Grosbach770d7182009-08-11 15:33:49 +000095
Evan Chengf3aaeed2008-10-29 23:55:17 +000096inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
97 V.print(O);
98 return O;
99}
100
101} // End llvm namespace
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000102
103#endif