@@ -52,152 +52,87 @@ class DTSortableEntry : public MapVector<const MachineFunction *, Register> {
52
52
void addDep (DTSortableEntry *E) { Deps.push_back (E); }
53
53
};
54
54
55
- struct SpecialTypeDescriptor {
56
- enum SpecialTypeKind {
57
- STK_Empty = 0 ,
58
- STK_Image,
59
- STK_SampledImage,
60
- STK_Sampler,
61
- STK_Pipe,
62
- STK_DeviceEvent,
63
- STK_Pointer,
64
- STK_Last = -1
65
- };
66
- SpecialTypeKind Kind;
67
-
68
- unsigned Hash;
69
-
70
- SpecialTypeDescriptor () = delete ;
71
- SpecialTypeDescriptor (SpecialTypeKind K) : Kind(K) { Hash = Kind; }
72
-
73
- unsigned getHash () const { return Hash; }
74
-
75
- virtual ~SpecialTypeDescriptor () {}
76
- };
77
-
78
- struct ImageTypeDescriptor : public SpecialTypeDescriptor {
79
- union ImageAttrs {
80
- struct BitFlags {
81
- unsigned Dim : 3 ;
82
- unsigned Depth : 2 ;
83
- unsigned Arrayed : 1 ;
84
- unsigned MS : 1 ;
85
- unsigned Sampled : 2 ;
86
- unsigned ImageFormat : 6 ;
87
- unsigned AQ : 2 ;
88
- } Flags;
89
- unsigned Val;
90
- };
91
-
92
- ImageTypeDescriptor (const Type *SampledTy, unsigned Dim, unsigned Depth,
93
- unsigned Arrayed, unsigned MS, unsigned Sampled,
94
- unsigned ImageFormat, unsigned AQ = 0 )
95
- : SpecialTypeDescriptor(SpecialTypeKind::STK_Image) {
96
- ImageAttrs Attrs;
97
- Attrs.Val = 0 ;
98
- Attrs.Flags .Dim = Dim;
99
- Attrs.Flags .Depth = Depth;
100
- Attrs.Flags .Arrayed = Arrayed;
101
- Attrs.Flags .MS = MS;
102
- Attrs.Flags .Sampled = Sampled;
103
- Attrs.Flags .ImageFormat = ImageFormat;
104
- Attrs.Flags .AQ = AQ;
105
- Hash = (DenseMapInfo<Type *>().getHashValue (SampledTy) & 0xffff ) ^
106
- ((Attrs.Val << 8 ) | Kind);
107
- }
108
-
109
- static bool classof (const SpecialTypeDescriptor *TD) {
110
- return TD->Kind == SpecialTypeKind::STK_Image;
111
- }
112
- };
113
-
114
- struct SampledImageTypeDescriptor : public SpecialTypeDescriptor {
115
- SampledImageTypeDescriptor (const Type *SampledTy, const MachineInstr *ImageTy)
116
- : SpecialTypeDescriptor(SpecialTypeKind::STK_SampledImage) {
117
- assert (ImageTy->getOpcode () == SPIRV::OpTypeImage);
118
- ImageTypeDescriptor TD (
119
- SampledTy, ImageTy->getOperand (2 ).getImm (),
120
- ImageTy->getOperand (3 ).getImm (), ImageTy->getOperand (4 ).getImm (),
121
- ImageTy->getOperand (5 ).getImm (), ImageTy->getOperand (6 ).getImm (),
122
- ImageTy->getOperand (7 ).getImm (), ImageTy->getOperand (8 ).getImm ());
123
- Hash = TD.getHash () ^ Kind;
124
- }
125
-
126
- static bool classof (const SpecialTypeDescriptor *TD) {
127
- return TD->Kind == SpecialTypeKind::STK_SampledImage;
128
- }
129
- };
130
-
131
- struct SamplerTypeDescriptor : public SpecialTypeDescriptor {
132
- SamplerTypeDescriptor ()
133
- : SpecialTypeDescriptor(SpecialTypeKind::STK_Sampler) {
134
- Hash = Kind;
135
- }
136
-
137
- static bool classof (const SpecialTypeDescriptor *TD) {
138
- return TD->Kind == SpecialTypeKind::STK_Sampler;
139
- }
55
+ enum SpecialTypeKind {
56
+ STK_Empty = 0 ,
57
+ STK_Image,
58
+ STK_SampledImage,
59
+ STK_Sampler,
60
+ STK_Pipe,
61
+ STK_DeviceEvent,
62
+ STK_Pointer,
63
+ STK_Last = -1
140
64
};
141
65
142
- struct PipeTypeDescriptor : public SpecialTypeDescriptor {
143
-
144
- PipeTypeDescriptor (uint8_t AQ)
145
- : SpecialTypeDescriptor(SpecialTypeKind::STK_Pipe) {
146
- Hash = (AQ << 8 ) | Kind;
147
- }
148
-
149
- static bool classof (const SpecialTypeDescriptor *TD) {
150
- return TD->Kind == SpecialTypeKind::STK_Pipe;
66
+ using SpecialTypeDescriptor = std::tuple<const Type *, unsigned , unsigned >;
67
+
68
+ union ImageAttrs {
69
+ struct BitFlags {
70
+ unsigned Dim : 3 ;
71
+ unsigned Depth : 2 ;
72
+ unsigned Arrayed : 1 ;
73
+ unsigned MS : 1 ;
74
+ unsigned Sampled : 2 ;
75
+ unsigned ImageFormat : 6 ;
76
+ unsigned AQ : 2 ;
77
+ } Flags;
78
+ unsigned Val;
79
+
80
+ ImageAttrs (unsigned Dim, unsigned Depth, unsigned Arrayed, unsigned MS,
81
+ unsigned Sampled, unsigned ImageFormat, unsigned AQ = 0 ) {
82
+ Val = 0 ;
83
+ Flags.Dim = Dim;
84
+ Flags.Depth = Depth;
85
+ Flags.Arrayed = Arrayed;
86
+ Flags.MS = MS;
87
+ Flags.Sampled = Sampled;
88
+ Flags.ImageFormat = ImageFormat;
89
+ Flags.AQ = AQ;
151
90
}
152
91
};
153
92
154
- struct DeviceEventTypeDescriptor : public SpecialTypeDescriptor {
155
-
156
- DeviceEventTypeDescriptor ()
157
- : SpecialTypeDescriptor(SpecialTypeKind::STK_DeviceEvent) {
158
- Hash = Kind;
159
- }
160
-
161
- static bool classof (const SpecialTypeDescriptor *TD) {
162
- return TD->Kind == SpecialTypeKind::STK_DeviceEvent;
163
- }
164
- };
165
-
166
- struct PointerTypeDescriptor : public SpecialTypeDescriptor {
167
- const Type *ElementType;
168
- unsigned AddressSpace;
169
-
170
- PointerTypeDescriptor () = delete ;
171
- PointerTypeDescriptor (const Type *ElementType, unsigned AddressSpace)
172
- : SpecialTypeDescriptor(SpecialTypeKind::STK_Pointer),
173
- ElementType (ElementType), AddressSpace(AddressSpace) {
174
- Hash = (DenseMapInfo<Type *>().getHashValue (ElementType) & 0xffff ) ^
175
- ((AddressSpace << 8 ) | Kind);
176
- }
177
-
178
- static bool classof (const SpecialTypeDescriptor *TD) {
179
- return TD->Kind == SpecialTypeKind::STK_Pointer;
180
- }
181
- };
93
+ inline SpecialTypeDescriptor
94
+ make_descr_image (const Type *SampledTy, unsigned Dim, unsigned Depth,
95
+ unsigned Arrayed, unsigned MS, unsigned Sampled,
96
+ unsigned ImageFormat, unsigned AQ = 0 ) {
97
+ return std::make_tuple (
98
+ SampledTy,
99
+ ImageAttrs (Dim, Depth, Arrayed, MS, Sampled, ImageFormat, AQ).Val ,
100
+ SpecialTypeKind::STK_Image);
101
+ }
102
+
103
+ inline SpecialTypeDescriptor
104
+ make_descr_sampled_image (const Type *SampledTy, const MachineInstr *ImageTy) {
105
+ assert (ImageTy->getOpcode () == SPIRV::OpTypeImage);
106
+ return std::make_tuple (
107
+ SampledTy,
108
+ ImageAttrs (
109
+ ImageTy->getOperand (2 ).getImm (), ImageTy->getOperand (3 ).getImm (),
110
+ ImageTy->getOperand (4 ).getImm (), ImageTy->getOperand (5 ).getImm (),
111
+ ImageTy->getOperand (6 ).getImm (), ImageTy->getOperand (7 ).getImm (),
112
+ ImageTy->getOperand (8 ).getImm ())
113
+ .Val ,
114
+ SpecialTypeKind::STK_SampledImage);
115
+ }
116
+
117
+ inline SpecialTypeDescriptor make_descr_sampler () {
118
+ return std::make_tuple (nullptr , 0U , SpecialTypeKind::STK_Sampler);
119
+ }
120
+
121
+ inline SpecialTypeDescriptor make_descr_pipe (uint8_t AQ) {
122
+ return std::make_tuple (nullptr , AQ, SpecialTypeKind::STK_Pipe);
123
+ }
124
+
125
+ inline SpecialTypeDescriptor make_descr_event () {
126
+ return std::make_tuple (nullptr , 0U , SpecialTypeKind::STK_DeviceEvent);
127
+ }
128
+
129
+ inline SpecialTypeDescriptor make_descr_pointee (const Type *ElementType,
130
+ unsigned AddressSpace) {
131
+ return std::make_tuple (ElementType, AddressSpace,
132
+ SpecialTypeKind::STK_Pointer);
133
+ }
182
134
} // namespace SPIRV
183
135
184
- template <> struct DenseMapInfo <SPIRV::SpecialTypeDescriptor> {
185
- static inline SPIRV::SpecialTypeDescriptor getEmptyKey () {
186
- return SPIRV::SpecialTypeDescriptor (
187
- SPIRV::SpecialTypeDescriptor::STK_Empty);
188
- }
189
- static inline SPIRV::SpecialTypeDescriptor getTombstoneKey () {
190
- return SPIRV::SpecialTypeDescriptor (SPIRV::SpecialTypeDescriptor::STK_Last);
191
- }
192
- static unsigned getHashValue (SPIRV::SpecialTypeDescriptor Val) {
193
- return Val.getHash ();
194
- }
195
- static bool isEqual (SPIRV::SpecialTypeDescriptor LHS,
196
- SPIRV::SpecialTypeDescriptor RHS) {
197
- return getHashValue (LHS) == getHashValue (RHS);
198
- }
199
- };
200
-
201
136
template <typename KeyTy> class SPIRVDuplicatesTrackerBase {
202
137
public:
203
138
// NOTE: using MapVector instead of DenseMap helps getting everything ordered
@@ -283,16 +218,13 @@ class SPIRVGeneralDuplicatesTracker {
283
218
MachineModuleInfo *MMI);
284
219
285
220
void add (const Type *Ty, const MachineFunction *MF, Register R) {
286
- TT.add (Ty , MF, R);
221
+ TT.add (unifyPtrType (Ty) , MF, R);
287
222
}
288
223
289
224
void add (const Type *PointeeTy, unsigned AddressSpace,
290
225
const MachineFunction *MF, Register R) {
291
- if (isUntypedPointerTy (PointeeTy))
292
- PointeeTy =
293
- TypedPointerType::get (IntegerType::getInt8Ty (PointeeTy->getContext ()),
294
- getPointerAddressSpace (PointeeTy));
295
- ST.add (SPIRV::PointerTypeDescriptor (PointeeTy, AddressSpace), MF, R);
226
+ ST.add (SPIRV::make_descr_pointee (unifyPtrType (PointeeTy), AddressSpace), MF,
227
+ R);
296
228
}
297
229
298
230
void add (const Constant *C, const MachineFunction *MF, Register R) {
@@ -321,16 +253,13 @@ class SPIRVGeneralDuplicatesTracker {
321
253
}
322
254
323
255
Register find (const Type *Ty, const MachineFunction *MF) {
324
- return TT.find (const_cast <Type *> (Ty), MF);
256
+ return TT.find (unifyPtrType (Ty), MF);
325
257
}
326
258
327
259
Register find (const Type *PointeeTy, unsigned AddressSpace,
328
260
const MachineFunction *MF) {
329
- if (isUntypedPointerTy (PointeeTy))
330
- PointeeTy =
331
- TypedPointerType::get (IntegerType::getInt8Ty (PointeeTy->getContext ()),
332
- getPointerAddressSpace (PointeeTy));
333
- return ST.find (SPIRV::PointerTypeDescriptor (PointeeTy, AddressSpace), MF);
261
+ return ST.find (
262
+ SPIRV::make_descr_pointee (unifyPtrType (PointeeTy), AddressSpace), MF);
334
263
}
335
264
336
265
Register find (const Constant *C, const MachineFunction *MF) {
0 commit comments