blob: 688f38bf99e3e9df186333e410802e778a4d7b0a [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"
Jim Grosbacha942ad42010-11-09 21:36:17 +000018#include "llvm/Support/ErrorHandling.h"
Daniel Dunbar09041342010-06-15 14:50:42 +000019#include <cstddef>
Evan Cheng10043e22007-01-19 07:51:42 +000020
21namespace llvm {
22
Bob Wilson433ab092009-11-02 16:59:06 +000023class Constant;
24class BlockAddress;
Dan Gohman0597e5b2008-07-11 20:38:31 +000025class GlobalValue;
Owen Anderson55f1c092009-08-13 21:58:54 +000026class LLVMContext;
Dan Gohman0597e5b2008-07-11 20:38:31 +000027
Jim Grosbach20eac922009-09-01 01:57:56 +000028namespace ARMCP {
29 enum ARMCPKind {
30 CPValue,
Bob Wilson433ab092009-11-02 16:59:06 +000031 CPExtSymbol,
32 CPBlockAddress,
Jim Grosbach20eac922009-09-01 01:57:56 +000033 CPLSDA
34 };
Jim Grosbacha942ad42010-11-09 21:36:17 +000035
36 enum ARMCPModifier {
37 no_modifier,
38 TLSGD,
39 GOT,
40 GOTOFF,
41 GOTTPOFF,
42 TPOFF
43 };
Jim Grosbach20eac922009-09-01 01:57:56 +000044}
45
Evan Cheng10043e22007-01-19 07:51:42 +000046/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson4c00a522009-11-02 17:10:37 +000047/// represent PC-relative displacement between the address of the load
Bob Wilson433ab092009-11-02 16:59:06 +000048/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Cheng10043e22007-01-19 07:51:42 +000049class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohmanbcaf6812010-04-15 01:51:59 +000050 const Constant *CVal; // Constant being loaded.
Evan Cheng83f35172007-01-30 20:37:08 +000051 const char *S; // ExtSymbol being loaded.
Evan Cheng10043e22007-01-19 07:51:42 +000052 unsigned LabelId; // Label id of the load.
Bob Wilson433ab092009-11-02 16:59:06 +000053 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson4c00a522009-11-02 17:10:37 +000054 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Cheng10043e22007-01-19 07:51:42 +000055 // 8 for ARM, 4 for Thumb.
Jim Grosbacha942ad42010-11-09 21:36:17 +000056 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000057 bool AddCurrentAddress;
Evan Cheng10043e22007-01-19 07:51:42 +000058
59public:
Dan Gohmanbcaf6812010-04-15 01:51:59 +000060 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach20eac922009-09-01 01:57:56 +000061 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Jim Grosbacha942ad42010-11-09 21:36:17 +000062 unsigned char PCAdj = 0,
63 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000064 bool AddCurrentAddress = false);
Owen Anderson55f1c092009-08-13 21:58:54 +000065 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Jim Grosbacha942ad42010-11-09 21:36:17 +000066 unsigned char PCAdj = 0,
67 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000068 bool AddCurrentAddress = false);
Jim Grosbacha942ad42010-11-09 21:36:17 +000069 ARMConstantPoolValue(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier);
Jim Grosbach693e36a2009-08-11 00:09:57 +000070 ARMConstantPoolValue();
Jim Grosbach74eb9e72009-08-11 15:26:27 +000071 ~ARMConstantPoolValue();
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000072
Dan Gohmanbcaf6812010-04-15 01:51:59 +000073 const GlobalValue *getGV() const;
Evan Cheng83f35172007-01-30 20:37:08 +000074 const char *getSymbol() const { return S; }
Dan Gohmanbcaf6812010-04-15 01:51:59 +000075 const BlockAddress *getBlockAddress() const;
Jim Grosbacha942ad42010-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 Venancioc39c12a2007-04-27 13:54:47 +000091 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Cheng10043e22007-01-19 07:51:42 +000092 unsigned getLabelId() const { return LabelId; }
Evan Cheng10043e22007-01-19 07:51:42 +000093 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson433ab092009-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 Grosbach20eac922009-09-01 01:57:56 +000097 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Evan Cheng10043e22007-01-19 07:51:42 +000098
Chris Lattner9bd736e2009-07-21 23:36:01 +000099 virtual unsigned getRelocationInfo() const {
Chris Lattnercfb01e22009-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 Cheng10043e22007-01-19 07:51:42 +0000105 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
106 unsigned Alignment);
107
108 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
109
Evan Cheng7ff83192009-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 Chengde9dbc52008-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 Cheng10043e22007-01-19 07:51:42 +0000117};
Evan Chengde9dbc52008-10-29 23:55:17 +0000118
Evan Chengde9dbc52008-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 Cheng10043e22007-01-19 07:51:42 +0000125
126#endif