blob: 6f4eddf7361d92daabe6646c3f70c20263d98a96 [file] [log] [blame]
Evan Cheng10043e22007-01-19 07:51:42 +00001//===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Cheng10043e22007-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"
18
19namespace llvm {
20
Bob Wilson433ab092009-11-02 16:59:06 +000021class Constant;
22class BlockAddress;
Dan Gohman0597e5b2008-07-11 20:38:31 +000023class GlobalValue;
Owen Anderson55f1c092009-08-13 21:58:54 +000024class LLVMContext;
Dan Gohman0597e5b2008-07-11 20:38:31 +000025
Jim Grosbach20eac922009-09-01 01:57:56 +000026namespace ARMCP {
27 enum ARMCPKind {
28 CPValue,
Bob Wilson433ab092009-11-02 16:59:06 +000029 CPExtSymbol,
30 CPBlockAddress,
Jim Grosbach20eac922009-09-01 01:57:56 +000031 CPLSDA
32 };
33}
34
Evan Cheng10043e22007-01-19 07:51:42 +000035/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson4c00a522009-11-02 17:10:37 +000036/// represent PC-relative displacement between the address of the load
Bob Wilson433ab092009-11-02 16:59:06 +000037/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Cheng10043e22007-01-19 07:51:42 +000038class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohmanbcaf6812010-04-15 01:51:59 +000039 const Constant *CVal; // Constant being loaded.
Evan Cheng83f35172007-01-30 20:37:08 +000040 const char *S; // ExtSymbol being loaded.
Evan Cheng10043e22007-01-19 07:51:42 +000041 unsigned LabelId; // Label id of the load.
Bob Wilson433ab092009-11-02 16:59:06 +000042 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson4c00a522009-11-02 17:10:37 +000043 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Cheng10043e22007-01-19 07:51:42 +000044 // 8 for ARM, 4 for Thumb.
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000045 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000046 bool AddCurrentAddress;
Evan Cheng10043e22007-01-19 07:51:42 +000047
48public:
Dan Gohmanbcaf6812010-04-15 01:51:59 +000049 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach20eac922009-09-01 01:57:56 +000050 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000051 unsigned char PCAdj = 0, const char *Modifier = NULL,
52 bool AddCurrentAddress = false);
Owen Anderson55f1c092009-08-13 21:58:54 +000053 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000054 unsigned char PCAdj = 0, const char *Modifier = NULL,
55 bool AddCurrentAddress = false);
Dan Gohmanbcaf6812010-04-15 01:51:59 +000056 ARMConstantPoolValue(const GlobalValue *GV, const char *Modifier);
Jim Grosbach693e36a2009-08-11 00:09:57 +000057 ARMConstantPoolValue();
Jim Grosbach74eb9e72009-08-11 15:26:27 +000058 ~ARMConstantPoolValue();
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000059
Dan Gohmanbcaf6812010-04-15 01:51:59 +000060 const GlobalValue *getGV() const;
Evan Cheng83f35172007-01-30 20:37:08 +000061 const char *getSymbol() const { return S; }
Dan Gohmanbcaf6812010-04-15 01:51:59 +000062 const BlockAddress *getBlockAddress() const;
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000063 const char *getModifier() const { return Modifier; }
64 bool hasModifier() const { return Modifier != NULL; }
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000065 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Cheng10043e22007-01-19 07:51:42 +000066 unsigned getLabelId() const { return LabelId; }
Evan Cheng10043e22007-01-19 07:51:42 +000067 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson433ab092009-11-02 16:59:06 +000068 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
69 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
70 bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
Jim Grosbach20eac922009-09-01 01:57:56 +000071 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Evan Cheng10043e22007-01-19 07:51:42 +000072
Chris Lattner9bd736e2009-07-21 23:36:01 +000073 virtual unsigned getRelocationInfo() const {
Chris Lattnercfb01e22009-07-21 23:34:23 +000074 // FIXME: This is conservatively claiming that these entries require a
75 // relocation, we may be able to do better than this.
76 return 2;
77 }
78
Evan Cheng10043e22007-01-19 07:51:42 +000079 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
80 unsigned Alignment);
81
82 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
83
Evan Cheng7ff83192009-11-07 03:52:02 +000084 /// hasSameValue - Return true if this ARM constpool value
85 /// can share the same constantpool entry as another ARM constpool value.
86 bool hasSameValue(ARMConstantPoolValue *ACPV);
87
Evan Chengde9dbc52008-10-29 23:55:17 +000088 void print(raw_ostream *O) const { if (O) print(*O); }
89 void print(raw_ostream &O) const;
90 void dump() const;
Evan Cheng10043e22007-01-19 07:51:42 +000091};
Evan Chengde9dbc52008-10-29 23:55:17 +000092
Evan Chengde9dbc52008-10-29 23:55:17 +000093inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
94 V.print(O);
95 return O;
96}
97
98} // End llvm namespace
Evan Cheng10043e22007-01-19 07:51:42 +000099
100#endif