blob: 688f38bf99e3e9df186333e410802e778a4d7b0a [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"
Jim Grosbach3a2429a2010-11-09 21:36:17 +000018#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarf4a7bf42010-06-15 14:50:42 +000019#include <cstddef>
Evan Chenga8e29892007-01-19 07:51:42 +000020
21namespace llvm {
22
Bob Wilson28989a82009-11-02 16:59:06 +000023class Constant;
24class BlockAddress;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000025class GlobalValue;
Owen Anderson1d0be152009-08-13 21:58:54 +000026class LLVMContext;
Dan Gohmandc2fbdd2008-07-11 20:38:31 +000027
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000028namespace ARMCP {
29 enum ARMCPKind {
30 CPValue,
Bob Wilson28989a82009-11-02 16:59:06 +000031 CPExtSymbol,
32 CPBlockAddress,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000033 CPLSDA
34 };
Jim Grosbach3a2429a2010-11-09 21:36:17 +000035
36 enum ARMCPModifier {
37 no_modifier,
38 TLSGD,
39 GOT,
40 GOTOFF,
41 GOTTPOFF,
42 TPOFF
43 };
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000044}
45
Evan Chenga8e29892007-01-19 07:51:42 +000046/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson31ba10b2009-11-02 17:10:37 +000047/// represent PC-relative displacement between the address of the load
Bob Wilson28989a82009-11-02 16:59:06 +000048/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Chenga8e29892007-01-19 07:51:42 +000049class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohman46510a72010-04-15 01:51:59 +000050 const Constant *CVal; // Constant being loaded.
Evan Chengc60e76d2007-01-30 20:37:08 +000051 const char *S; // ExtSymbol being loaded.
Evan Chenga8e29892007-01-19 07:51:42 +000052 unsigned LabelId; // Label id of the load.
Bob Wilson28989a82009-11-02 16:59:06 +000053 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson31ba10b2009-11-02 17:10:37 +000054 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Chenga8e29892007-01-19 07:51:42 +000055 // 8 for ARM, 4 for Thumb.
Jim Grosbach3a2429a2010-11-09 21:36:17 +000056 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000057 bool AddCurrentAddress;
Evan Chenga8e29892007-01-19 07:51:42 +000058
59public:
Dan Gohman46510a72010-04-15 01:51:59 +000060 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000061 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Jim Grosbach3a2429a2010-11-09 21:36:17 +000062 unsigned char PCAdj = 0,
63 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000064 bool AddCurrentAddress = false);
Owen Anderson1d0be152009-08-13 21:58:54 +000065 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Jim Grosbach3a2429a2010-11-09 21:36:17 +000066 unsigned char PCAdj = 0,
67 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000068 bool AddCurrentAddress = false);
Jim Grosbach3a2429a2010-11-09 21:36:17 +000069 ARMConstantPoolValue(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier);
Jim Grosbach1b747ad2009-08-11 00:09:57 +000070 ARMConstantPoolValue();
Jim Grosbachf1287872009-08-11 15:26:27 +000071 ~ARMConstantPoolValue();
Lauro Ramos Venancio0ae4a332007-04-22 00:04:12 +000072
Dan Gohman46510a72010-04-15 01:51:59 +000073 const GlobalValue *getGV() const;
Evan Chengc60e76d2007-01-30 20:37:08 +000074 const char *getSymbol() const { return S; }
Dan Gohman46510a72010-04-15 01:51:59 +000075 const BlockAddress *getBlockAddress() const;
Jim Grosbach3a2429a2010-11-09 21:36:17 +000076 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
77 const char *getModifierText() const {
78 switch (Modifier) {
79 default: llvm_unreachable("Unknown modifier!");
80 // FIXME: Are these case sensitive? It'd be nice to lower-case all the
81 // strings if that's legal.
82 case ARMCP::no_modifier: return "none";
83 case ARMCP::TLSGD: return "tlsgd";
84 case ARMCP::GOT: return "GOT";
85 case ARMCP::GOTOFF: return "GOTOFF";
86 case ARMCP::GOTTPOFF: return "gottpoff";
87 case ARMCP::TPOFF: return "tpoff";
88 }
89 }
90 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
Lauro Ramos Venancio64f4fa52007-04-27 13:54:47 +000091 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Chenga8e29892007-01-19 07:51:42 +000092 unsigned getLabelId() const { return LabelId; }
Evan Chenga8e29892007-01-19 07:51:42 +000093 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson28989a82009-11-02 16:59:06 +000094 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
95 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
96 bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
Jim Grosbach3fb2b1e2009-09-01 01:57:56 +000097 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Evan Chenga8e29892007-01-19 07:51:42 +000098
Chris Lattner354c0162009-07-21 23:36:01 +000099 virtual unsigned getRelocationInfo() const {
Chris Lattnercb459632009-07-21 23:34:23 +0000100 // FIXME: This is conservatively claiming that these entries require a
101 // relocation, we may be able to do better than this.
102 return 2;
103 }
104
Evan Chenga8e29892007-01-19 07:51:42 +0000105 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
106 unsigned Alignment);
107
108 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
109
Evan Cheng78e5c112009-11-07 03:52:02 +0000110 /// hasSameValue - Return true if this ARM constpool value
111 /// can share the same constantpool entry as another ARM constpool value.
112 bool hasSameValue(ARMConstantPoolValue *ACPV);
113
Evan Cheng5be59ea2008-10-29 23:55:17 +0000114 void print(raw_ostream *O) const { if (O) print(*O); }
115 void print(raw_ostream &O) const;
116 void dump() const;
Evan Chenga8e29892007-01-19 07:51:42 +0000117};
Evan Cheng5be59ea2008-10-29 23:55:17 +0000118
Evan Cheng5be59ea2008-10-29 23:55:17 +0000119inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
120 V.print(O);
121 return O;
122}
123
124} // End llvm namespace
Evan Chenga8e29892007-01-19 07:51:42 +0000125
126#endif