blob: 3119b54563dee59dc65788e30753dfee3e085b0f [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Dunbar3cae8c12010-06-15 14:50:42 +000018#include <cstddef>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000019
20namespace llvm {
21
Bob Wilson62acbf12009-11-02 16:59:06 +000022class Constant;
23class BlockAddress;
Dan Gohman02983112008-07-11 20:38:31 +000024class GlobalValue;
Owen Anderson35b47072009-08-13 21:58:54 +000025class LLVMContext;
Dan Gohman02983112008-07-11 20:38:31 +000026
Jim Grosbach5e0257f2009-09-01 01:57:56 +000027namespace ARMCP {
28 enum ARMCPKind {
29 CPValue,
Bob Wilson62acbf12009-11-02 16:59:06 +000030 CPExtSymbol,
31 CPBlockAddress,
Jim Grosbach5e0257f2009-09-01 01:57:56 +000032 CPLSDA
33 };
34}
35
Dan Gohmanf17a25c2007-07-18 16:29:46 +000036/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
Bob Wilsona07d68f2009-11-02 17:10:37 +000037/// represent PC-relative displacement between the address of the load
Bob Wilson62acbf12009-11-02 16:59:06 +000038/// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039class ARMConstantPoolValue : public MachineConstantPoolValue {
Dan Gohman36c56d02010-04-15 01:51:59 +000040 const Constant *CVal; // Constant being loaded.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 const char *S; // ExtSymbol being loaded.
42 unsigned LabelId; // Label id of the load.
Bob Wilson62acbf12009-11-02 16:59:06 +000043 ARMCP::ARMCPKind Kind; // Kind of constant.
Bob Wilsona07d68f2009-11-02 17:10:37 +000044 unsigned char PCAdjust; // Extra adjustment if constantpool is pc-relative.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045 // 8 for ARM, 4 for Thumb.
46 const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
47 bool AddCurrentAddress;
48
49public:
Dan Gohman36c56d02010-04-15 01:51:59 +000050 ARMConstantPoolValue(const Constant *cval, unsigned id,
Jim Grosbach5e0257f2009-09-01 01:57:56 +000051 ARMCP::ARMCPKind Kind = ARMCP::CPValue,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 unsigned char PCAdj = 0, const char *Modifier = NULL,
53 bool AddCurrentAddress = false);
Owen Anderson35b47072009-08-13 21:58:54 +000054 ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055 unsigned char PCAdj = 0, const char *Modifier = NULL,
56 bool AddCurrentAddress = false);
Dan Gohman36c56d02010-04-15 01:51:59 +000057 ARMConstantPoolValue(const GlobalValue *GV, const char *Modifier);
Jim Grosbach29feb6a2009-08-11 00:09:57 +000058 ARMConstantPoolValue();
Jim Grosbach3fe420b2009-08-11 15:26:27 +000059 ~ARMConstantPoolValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060
Dan Gohman36c56d02010-04-15 01:51:59 +000061 const GlobalValue *getGV() const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062 const char *getSymbol() const { return S; }
Dan Gohman36c56d02010-04-15 01:51:59 +000063 const BlockAddress *getBlockAddress() const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064 const char *getModifier() const { return Modifier; }
65 bool hasModifier() const { return Modifier != NULL; }
66 bool mustAddCurrentAddress() const { return AddCurrentAddress; }
67 unsigned getLabelId() const { return LabelId; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068 unsigned char getPCAdjustment() const { return PCAdjust; }
Bob Wilson62acbf12009-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 Grosbach5e0257f2009-09-01 01:57:56 +000072 bool isLSDA() { return Kind == ARMCP::CPLSDA; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073
Chris Lattner690b8d52009-07-21 23:36:01 +000074 virtual unsigned getRelocationInfo() const {
Chris Lattner8f3f8512009-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
81 unsigned Alignment);
82
83 virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
84
Evan Cheng626474d2009-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 Chengf3aaeed2008-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;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092};
Evan Chengf3aaeed2008-10-29 23:55:17 +000093
Evan Chengf3aaeed2008-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000100
101#endif