blob: 3119b54563dee59dc65788e30753dfee3e085b0f [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"
Daniel Dunbar09041342010-06-15 14:50:42 +000018#include <cstddef>
Evan Cheng10043e22007-01-19 07:51:42 +000019
20namespace llvm {
21
Bob Wilson433ab092009-11-02 16:59:06 +000022class Constant;
23class BlockAddress;
Dan Gohman0597e5b2008-07-11 20:38:31 +000024class GlobalValue;
Owen Anderson55f1c092009-08-13 21:58:54 +000025class LLVMContext;
Dan Gohman0597e5b2008-07-11 20:38:31 +000026
Jim Grosbach20eac922009-09-01 01:57:56 +000027namespace ARMCP {
28 enum ARMCPKind {
29 CPValue,
Bob Wilson433ab092009-11-02 16:59:06 +000030 CPExtSymbol,
31 CPBlockAddress,
Jim Grosbach20eac922009-09-01 01:57:56 +000032 CPLSDA
33 };
34}
35
Evan Cheng10043e22007-01-19 07:51:42 +000036/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilson4c00a522009-11-02 17:10:37 +000037/// represent PC-relative displacement between the address of the load
Bob Wilson433ab092009-11-02 16:59:06 +000038/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Evan Cheng10043e22007-01-19 07:51:42 +000039class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohmanbcaf6812010-04-15 01:51:59 +000040 const Constant *CVal; // Constant being loaded.
Evan Cheng83f35172007-01-30 20:37:08 +000041 const char *S; // ExtSymbol being loaded.
Evan Cheng10043e22007-01-19 07:51:42 +000042 unsigned LabelId; // Label id of the load.
Bob Wilson433ab092009-11-02 16:59:06 +000043 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilson4c00a522009-11-02 17:10:37 +000044 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Evan Cheng10043e22007-01-19 07:51:42 +000045 // 8 for ARM, 4 for Thumb.
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000046 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000047 bool AddCurrentAddress;
Evan Cheng10043e22007-01-19 07:51:42 +000048
49public:
Dan Gohmanbcaf6812010-04-15 01:51:59 +000050 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach20eac922009-09-01 01:57:56 +000051 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000052 unsigned char PCAdj = 0, const char *Modifier = NULL,
53 bool AddCurrentAddress = false);
Owen Anderson55f1c092009-08-13 21:58:54 +000054 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000055 unsigned char PCAdj = 0, const char *Modifier = NULL,
56 bool AddCurrentAddress = false);
Dan Gohmanbcaf6812010-04-15 01:51:59 +000057 ARMConstantPoolValue(const GlobalValue *GV, const char *Modifier);
Jim Grosbach693e36a2009-08-11 00:09:57 +000058 ARMConstantPoolValue();
Jim Grosbach74eb9e72009-08-11 15:26:27 +000059 ~ARMConstantPoolValue();
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000060
Dan Gohmanbcaf6812010-04-15 01:51:59 +000061 const GlobalValue *getGV() const;
Evan Cheng83f35172007-01-30 20:37:08 +000062 const char *getSymbol() const { return S; }
Dan Gohmanbcaf6812010-04-15 01:51:59 +000063 const BlockAddress *getBlockAddress() const;
Lauro Ramos Venancioee2d1642007-04-22 00:04:12 +000064 const char *getModifier() const { return Modifier; }
65 bool hasModifier() const { return Modifier != NULL; }
Lauro Ramos Venancioc39c12a2007-04-27 13:54:47 +000066 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
Evan Cheng10043e22007-01-19 07:51:42 +000067 unsigned getLabelId() const { return LabelId; }
Evan Cheng10043e22007-01-19 07:51:42 +000068 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson433ab092009-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 Grosbach20eac922009-09-01 01:57:56 +000072 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Evan Cheng10043e22007-01-19 07:51:42 +000073
Chris Lattner9bd736e2009-07-21 23:36:01 +000074 virtual unsigned getRelocationInfo() const {
Chris Lattnercfb01e22009-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 Cheng10043e22007-01-19 07:51:42 +000080 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
81 unsigned Alignment);
82
83 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
84
Evan Cheng7ff83192009-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 Chengde9dbc52008-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 Cheng10043e22007-01-19 07:51:42 +000092};
Evan Chengde9dbc52008-10-29 23:55:17 +000093
Evan Chengde9dbc52008-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 Cheng10043e22007-01-19 07:51:42 +0000100
101#endif