21
21
#include " llvm/ADT/ArrayRef.h"
22
22
#include " llvm/ADT/DenseMap.h"
23
23
#include " llvm/ADT/Optional.h"
24
+ #include " llvm/ADT/STLExtras.h"
24
25
#include " llvm/ADT/SmallVector.h"
25
26
#include " llvm/ADT/SparseBitVector.h"
26
27
#include " llvm/CodeGen/MIRYamlMapping.h"
@@ -114,6 +115,123 @@ class AMDGPUGWSResourcePseudoSourceValue final : public AMDGPUPseudoSourceValue
114
115
115
116
namespace yaml {
116
117
118
+ struct SIArgument {
119
+ bool IsRegister;
120
+ union {
121
+ StringValue RegisterName;
122
+ unsigned StackOffset;
123
+ };
124
+ Optional<unsigned > Mask;
125
+
126
+ // Default constructor, which creates a stack argument.
127
+ SIArgument () : IsRegister(false ), StackOffset(0 ) {}
128
+ SIArgument (const SIArgument &Other) {
129
+ IsRegister = Other.IsRegister ;
130
+ if (IsRegister) {
131
+ ::new ((void *)std::addressof (RegisterName))
132
+ StringValue (Other.RegisterName );
133
+ } else
134
+ StackOffset = Other.StackOffset ;
135
+ Mask = Other.Mask ;
136
+ }
137
+ SIArgument &operator =(const SIArgument &Other) {
138
+ IsRegister = Other.IsRegister ;
139
+ if (IsRegister) {
140
+ ::new ((void *)std::addressof (RegisterName))
141
+ StringValue (Other.RegisterName );
142
+ } else
143
+ StackOffset = Other.StackOffset ;
144
+ Mask = Other.Mask ;
145
+ return *this ;
146
+ }
147
+ ~SIArgument () {
148
+ if (IsRegister)
149
+ RegisterName.~StringValue ();
150
+ }
151
+
152
+ // Helper to create a register or stack argument.
153
+ static inline SIArgument createArgument (bool IsReg) {
154
+ if (IsReg)
155
+ return SIArgument (IsReg);
156
+ return SIArgument ();
157
+ }
158
+
159
+ private:
160
+ // Construct a register argument.
161
+ SIArgument (bool ) : IsRegister(true ), RegisterName() {}
162
+ };
163
+
164
+ template <> struct MappingTraits <SIArgument> {
165
+ static void mapping (IO &YamlIO, SIArgument &A) {
166
+ if (YamlIO.outputting ()) {
167
+ if (A.IsRegister )
168
+ YamlIO.mapRequired (" reg" , A.RegisterName );
169
+ else
170
+ YamlIO.mapRequired (" offset" , A.StackOffset );
171
+ } else {
172
+ auto Keys = YamlIO.keys ();
173
+ if (is_contained (Keys, " reg" )) {
174
+ A = SIArgument::createArgument (true );
175
+ YamlIO.mapRequired (" reg" , A.RegisterName );
176
+ } else if (is_contained (Keys, " offset" ))
177
+ YamlIO.mapRequired (" offset" , A.StackOffset );
178
+ else
179
+ YamlIO.setError (" missing required key 'reg' or 'offset'" );
180
+ }
181
+ YamlIO.mapOptional (" mask" , A.Mask );
182
+ }
183
+ static const bool flow = true ;
184
+ };
185
+
186
+ struct SIArgumentInfo {
187
+ Optional<SIArgument> PrivateSegmentBuffer;
188
+ Optional<SIArgument> DispatchPtr;
189
+ Optional<SIArgument> QueuePtr;
190
+ Optional<SIArgument> KernargSegmentPtr;
191
+ Optional<SIArgument> DispatchID;
192
+ Optional<SIArgument> FlatScratchInit;
193
+ Optional<SIArgument> PrivateSegmentSize;
194
+
195
+ Optional<SIArgument> WorkGroupIDX;
196
+ Optional<SIArgument> WorkGroupIDY;
197
+ Optional<SIArgument> WorkGroupIDZ;
198
+ Optional<SIArgument> WorkGroupInfo;
199
+ Optional<SIArgument> PrivateSegmentWaveByteOffset;
200
+
201
+ Optional<SIArgument> ImplicitArgPtr;
202
+ Optional<SIArgument> ImplicitBufferPtr;
203
+
204
+ Optional<SIArgument> WorkItemIDX;
205
+ Optional<SIArgument> WorkItemIDY;
206
+ Optional<SIArgument> WorkItemIDZ;
207
+ };
208
+
209
+ template <> struct MappingTraits <SIArgumentInfo> {
210
+ static void mapping (IO &YamlIO, SIArgumentInfo &AI) {
211
+ YamlIO.mapOptional (" privateSegmentBuffer" , AI.PrivateSegmentBuffer );
212
+ YamlIO.mapOptional (" dispatchPtr" , AI.DispatchPtr );
213
+ YamlIO.mapOptional (" queuePtr" , AI.QueuePtr );
214
+ YamlIO.mapOptional (" kernargSegmentPtr" , AI.KernargSegmentPtr );
215
+ YamlIO.mapOptional (" dispatchID" , AI.DispatchID );
216
+ YamlIO.mapOptional (" flatScratchInit" , AI.FlatScratchInit );
217
+ YamlIO.mapOptional (" privateSegmentSize" , AI.PrivateSegmentSize );
218
+
219
+ YamlIO.mapOptional (" workGroupIDX" , AI.WorkGroupIDX );
220
+ YamlIO.mapOptional (" workGroupIDY" , AI.WorkGroupIDY );
221
+ YamlIO.mapOptional (" workGroupIDZ" , AI.WorkGroupIDZ );
222
+ YamlIO.mapOptional (" workGroupInfo" , AI.WorkGroupInfo );
223
+ YamlIO.mapOptional (" privateSegmentWaveByteOffset" ,
224
+ AI.PrivateSegmentWaveByteOffset );
225
+
226
+ YamlIO.mapOptional (" implicitArgPtr" , AI.ImplicitArgPtr );
227
+ YamlIO.mapOptional (" implicitBufferPtr" , AI.ImplicitBufferPtr );
228
+
229
+ YamlIO.mapOptional (" workItemIDX" , AI.WorkItemIDX );
230
+ YamlIO.mapOptional (" workItemIDY" , AI.WorkItemIDY );
231
+ YamlIO.mapOptional (" workItemIDZ" , AI.WorkItemIDZ );
232
+ }
233
+ };
234
+
117
235
struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
118
236
uint64_t ExplicitKernArgSize = 0 ;
119
237
unsigned MaxKernArgAlign = 0 ;
@@ -128,6 +246,8 @@ struct SIMachineFunctionInfo final : public yaml::MachineFunctionInfo {
128
246
StringValue FrameOffsetReg = " $fp_reg" ;
129
247
StringValue StackPtrOffsetReg = " $sp_reg" ;
130
248
249
+ Optional<SIArgumentInfo> ArgInfo;
250
+
131
251
SIMachineFunctionInfo () = default ;
132
252
SIMachineFunctionInfo (const llvm::SIMachineFunctionInfo &,
133
253
const TargetRegisterInfo &TRI);
@@ -154,6 +274,7 @@ template <> struct MappingTraits<SIMachineFunctionInfo> {
154
274
StringValue (" $fp_reg" ));
155
275
YamlIO.mapOptional (" stackPtrOffsetReg" , MFI.StackPtrOffsetReg ,
156
276
StringValue (" $sp_reg" ));
277
+ YamlIO.mapOptional (" argumentInfo" , MFI.ArgInfo );
157
278
}
158
279
};
159
280
0 commit comments