- Add TargetInstrInfo::isIdentical(). It's similar to MachineInstr::isIdentical
[oota-llvm.git] / lib / Target / ARM / ARMConstantPoolValue.h
1 //===- ARMConstantPoolValue.h - ARM constantpool value ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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"
18
19 namespace llvm {
20
21 class Constant;
22 class BlockAddress;
23 class GlobalValue;
24 class LLVMContext;
25
26 namespace ARMCP {
27   enum ARMCPKind {
28     CPValue,
29     CPExtSymbol,
30     CPBlockAddress,
31     CPLSDA
32   };
33 }
34
35 /// ARMConstantPoolValue - ARM specific constantpool value. This is used to
36 /// represent PC-relative displacement between the address of the load
37 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
38 class ARMConstantPoolValue : public MachineConstantPoolValue {
39   Constant *CVal;          // Constant being loaded.
40   const char *S;           // ExtSymbol being loaded.
41   unsigned LabelId;        // Label id of the load.
42   ARMCP::ARMCPKind Kind;   // Kind of constant.
43   unsigned char PCAdjust;  // Extra adjustment if constantpool is pc-relative.
44                            // 8 for ARM, 4 for Thumb.
45   const char *Modifier;    // GV modifier i.e. (&GV(modifier)-(LPIC+8))
46   bool AddCurrentAddress;
47
48 public:
49   ARMConstantPoolValue(Constant *cval, unsigned id,
50                        ARMCP::ARMCPKind Kind = ARMCP::CPValue,
51                        unsigned char PCAdj = 0, const char *Modifier = NULL,
52                        bool AddCurrentAddress = false);
53   ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
54                        unsigned char PCAdj = 0, const char *Modifier = NULL,
55                        bool AddCurrentAddress = false);
56   ARMConstantPoolValue(GlobalValue *GV, const char *Modifier);
57   ARMConstantPoolValue();
58   ~ARMConstantPoolValue();
59
60   GlobalValue *getGV() const;
61   const char *getSymbol() const { return S; }
62   BlockAddress *getBlockAddress() const;
63   const char *getModifier() const { return Modifier; }
64   bool hasModifier() const { return Modifier != NULL; }
65   bool mustAddCurrentAddress() const { return AddCurrentAddress; }
66   unsigned getLabelId() const { return LabelId; }
67   unsigned char getPCAdjustment() const { return PCAdjust; }
68   bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
69   bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
70   bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
71   bool isLSDA() { return Kind == ARMCP::CPLSDA; }
72
73   virtual unsigned getRelocationInfo() const {
74     // FIXME: This is conservatively claiming that these entries require a
75     // relocation, we may be able to do better than this.
76     return 2;
77   }
78
79   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
80                                         unsigned Alignment);
81
82   virtual void AddSelectionDAGCSEId(FoldingSetNodeID &ID);
83
84   /// hasSameValue - Return true if this ARM constpool value
85   /// can share the same constantpool entry as another ARM constpool value.
86   bool hasSameValue(ARMConstantPoolValue *ACPV);
87
88   void print(raw_ostream *O) const { if (O) print(*O); }
89   void print(raw_ostream &O) const;
90   void dump() const;
91 };
92
93 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
94   V.print(O);
95   return O;
96 }
97
98 } // End llvm namespace
99
100 #endif