LLVM 20.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"
21#include <climits>
22#include <vector>
23
24namespace llvm {
25
26class Constant;
27class DataLayout;
28class FoldingSetNodeID;
29class MachineConstantPool;
30class raw_ostream;
31class Type;
32
33/// Abstract base class for all machine specific constantpool value subclasses.
34///
36 virtual void anchor();
37
38 Type *Ty;
39
40public:
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
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
68public:
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
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
126public:
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);
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
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
basic Basic Alias true
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
RelocType Type
Definition: COFFYAML.cpp:410
This file defines the DenseSet and SmallDenseSet classes.
raw_pwrite_stream & OS
This is an important base class in LLVM.
Definition: Constant.h:42
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
Implements a dense probed hash-table based set.
Definition: DenseSet.h:278
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:327
This class is a data container for one entry in a MachineConstantPool.
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry.
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
union llvm::MachineConstantPoolEntry::@204 Val
The constant itself.
MachineConstantPoolEntry(const Constant *V, Align A)
MachineConstantPoolValue * MachineCPVal
Align Alignment
The required alignment for this entry.
unsigned getSizeInBytes(const DataLayout &DL) const
SectionKind getSectionKind(const DataLayout *DL) const
MachineConstantPoolEntry(MachineConstantPoolValue *V, Align A)
Abstract base class for all machine specific constantpool value subclasses.
virtual int getExistingMachineCPValue(MachineConstantPool *CP, Align Alignment)=0
virtual void print(raw_ostream &O) const =0
print - Implement operator<<
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID)=0
virtual ~MachineConstantPoolValue()=default
virtual unsigned getSizeInBytes(const DataLayout &DL) const
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
void dump() const
dump - Call print(cerr) to be called from the debugger.
MachineConstantPool(const DataLayout &DL)
The only constructor.
Align getConstantPoolAlign() const
Return the alignment required by the whole constant pool, of which the first element must be aligned.
const std::vector< MachineConstantPoolEntry > & getConstants() const
void print(raw_ostream &OS) const
print - Used by the MachineFunction printer to print information about constant pool objects.
bool isEmpty() const
isEmpty - Return true if this constant pool contains no constants.
unsigned getConstantPoolIndex(const Constant *C, Align Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one.
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:303
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39