| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 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 |
|
| 34 |
|
| 35 |
class MachineConstantPoolValue { |
| 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 |
|
| 48 |
virtual int getExistingMachineCPValue(MachineConstantPool *CP, |
| 49 |
Align Alignment) = 0; |
| 50 |
|
| 51 |
virtual void addSelectionDAGCSEId(FoldingSetNodeID &ID) = 0; |
| 52 |
|
| 53 |
|
| 54 |
virtual void print(raw_ostream &O) const = 0; |
| 55 |
}; |
| 56 |
|
| 57 |
inline raw_ostream &operator<<(raw_ostream &OS, |
| 58 |
const MachineConstantPoolValue &V) { |
| 59 |
V.print(OS); |
| 60 |
return OS; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
class MachineConstantPoolEntry { |
| 68 |
public: |
| 69 |
|
| 70 |
union { |
| 71 |
const Constant *ConstVal; |
| 72 |
MachineConstantPoolValue *MachineCPVal; |
| 73 |
} Val; |
| 74 |
|
| 75 |
|
| 76 |
Align Alignment; |
| 77 |
|
| 78 |
bool IsMachineConstantPoolEntry; |
| 79 |
|
| 80 |
MachineConstantPoolEntry(const Constant *V, Align A) |
| 81 |
: Alignment(A), IsMachineConstantPoolEntry(false) { |
| 82 |
Val.ConstVal = V; |
| 83 |
} |
| 84 |
|
| 85 |
MachineConstantPoolEntry(MachineConstantPoolValue *V, Align A) |
| 86 |
: Alignment(A), IsMachineConstantPoolEntry(true) { |
| 87 |
Val.MachineCPVal = V; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
bool isMachineConstantPoolEntry() const { return IsMachineConstantPoolEntry; } |
| 94 |
|
| 95 |
Align getAlign() const { return Alignment; } |
| 96 |
|
| 97 |
unsigned getSizeInBytes(const DataLayout &DL) const; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
bool needsRelocation() const; |
| 103 |
|
| 104 |
SectionKind getSectionKind(const DataLayout *DL) const; |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
class MachineConstantPool { |
| 118 |
Align PoolAlignment; |
| 119 |
std::vector<MachineConstantPoolEntry> Constants; |
| 120 |
|
| 121 |
DenseSet<MachineConstantPoolValue*> MachineCPVsSharingEntries; |
| 122 |
const DataLayout &DL; |
| 123 |
|
| 124 |
const DataLayout &getDataLayout() const { return DL; } |
| 125 |
|
| 126 |
public: |
| 127 |
|
| 128 |
explicit MachineConstantPool(const DataLayout &DL) |
| 129 |
: PoolAlignment(1), DL(DL) {} |
| 130 |
~MachineConstantPool(); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
Align getConstantPoolAlign() const { return PoolAlignment; } |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
unsigned getConstantPoolIndex(const Constant *C, Align Alignment); |
| 140 |
unsigned getConstantPoolIndex(MachineConstantPoolValue *V, Align Alignment); |
| 141 |
|
| 142 |
|
| 143 |
bool isEmpty() const { return Constants.empty(); } |
| 144 |
|
| 145 |
const std::vector<MachineConstantPoolEntry> &getConstants() const { |
| 146 |
return Constants; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
void print(raw_ostream &OS) const; |
| 152 |
|
| 153 |
|
| 154 |
void dump() const; |
| 155 |
}; |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
#endif |