blob: 1a3df3c89c6004c125506416894494064b44dee4 [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 BlockAddress;
Bill Wendlinga1127b22011-09-29 23:48:44 +000024class Constant;
Dan Gohman0597e5b2008-07-11 20:38:31 +000025class GlobalValue;
Owen Anderson55f1c092009-08-13 21:58:54 +000026class LLVMContext;
Bill Wendlinga1127b22011-09-29 23:48:44 +000027class MachineBasicBlock;
Dan Gohman0597e5b2008-07-11 20:38:31 +000028
Jim Grosbach20eac922009-09-01 01:57:56 +000029namespace ARMCP {
30 enum ARMCPKind {
31 CPValue,
Bob Wilson433ab092009-11-02 16:59:06 +000032 CPExtSymbol,
33 CPBlockAddress,
Bill Wendlinga1127b22011-09-29 23:48:44 +000034 CPLSDA,
35 CPMachineBasicBlock
Jim Grosbach20eac922009-09-01 01:57:56 +000036 };
Jim Grosbacha942ad42010-11-09 21:36:17 +000037
38 enum ARMCPModifier {
39 no_modifier,
40 TLSGD,
41 GOT,
42 GOTOFF,
43 GOTTPOFF,
44 TPOFF
45 };
Jim Grosbach20eac922009-09-01 01:57:56 +000046}
47
Evan Cheng10043e22007-01-19 07:51:42 +000048/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson4c00a522009-11-02 17:10:37 +000049/// represent PC-relative displacement between the address of the load
Bob Wilson433ab092009-11-02 16:59:06 +000050/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Cheng10043e22007-01-19 07:51:42 +000051class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohmanbcaf6812010-04-15 01:51:59 +000052 const Constant *CVal; // Constant being loaded.
Bill Wendlinga1127b22011-09-29 23:48:44 +000053 const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
Evan Cheng83f35172007-01-30 20:37:08 +000054 const char *S; // ExtSymbol being loaded.
Evan Cheng10043e22007-01-19 07:51:42 +000055 unsigned LabelId; // Label id of the load.
Bob Wilson433ab092009-11-02 16:59:06 +000056 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson4c00a522009-11-02 17:10:37 +000057 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Cheng10043e22007-01-19 07:51:42 +000058 // 8 for ARM, 4 for Thumb.
Jim Grosbacha942ad42010-11-09 21:36:17 +000059 ARMCP::ARMCPModifier Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000060 bool AddCurrentAddress;
Evan Cheng10043e22007-01-19 07:51:42 +000061
62public:
Dan Gohmanbcaf6812010-04-15 01:51:59 +000063 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach20eac922009-09-01 01:57:56 +000064 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Jim Grosbacha942ad42010-11-09 21:36:17 +000065 unsigned char PCAdj = 0,
66 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000067 bool AddCurrentAddress = false);
Bill Wendlinga1127b22011-09-29 23:48:44 +000068 ARMConstantPoolValue(LLVMContext &C, const MachineBasicBlock *mbb,unsigned id,
69 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
70 unsigned char PCAdj = 0,
71 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
72 bool AddCurrentAddress = false);
Owen Anderson55f1c092009-08-13 21:58:54 +000073 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Jim Grosbacha942ad42010-11-09 21:36:17 +000074 unsigned char PCAdj = 0,
75 ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000076 bool AddCurrentAddress = false);
Jim Grosbacha942ad42010-11-09 21:36:17 +000077 ARMConstantPoolValue(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier);
Jim Grosbach693e36a2009-08-11 00:09:57 +000078 ARMConstantPoolValue();
Jim Grosbach74eb9e72009-08-11 15:26:27 +000079 ~ARMConstantPoolValue();
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000080
Dan Gohmanbcaf6812010-04-15 01:51:59 +000081 const GlobalValue *getGV() const;
Evan Cheng83f35172007-01-30 20:37:08 +000082 const char *getSymbol() const { return S; }
Dan Gohmanbcaf6812010-04-15 01:51:59 +000083 const BlockAddress *getBlockAddress() const;
Bill Wendlinga1127b22011-09-29 23:48:44 +000084 const MachineBasicBlock *getMBB() const;
Jim Grosbacha942ad42010-11-09 21:36:17 +000085 ARMCP::ARMCPModifier getModifier() const { return Modifier; }
86 const char *getModifierText() const {
87 switch (Modifier) {
88 default: llvm_unreachable("Unknown modifier!");
89 // FIXME: Are these case sensitive? It'd be nice to lower-case all the
90 // strings if that's legal.
91 case ARMCP::no_modifier: return "none";
92 case ARMCP::TLSGD: return "tlsgd";
93 case ARMCP::GOT: return "GOT";
94 case ARMCP::GOTOFF: return "GOTOFF";
95 case ARMCP::GOTTPOFF: return "gottpoff";
96 case ARMCP::TPOFF: return "tpoff";
97 }
98 }
99 bool hasModifier() const { return Modifier != ARMCP::no_modifier; }
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +0000100 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Cheng10043e22007-01-19 07:51:42 +0000101 unsigned getLabelId() const { return LabelId; }
Evan Cheng10043e22007-01-19 07:51:42 +0000102 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson433ab092009-11-02 16:59:06 +0000103 bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
104 bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
105 bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
Jim Grosbach20eac922009-09-01 01:57:56 +0000106 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Bill Wendlinga1127b22011-09-29 23:48:44 +0000107 bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
Evan Cheng10043e22007-01-19 07:51:42 +0000108
Jim Grosbach9f0356b2010-11-29 23:09:20 +0000109 virtual unsigned getRelocationInfo() const { return 2; }
Chris Lattnercfb01e22009-07-21 23:34:23 +0000110
Evan Cheng10043e22007-01-19 07:51:42 +0000111 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
112 unsigned Alignment);
113
Jim Grosbachaf136f72011-09-27 20:59:33 +0000114 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
Evan Cheng10043e22007-01-19 07:51:42 +0000115
Evan Cheng7ff83192009-11-07 03:52:02 +0000116 /// hasSameValue - Return true if this ARM constpool value
117 /// can share the same constantpool entry as another ARM constpool value.
118 bool hasSameValue(ARMConstantPoolValue *ACPV);
119
Evan Chengde9dbc52008-10-29 23:55:17 +0000120 void print(raw_ostream *O) const { if (O) print(*O); }
121 void print(raw_ostream &O) const;
122 void dump() const;
Evan Cheng10043e22007-01-19 07:51:42 +0000123};
Evan Chengde9dbc52008-10-29 23:55:17 +0000124
Evan Chengde9dbc52008-10-29 23:55:17 +0000125inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
126 V.print(O);
127 return O;
128}
129
130} // End llvm namespace
Evan Cheng10043e22007-01-19 07:51:42 +0000131
132#endif