File indexing completed on 2026-05-10 08:43:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CODEGEN_MACHINECONSTANTPOOL_H
0016 #define LLVM_CODEGEN_MACHINECONSTANTPOOL_H
0017
0018 #include "llvm/ADT/DenseSet.h"
0019 #include "llvm/MC/SectionKind.h"
0020 #include "llvm/Support/Alignment.h"
0021 #include <climits>
0022 #include <vector>
0023
0024 namespace llvm {
0025
0026 class Constant;
0027 class DataLayout;
0028 class FoldingSetNodeID;
0029 class MachineConstantPool;
0030 class raw_ostream;
0031 class Type;
0032
0033
0034
0035 class MachineConstantPoolValue {
0036 virtual void anchor();
0037
0038 Type *Ty;
0039
0040 public:
0041 explicit MachineConstantPoolValue(Type *ty) : Ty(ty) {}
0042 virtual ~MachineConstantPoolValue() = default;
0043
0044 Type *getType() const { return Ty; }
0045
0046 virtual unsigned getSizeInBytes(const DataLayout &DL) const;
0047
0048 virtual int getExistingMachineCPValue(MachineConstantPool *CP,
0049 Align Alignment) = 0;
0050
0051 virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID) = 0;
0052
0053
0054 virtual void print(raw_ostream &O) const = 0;
0055 };
0056
0057 inline raw_ostream &operator<<(raw_ostream &OS,
0058 const MachineConstantPoolValue &V) {
0059 V.print(OS);
0060 return OS;
0061 }
0062
0063
0064
0065
0066
0067 class MachineConstantPoolEntry {
0068 public:
0069
0070 union {
0071 const Constant *ConstVal;
0072 MachineConstantPoolValue *MachineCPVal;
0073 } Val;
0074
0075
0076 Align Alignment;
0077
0078 bool IsMachineConstantPoolEntry;
0079
0080 MachineConstantPoolEntry(const Constant *V, Align A)
0081 : Alignment(A), IsMachineConstantPoolEntry(false) {
0082 Val.ConstVal = V;
0083 }
0084
0085 MachineConstantPoolEntry(MachineConstantPoolValue *V, Align A)
0086 : Alignment(A), IsMachineConstantPoolEntry(true) {
0087 Val.MachineCPVal = V;
0088 }
0089
0090
0091
0092
0093 bool isMachineConstantPoolEntry() const { return IsMachineConstantPoolEntry; }
0094
0095 Align getAlign() const { return Alignment; }
0096
0097 unsigned getSizeInBytes(const DataLayout &DL) const;
0098
0099
0100
0101
0102 bool needsRelocation() const;
0103
0104 SectionKind getSectionKind(const DataLayout *DL) const;
0105 };
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 class MachineConstantPool {
0118 Align PoolAlignment;
0119 std::vector<MachineConstantPoolEntry> Constants;
0120
0121 DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries;
0122 const DataLayout &DL;
0123
0124 const DataLayout &getDataLayout() const { return DL; }
0125
0126 public:
0127
0128 explicit MachineConstantPool(const DataLayout &DL)
0129 : PoolAlignment(1), DL(DL) {}
0130 ~MachineConstantPool();
0131
0132
0133
0134 Align getConstantPoolAlign() const { return PoolAlignment; }
0135
0136
0137
0138
0139 unsigned getConstantPoolIndex(const Constant *C, Align Alignment);
0140 unsigned getConstantPoolIndex(MachineConstantPoolValue *V, Align Alignment);
0141
0142
0143 bool isEmpty() const { return Constants.empty(); }
0144
0145 const std::vector<MachineConstantPoolEntry> &getConstants() const {
0146 return Constants;
0147 }
0148
0149
0150
0151 void print(raw_ostream &OS) const;
0152
0153
0154 void dump() const;
0155 };
0156
0157 }
0158
0159 #endif