LLVM  3.7.0
MachineConstantPool.h
Go to the documentation of this file.
1 //===-- CodeGen/MachineConstantPool.h - Abstract Constant Pool --*- 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 /// @file
11 /// This file declares the MachineConstantPool class which is an abstract
12 /// constant pool to keep track of constants referenced by a function.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
17 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
18 
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/MC/SectionKind.h"
21 #include <cassert>
22 #include <climits>
23 #include <vector>
24 
25 namespace llvm {
26 
27 class Constant;
28 class FoldingSetNodeID;
29 class DataLayout;
30 class TargetMachine;
31 class Type;
32 class MachineConstantPool;
33 class raw_ostream;
34 
35 /// Abstract base class for all machine specific constantpool value subclasses.
36 ///
38  virtual void anchor();
39  Type *Ty;
40 
41 public:
42  explicit MachineConstantPoolValue(Type *ty) : Ty(ty) {}
44 
45  /// getType - get type of this MachineConstantPoolValue.
46  ///
47  Type *getType() const { return Ty; }
48 
49 
50  /// getRelocationInfo - This method classifies the entry according to
51  /// whether or not it may generate a relocation entry. This must be
52  /// conservative, so if it might codegen to a relocatable entry, it should say
53  /// so. The return values are the same as Constant::getRelocationInfo().
54  virtual unsigned getRelocationInfo() const = 0;
55 
57  unsigned Alignment) = 0;
58 
59  virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
60 
61  /// print - Implement operator<<
62  virtual void print(raw_ostream &O) const = 0;
63 };
64 
66  const MachineConstantPoolValue &V) {
67  V.print(OS);
68  return OS;
69 }
70 
71 
72 /// This class is a data container for one entry in a MachineConstantPool.
73 /// It contains a pointer to the value and an offset from the start of
74 /// the constant pool.
75 /// @brief An entry in a MachineConstantPool
77 public:
78  /// The constant itself.
79  union {
82  } Val;
83 
84  /// The required alignment for this entry. The top bit is set when Val is
85  /// a target specific MachineConstantPoolValue.
86  unsigned Alignment;
87 
88  MachineConstantPoolEntry(const Constant *V, unsigned A)
89  : Alignment(A) {
90  Val.ConstVal = V;
91  }
93  : Alignment(A) {
94  Val.MachineCPVal = V;
95  Alignment |= 1U << (sizeof(unsigned)*CHAR_BIT-1);
96  }
97 
98  /// isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry
99  /// is indeed a target specific constantpool entry, not a wrapper over a
100  /// Constant.
102  return (int)Alignment < 0;
103  }
104 
105  int getAlignment() const {
106  return Alignment & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
107  }
108 
109  Type *getType() const;
110 
111  /// getRelocationInfo - This method classifies the entry according to
112  /// whether or not it may generate a relocation entry. This must be
113  /// conservative, so if it might codegen to a relocatable entry, it should say
114  /// so. The return values are:
115  ///
116  /// 0: This constant pool entry is guaranteed to never have a relocation
117  /// applied to it (because it holds a simple constant like '4').
118  /// 1: This entry has relocations, but the entries are guaranteed to be
119  /// resolvable by the static linker, so the dynamic linker will never see
120  /// them.
121  /// 2: This entry may have arbitrary relocations.
122  unsigned getRelocationInfo() const;
123 
124  SectionKind getSectionKind(const DataLayout *DL) const;
125 };
126 
127 /// The MachineConstantPool class keeps track of constants referenced by a
128 /// function which must be spilled to memory. This is used for constants which
129 /// are unable to be used directly as operands to instructions, which typically
130 /// include floating point and large integer constants.
131 ///
132 /// Instructions reference the address of these constant pool constants through
133 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine
134 /// code, these virtual address references are converted to refer to the
135 /// address of the function constant pool values.
136 /// @brief The machine constant pool.
138  unsigned PoolAlignment; ///< The alignment for the pool.
139  std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
140  /// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
141  DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
142  const DataLayout &DL;
143 
144  const DataLayout &getDataLayout() const { return DL; }
145 
146 public:
147  /// @brief The only constructor.
148  explicit MachineConstantPool(const DataLayout &DL)
149  : PoolAlignment(1), DL(DL) {}
151 
152  /// getConstantPoolAlignment - Return the alignment required by
153  /// the whole constant pool, of which the first element must be aligned.
154  unsigned getConstantPoolAlignment() const { return PoolAlignment; }
155 
156  /// getConstantPoolIndex - Create a new entry in the constant pool or return
157  /// an existing one. User must specify the minimum required alignment for
158  /// the object.
159  unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment);
160  unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment);
161 
162  /// isEmpty - Return true if this constant pool contains no constants.
163  bool isEmpty() const { return Constants.empty(); }
164 
165  const std::vector<MachineConstantPoolEntry> &getConstants() const {
166  return Constants;
167  }
168 
169  /// print - Used by the MachineFunction printer to print information about
170  /// constant pool objects. Implemented in MachineFunction.cpp
171  ///
172  void print(raw_ostream &OS) const;
173 
174  /// dump - Call print(cerr) to be called from the debugger.
175  void dump() const;
176 };
177 
178 } // End llvm namespace
179 
180 #endif
MachineConstantPoolValue * MachineCPVal
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
SectionKind getSectionKind(const DataLayout *DL) const
DenseSet - This implements a dense probed hash-table based set.
Definition: DenseSet.h:39
virtual void print(raw_ostream &O) const =0
print - Implement operator<<
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)=0
MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A)
unsigned getRelocationInfo() const
getRelocationInfo - This method classifies the entry according to whether or not it may generate a re...
MachineConstantPoolEntry(const Constant *V, unsigned A)
virtual int getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment)=0
This class is a data container for one entry in a MachineConstantPool.
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:297
bool isEmpty() const
isEmpty - Return true if this constant pool contains no constants.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important base class in LLVM.
Definition: Constant.h:41
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
MachineConstantPool(const DataLayout &DL)
The only constructor.
Abstract base class for all machine specific constantpool value subclasses.
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about constant pool objects...
unsigned Alignment
The required alignment for this entry.
void dump() const
dump - Call print(cerr) to be called from the debugger.
Type * getType() const
getType - get type of this MachineConstantPoolValue.
unsigned getConstantPoolAlignment() const
getConstantPoolAlignment - Return the alignment required by the whole constant pool, of which the first element must be aligned.
union llvm::MachineConstantPoolEntry::@30 Val
The constant itself.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1738
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
const std::vector< MachineConstantPoolEntry > & getConstants() const
virtual unsigned getRelocationInfo() const =0
getRelocationInfo - This method classifies the entry according to whether or not it may generate a re...
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...