blob: 3119b54563dee59dc65788e30753dfee3e085b0f [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"
Daniel Dunbarf4a7bf42010-06-15 14:50:42 +000018#include <cstddef>
Evan Chenga8e29892007-01-19 07:51:42 +000019
20namespace llvm {
21
Bob Wilson28989a82009-11-02 16:59:06 +000022class Constant;
23class BlockAddress;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000024class GlobalValue;
Owen Anderson1d0be152009-08-13 21:58:54 +000025class LLVMContext;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000026
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000027namespace ARMCP {
28 enum ARMCPKind {
29 CPValue,
Bob Wilson28989a82009-11-02 16:59:06 +000030 CPExtSymbol,
31 CPBlockAddress,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000032 CPLSDA
33 };
34}
35
Evan Chenga8e29892007-01-19 07:51:42 +000036/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson31ba10b2009-11-02 17:10:37 +000037/// represent PC-relative displacement between the address of the load
Bob Wilson28989a82009-11-02 16:59:06 +000038/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Chenga8e29892007-01-19 07:51:42 +000039class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohman46510a72010-04-15 01:51:59 +000040 const Constant *CVal; // Constant being loaded.
Evan Chengc60e76d2007-01-30 20:37:08 +000041 const char *S; // ExtSymbol being loaded.
Evan Chenga8e29892007-01-19 07:51:42 +000042 unsigned LabelId; // Label id of the load.
Bob Wilson28989a82009-11-02 16:59:06 +000043 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson31ba10b2009-11-02 17:10:37 +000044 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Chenga8e29892007-01-19 07:51:42 +000045 // 8 for ARM, 4 for Thumb.
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000046 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000047 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000048
49public:
Dan Gohman46510a72010-04-15 01:51:59 +000050 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000051 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);
Owen Anderson1d0be152009-08-13 21:58:54 +000054 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000055 unsigned char PCAdj = 0, const char *Modifier = NULL,
56 bool AddCurrentAddress = false);
Dan Gohman46510a72010-04-15 01:51:59 +000057 ARMConstantPoolValue(const GlobalValue *GV, const char *Modifier);
Jim Grosbach1b747ad2009-08-11 00:09:57 +000058 ARMConstantPoolValue();
Jim Grosbachf1287872009-08-11 15:26:27 +000059 ~ARMConstantPoolValue();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000060
Dan Gohman46510a72010-04-15 01:51:59 +000061 const GlobalValue *getGV() const;
Evan Chengc60e76d2007-01-30 20:37:08 +000062 const char *getSymbol() const { return S; }
Dan Gohman46510a72010-04-15 01:51:59 +000063 const BlockAddress *getBlockAddress() const;
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000064 const char *getModifier() const { return Modifier; }
65 bool hasModifier() const { return Modifier != NULL; }
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000066 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Chenga8e29892007-01-19 07:51:42 +000067 unsigned getLabelId() const { return LabelId; }
Evan Chenga8e29892007-01-19 07:51:42 +000068 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson28989a82009-11-02 16:59:06 +000069 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
70 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
71 bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000072 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Evan Chenga8e29892007-01-19 07:51:42 +000073
Chris Lattner354c0162009-07-21 23:36:01 +000074 virtual unsigned getRelocationInfo() const {
Chris Lattnercb459632009-07-21 23:34:23 +000075 // FIXME: This is conservatively claiming that these entries require a
76 // relocation, we may be able to do better than this.
77 return 2;
78 }
79
Evan Chenga8e29892007-01-19 07:51:42 +000080 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
81 unsigned Alignment);
82
83 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
84
Evan Cheng78e5c112009-11-07 03:52:02 +000085 /// hasSameValue - Return true if this ARM constpool value
86 /// can share the same constantpool entry as another ARM constpool value.
87 bool hasSameValue(ARMConstantPoolValue *ACPV);
88
Evan Cheng5be59ea2008-10-29 23:55:17 +000089 void print(raw_ostream *O) const { if (O) print(*O); }
90 void print(raw_ostream &O) const;
91 void dump() const;
Evan Chenga8e29892007-01-19 07:51:42 +000092};
Evan Cheng5be59ea2008-10-29 23:55:17 +000093
Evan Cheng5be59ea2008-10-29 23:55:17 +000094inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
95 V.print(O);
96 return O;
97}
98
99} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +0000100
101#endif