blob: 00c48086aef669ea2c578d68959156cdea066d20 [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
Jim Grosbach5e0257f2009-09-01 01:57:56 +000024namespace ARMCP {
25 enum ARMCPKind {
26 CPValue,
27 CPLSDA
28 };
29}
30
Dan Gohmanf17a25c2007-07-18 16:29:46 +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.
36 const char *S; // ExtSymbol being loaded.
37 unsigned LabelId; // Label id of the load.
Jim Grosbach4b673ee2009-09-01 02:05:03 +000038 ARMCP::ARMCPKind Kind; // Value or LSDA?
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
40 // 8 for ARM, 4 for Thumb.
41 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
42 bool AddCurrentAddress;
43
44public:
45 ARMConstantPoolValue(GlobalValue *gv, unsigned id,
Jim Grosbach5e0257f2009-09-01 01:57:56 +000046 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 unsigned char PCAdj = 0, const char *Modifier = NULL,
48 bool AddCurrentAddress = false);
Owen Anderson35b47072009-08-13 21:58:54 +000049 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 unsigned char PCAdj = 0, const char *Modifier = NULL,
51 bool AddCurrentAddress = false);
Evan Chengc2999142009-08-28 23:18:09 +000052 ARMConstantPoolValue(GlobalValue *GV, const char *Modifier);
Jim Grosbach29feb6a2009-08-11 00:09:57 +000053 ARMConstantPoolValue();
Jim Grosbach3fe420b2009-08-11 15:26:27 +000054 ~ARMConstantPoolValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055
56
57 GlobalValue *getGV() const { return GV; }
58 const char *getSymbol() const { return S; }
59 const char *getModifier() const { return Modifier; }
60 bool hasModifier() const { return Modifier != NULL; }
61 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
62 unsigned getLabelId() const { return LabelId; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 unsigned char getPCAdjustment() const { return PCAdjust; }
Jim Grosbach5e0257f2009-09-01 01:57:56 +000064 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065
Chris Lattner690b8d52009-07-21 23:36:01 +000066 virtual unsigned getRelocationInfo() const {
Chris Lattner8f3f8512009-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 Grosbach770d7182009-08-11 15:33:49 +000072
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
74 unsigned Alignment);
75
76 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
77
Evan Chengf3aaeed2008-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;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081};
Evan Chengf3aaeed2008-10-29 23:55:17 +000082
Jim Grosbach770d7182009-08-11 15:33:49 +000083
Evan Chengf3aaeed2008-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090
91#endif