LLVM  4.0.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 
50  unsigned Alignment) = 0;
51 
52  virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
53 
54  /// print - Implement operator<<
55  virtual void print(raw_ostream &O) const = 0;
56 };
57 
59  const MachineConstantPoolValue &V) {
60  V.print(OS);
61  return OS;
62 }
63 
64 /// This class is a data container for one entry in a MachineConstantPool.
65 /// It contains a pointer to the value and an offset from the start of
66 /// the constant pool.
67 /// @brief An entry in a MachineConstantPool
69 public:
70  /// The constant itself.
71  union {
74  } Val;
75 
76  /// The required alignment for this entry. The top bit is set when Val is
77  /// a target specific MachineConstantPoolValue.
78  unsigned Alignment;
79 
80  MachineConstantPoolEntry(const Constant *V, unsigned A)
81  : Alignment(A) {
82  Val.ConstVal = V;
83  }
85  : Alignment(A) {
86  Val.MachineCPVal = V;
87  Alignment |= 1U << (sizeof(unsigned) * CHAR_BIT - 1);
88  }
89 
90  /// isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry
91  /// is indeed a target specific constantpool entry, not a wrapper over a
92  /// Constant.
94  return (int)Alignment < 0;
95  }
96 
97  int getAlignment() const {
98  return Alignment & ~(1 << (sizeof(unsigned) * CHAR_BIT - 1));
99  }
100 
101  Type *getType() const;
102 
103  /// This method classifies the entry according to whether or not it may
104  /// generate a relocation entry. This must be conservative, so if it might
105  /// codegen to a relocatable entry, it should say so.
106  bool needsRelocation() const;
107 
108  SectionKind getSectionKind(const DataLayout *DL) const;
109 };
110 
111 /// The MachineConstantPool class keeps track of constants referenced by a
112 /// function which must be spilled to memory. This is used for constants which
113 /// are unable to be used directly as operands to instructions, which typically
114 /// include floating point and large integer constants.
115 ///
116 /// Instructions reference the address of these constant pool constants through
117 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine
118 /// code, these virtual address references are converted to refer to the
119 /// address of the function constant pool values.
120 /// @brief The machine constant pool.
122  unsigned PoolAlignment; ///< The alignment for the pool.
123  std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
124  /// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
125  DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
126  const DataLayout &DL;
127 
128  const DataLayout &getDataLayout() const { return DL; }
129 
130 public:
131  /// @brief The only constructor.
132  explicit MachineConstantPool(const DataLayout &DL)
133  : PoolAlignment(1), DL(DL) {}
135 
136  /// getConstantPoolAlignment - Return the alignment required by
137  /// the whole constant pool, of which the first element must be aligned.
138  unsigned getConstantPoolAlignment() const { return PoolAlignment; }
139 
140  /// getConstantPoolIndex - Create a new entry in the constant pool or return
141  /// an existing one. User must specify the minimum required alignment for
142  /// the object.
143  unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment);
145  unsigned Alignment);
146 
147  /// isEmpty - Return true if this constant pool contains no constants.
148  bool isEmpty() const { return Constants.empty(); }
149 
150  const std::vector<MachineConstantPoolEntry> &getConstants() const {
151  return Constants;
152  }
153 
154  /// print - Used by the MachineFunction printer to print information about
155  /// constant pool objects. Implemented in MachineFunction.cpp
156  ///
157  void print(raw_ostream &OS) const;
158 
159  /// dump - Call print(cerr) to be called from the debugger.
160  void dump() const;
161 };
162 
163 } // End llvm namespace
164 
165 #endif
MachineConstantPoolValue * MachineCPVal
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:102
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
SectionKind getSectionKind(const DataLayout *DL) const
Implements a dense probed hash-table based set.
Definition: DenseSet.h:202
virtual void print(raw_ostream &O) const =0
print - Implement operator<<
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)=0
MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A)
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:316
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:42
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
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.
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.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1726
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry...
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
void dump() const
dump - Call print(cerr) to be called from the debugger.
const std::vector< MachineConstantPoolEntry > & getConstants() const
union llvm::MachineConstantPoolEntry::@35 Val
The constant itself.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...