LLVM  14.0.0git
MachineConstantPool.h
Go to the documentation of this file.
1 //===- CodeGen/MachineConstantPool.h - Abstract Constant Pool ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// @file
10 /// This file declares the MachineConstantPool class which is an abstract
11 /// constant pool to keep track of constants referenced by a function.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
16 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
17 
18 #include "llvm/ADT/DenseSet.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Support/Alignment.h"
21 #include <climits>
22 #include <vector>
23 
24 namespace llvm {
25 
26 class Constant;
27 class DataLayout;
28 class FoldingSetNodeID;
29 class MachineConstantPool;
30 class raw_ostream;
31 class Type;
32 
33 /// Abstract base class for all machine specific constantpool value subclasses.
34 ///
36  virtual void anchor();
37 
38  Type *Ty;
39 
40 public:
41  explicit MachineConstantPoolValue(Type *ty) : Ty(ty) {}
42  virtual ~MachineConstantPoolValue() = default;
43 
44  Type *getType() const { return Ty; }
45 
46  virtual unsigned getSizeInBytes(const DataLayout &DL) const;
47 
49  Align Alignment) = 0;
50 
51  virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
52 
53  /// print - Implement operator<<
54  virtual void print(raw_ostream &O) const = 0;
55 };
56 
58  const MachineConstantPoolValue &V) {
59  V.print(OS);
60  return OS;
61 }
62 
63 /// This class is a data container for one entry in a MachineConstantPool.
64 /// It contains a pointer to the value and an offset from the start of
65 /// the constant pool.
66 /// An entry in a MachineConstantPool
68 public:
69  /// The constant itself.
70  union {
73  } Val;
74 
75  /// The required alignment for this entry.
77 
79 
82  Val.ConstVal = V;
83  }
84 
87  Val.MachineCPVal = V;
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 
95  Align getAlign() const { return Alignment; }
96 
97  unsigned getSizeInBytes(const DataLayout &DL) const;
98 
99  /// This method classifies the entry according to whether or not it may
100  /// generate a relocation entry. This must be conservative, so if it might
101  /// codegen to a relocatable entry, it should say so.
102  bool needsRelocation() const;
103 
104  SectionKind getSectionKind(const DataLayout *DL) const;
105 };
106 
107 /// The MachineConstantPool class keeps track of constants referenced by a
108 /// function which must be spilled to memory. This is used for constants which
109 /// are unable to be used directly as operands to instructions, which typically
110 /// include floating point and large integer constants.
111 ///
112 /// Instructions reference the address of these constant pool constants through
113 /// the use of MO_ConstantPoolIndex values. When emitting assembly or machine
114 /// code, these virtual address references are converted to refer to the
115 /// address of the function constant pool values.
116 /// The machine constant pool.
118  Align PoolAlignment; ///< The alignment for the pool.
119  std::vector<MachineConstantPoolEntry> Constants; ///< The pool of constants.
120  /// MachineConstantPoolValues that use an existing MachineConstantPoolEntry.
121  DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
122  const DataLayout &DL;
123 
124  const DataLayout &getDataLayout() const { return DL; }
125 
126 public:
127  /// The only constructor.
128  explicit MachineConstantPool(const DataLayout &DL)
129  : PoolAlignment(1), DL(DL) {}
131 
132  /// Return the alignment required by the whole constant pool, of which the
133  /// first element must be aligned.
134  Align getConstantPoolAlign() const { return PoolAlignment; }
135 
136  /// getConstantPoolIndex - Create a new entry in the constant pool or return
137  /// an existing one. User must specify the minimum required alignment for
138  /// the object.
139  unsigned getConstantPoolIndex(const Constant *C, Align Alignment);
140  unsigned getConstantPoolIndex(MachineConstantPoolValue *V, Align Alignment);
141 
142  /// isEmpty - Return true if this constant pool contains no constants.
143  bool isEmpty() const { return Constants.empty(); }
144 
145  const std::vector<MachineConstantPoolEntry> &getConstants() const {
146  return Constants;
147  }
148 
149  /// print - Used by the MachineFunction printer to print information about
150  /// constant pool objects. Implemented in MachineFunction.cpp
151  void print(raw_ostream &OS) const;
152 
153  /// dump - Call print(cerr) to be called from the debugger.
154  void dump() const;
155 };
156 
157 } // end namespace llvm
158 
159 #endif // LLVM_CODEGEN_MACHINECONSTANTPOOL_H
llvm::MachineConstantPool::getConstantPoolIndex
unsigned getConstantPoolIndex(const Constant *C, Align Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.
Definition: MachineFunction.cpp:1463
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:113
llvm::MachineConstantPool::getConstantPoolAlign
Align getConstantPoolAlign() const
Return the alignment required by the whole constant pool, of which the first element must be aligned.
Definition: MachineConstantPool.h:134
llvm::MachineConstantPool::isEmpty
bool isEmpty() const
isEmpty - Return true if this constant pool contains no constants.
Definition: MachineConstantPool.h:143
llvm::MachineConstantPoolEntry::MachineCPVal
MachineConstantPoolValue * MachineCPVal
Definition: MachineConstantPool.h:72
llvm::MachineConstantPoolValue
Abstract base class for all machine specific constantpool value subclasses.
Definition: MachineConstantPool.h:35
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::MachineConstantPoolEntry::MachineConstantPoolEntry
MachineConstantPoolEntry(const Constant *V, Align A)
Definition: MachineConstantPool.h:80
llvm::MachineConstantPoolEntry::MachineConstantPoolEntry
MachineConstantPoolEntry(MachineConstantPoolValue *V, Align A)
Definition: MachineConstantPool.h:85
llvm::MachineConstantPoolValue::getType
Type * getType() const
Definition: MachineConstantPool.h:44
llvm::MachineConstantPoolEntry::IsMachineConstantPoolEntry
bool IsMachineConstantPoolEntry
Definition: MachineConstantPool.h:78
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::MachineConstantPoolValue::MachineConstantPoolValue
MachineConstantPoolValue(Type *ty)
Definition: MachineConstantPool.h:41
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::MachineConstantPool::MachineConstantPool
MachineConstantPool(const DataLayout &DL)
The only constructor.
Definition: MachineConstantPool.h:128
llvm::MachineConstantPoolValue::print
virtual void print(raw_ostream &O) const =0
print - Implement operator<<
DenseSet.h
false
Definition: StackSlotColoring.cpp:142
llvm::MachineConstantPoolEntry::getSectionKind
SectionKind getSectionKind(const DataLayout *DL) const
Definition: MachineFunction.cpp:1386
llvm::MachineConstantPoolEntry::getAlign
Align getAlign() const
Definition: MachineConstantPool.h:95
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::operator<<
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:230
llvm::MachineConstantPool::~MachineConstantPool
~MachineConstantPool()
Definition: MachineFunction.cpp:1403
llvm::MachineConstantPoolEntry::Val
union llvm::MachineConstantPoolEntry::@181 Val
The constant itself.
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:206
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::MachineConstantPoolValue::getSizeInBytes
virtual unsigned getSizeInBytes(const DataLayout &DL) const
Definition: MachineFunction.cpp:1369
llvm::MachineConstantPool
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
Definition: MachineConstantPool.h:117
TemplateParamKind::Type
@ Type
llvm::MachineConstantPoolEntry::isMachineConstantPoolEntry
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
Definition: MachineConstantPool.h:93
llvm::MachineConstantPoolValue::~MachineConstantPoolValue
virtual ~MachineConstantPoolValue()=default
llvm::MachineConstantPoolEntry::needsRelocation
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry.
Definition: MachineFunction.cpp:1379
llvm::MachineConstantPoolValue::addSelectionDAGCSEId
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)=0
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::FoldingSetNodeID
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:313
llvm::HexagonISD::CP
@ CP
Definition: HexagonISelLowering.h:53
Alignment.h
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::MachineConstantPoolEntry
This class is a data container for one entry in a MachineConstantPool.
Definition: MachineConstantPool.h:67
llvm::MachineConstantPool::getConstants
const std::vector< MachineConstantPoolEntry > & getConstants() const
Definition: MachineConstantPool.h:145
SectionKind.h
llvm::MachineConstantPool::print
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about constant pool objects.
Definition: MachineFunction.cpp:1499
llvm::MachineConstantPoolValue::getExistingMachineCPValue
virtual int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment)=0
llvm::MachineConstantPool::dump
void dump() const
dump - Call print(cerr) to be called from the debugger.
Definition: MachineFunction.cpp:1515
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1879
llvm::MachineConstantPoolEntry::ConstVal
const Constant * ConstVal
Definition: MachineConstantPool.h:71
llvm::MachineConstantPoolEntry::getSizeInBytes
unsigned getSizeInBytes(const DataLayout &DL) const
Definition: MachineFunction.cpp:1373
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::MachineConstantPoolEntry::Alignment
Align Alignment
The required alignment for this entry.
Definition: MachineConstantPool.h:76