PTX: Various stylistic and code readability changes recommended by Jim Grosbach.
[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 #include "llvm/Support/ErrorHandling.h"
19 #include <cstddef>
20
21 namespace llvm {
22
23 class BlockAddress;
24 class Constant;
25 class GlobalValue;
26 class LLVMContext;
27 class MachineBasicBlock;
28
29 namespace ARMCP {
30   enum ARMCPKind {
31     CPValue,
32     CPExtSymbol,
33     CPBlockAddress,
34     CPLSDA,
35     CPMachineBasicBlock
36   };
37
38   enum ARMCPModifier {
39     no_modifier,
40     TLSGD,
41     GOT,
42     GOTOFF,
43     GOTTPOFF,
44     TPOFF
45   };
46 }
47
48 /// ARMConstantPoolValue - ARM specific constantpool value. This is used to
49 /// represent PC-relative displacement between the address of the load
50 /// instruction and the constant being loaded, i.e. (&GV-(LPIC+8)).
51 class ARMConstantPoolValue : public MachineConstantPoolValue {
52   const Constant *CVal;    // Constant being loaded.
53   const MachineBasicBlock *MBB; // MachineBasicBlock being loaded.
54   const char *S;           // ExtSymbol being loaded.
55   unsigned LabelId;        // Label id of the load.
56   ARMCP::ARMCPKind Kind;   // Kind of constant.
57   unsigned char PCAdjust;  // Extra adjustment if constantpool is pc-relative.
58                            // 8 for ARM, 4 for Thumb.
59   ARMCP::ARMCPModifier Modifier;   // GV modifier i.e. (&GV(modifier)-(LPIC+8))
60   bool AddCurrentAddress;
61
62 public:
63   ARMConstantPoolValue(const Constant *cval, unsigned id,
64                        ARMCP::ARMCPKind Kind = ARMCP::CPValue,
65                        unsigned char PCAdj = 0,
66                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
67                        bool AddCurrentAddress = false);
68   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);
73   ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
74                        unsigned char PCAdj = 0,
75                        ARMCP::ARMCPModifier Modifier = ARMCP::no_modifier,
76                        bool AddCurrentAddress = false);
77   ARMConstantPoolValue(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier);
78   ARMConstantPoolValue();
79   ~ARMConstantPoolValue();
80
81   const GlobalValue *getGV() const;
82   const char *getSymbol() const { return S; }
83   const BlockAddress *getBlockAddress() const;
84   const MachineBasicBlock *getMBB() const;
85   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; }
100   bool mustAddCurrentAddress() const { return AddCurrentAddress; }
101   unsigned getLabelId() const { return LabelId; }
102   unsigned char getPCAdjustment() const { return PCAdjust; }
103   bool isGlobalValue() const { return Kind == ARMCP::CPValue; }
104   bool isExtSymbol() const { return Kind == ARMCP::CPExtSymbol; }
105   bool isBlockAddress() { return Kind == ARMCP::CPBlockAddress; }
106   bool isLSDA() { return Kind == ARMCP::CPLSDA; }
107   bool isMachineBasicBlock() { return Kind == ARMCP::CPMachineBasicBlock; }
108
109   virtual unsigned getRelocationInfo() const { return 2; }
110
111   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
112                                         unsigned Alignment);
113
114   virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID);
115
116   /// 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
120   void print(raw_ostream *O) const { if (O) print(*O); }
121   void print(raw_ostream &O) const;
122   void dump() const;
123 };
124
125 inline raw_ostream &operator<<(raw_ostream &O, const ARMConstantPoolValue &V) {
126   V.print(O);
127   return O;
128 }
129
130 } // End llvm namespace
131
132 #endif