blob: 95c5358f5d21176fd6edb87a450601de04c84745 [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"
18
19namespace llvm {
20
Dan Gohman02983112008-07-11 20:38:31 +000021class GlobalValue;
Owen Anderson35b47072009-08-13 21:58:54 +000022class LLVMContext;
Dan Gohman02983112008-07-11 20:38:31 +000023
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024namespace ARMCP {
25 enum ARMCPKind {
26 CPValue,
27 CPNonLazyPtr,
28 CPStub
29 };
30}
31
32/// 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.
37 const char *S; // ExtSymbol being loaded.
38 unsigned LabelId; // Label id of the load.
39 ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub?
40 unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
41 // 8 for ARM, 4 for Thumb.
42 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
43 bool AddCurrentAddress;
44
45public:
46 ARMConstantPoolValue(GlobalValue *gv, unsigned id,
47 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
48 unsigned char PCAdj = 0, const char *Modifier = NULL,
49 bool AddCurrentAddress = false);
Owen Anderson35b47072009-08-13 21:58:54 +000050 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
52 unsigned char PCAdj = 0, const char *Modifier = NULL,
53 bool AddCurrentAddress = false);
54 ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind,
55 const char *Modifier);
Jim Grosbach29feb6a2009-08-11 00:09:57 +000056 ARMConstantPoolValue();
Jim Grosbach3fe420b2009-08-11 15:26:27 +000057 ~ARMConstantPoolValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058
59
60 GlobalValue *getGV() const { return GV; }
61 const char *getSymbol() const { return S; }
62 const char *getModifier() const { return Modifier; }
63 bool hasModifier() const { return Modifier != NULL; }
64 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
65 unsigned getLabelId() const { return LabelId; }
66 bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; }
67 bool isStub() const { return Kind == ARMCP::CPStub; }
68 unsigned char getPCAdjustment() const { return PCAdjust; }
69
Chris Lattner690b8d52009-07-21 23:36:01 +000070 virtual unsigned getRelocationInfo() const {
Chris Lattner8f3f8512009-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
Jim Grosbach770d7182009-08-11 15:33:49 +000076
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
78 unsigned Alignment);
79
80 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
81
Evan Chengf3aaeed2008-10-29 23:55:17 +000082 void print(raw_ostream *O) const { if (O) print(*O); }
83 void print(raw_ostream &O) const;
84 void dump() const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000085};
Evan Chengf3aaeed2008-10-29 23:55:17 +000086
Jim Grosbach770d7182009-08-11 15:33:49 +000087
Evan Chengf3aaeed2008-10-29 23:55:17 +000088inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
89 V.print(O);
90 return O;
91}
92
93} // End llvm namespace
Dan Gohmanf17a25c2007-07-18 16:29:46 +000094
95#endif