forked from microsoft/DirectXShaderCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHLOperations.h
More file actions
487 lines (407 loc) · 14.5 KB
/
HLOperations.h
File metadata and controls
487 lines (407 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
///////////////////////////////////////////////////////////////////////////////
// //
// HLOperations.h //
// Copyright (C) Microsoft Corporation. All rights reserved. //
// This file is distributed under the University of Illinois Open Source //
// License. See LICENSE.TXT for details. //
// //
// Implentation of High Level DXIL operations. //
// //
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "llvm/IR/IRBuilder.h"
#include <string>
namespace llvm {
class Argument;
template <typename T> class ArrayRef;
class AttributeSet;
class CallInst;
class Function;
class FunctionType;
class Module;
class StringRef;
class Type;
class Value;
} // namespace llvm
namespace hlsl {
enum class HLOpcodeGroup {
NotHL,
HLExtIntrinsic,
HLIntrinsic,
HLCast,
HLInit,
HLBinOp,
HLUnOp,
HLSubscript,
HLMatLoadStore,
HLSelect,
HLCreateHandle,
// FIXME: Change the way these groups are being proliferated/used for each
// new generated op.
// Suggestion: Add an opcode and reuse CreateHandle/AnnotateHandle groups, and
// add an IndexHandle group.
HLCreateNodeOutputHandle,
HLIndexNodeHandle,
HLCreateNodeInputRecordHandle,
HLAnnotateHandle,
HLAnnotateNodeHandle,
HLAnnotateNodeRecordHandle,
NumOfHLOps
};
enum class HLBinaryOpcode {
Invalid,
Mul,
Div,
Rem,
Add,
Sub,
Shl,
Shr,
LT,
GT,
LE,
GE,
EQ,
NE,
And,
Xor,
Or,
LAnd,
LOr,
UDiv,
URem,
UShr,
ULT,
UGT,
ULE,
UGE,
NumOfBO,
};
enum class HLUnaryOpcode {
Invalid,
PostInc,
PostDec,
PreInc,
PreDec,
Plus,
Minus,
Not,
LNot,
NumOfUO,
};
enum class HLSubscriptOpcode {
DefaultSubscript,
ColMatSubscript,
RowMatSubscript,
ColMatElement,
RowMatElement,
DoubleSubscript,
CBufferSubscript,
VectorSubscript, // Only for bool vector, other vector type will use GEP
// directly.
};
enum class HLCastOpcode {
DefaultCast,
UnsignedUnsignedCast,
FromUnsignedCast,
ToUnsignedCast,
ColMatrixToVecCast,
RowMatrixToVecCast,
ColMatrixToRowMatrix,
RowMatrixToColMatrix,
HandleToResCast,
HandleToNodeOutputCast,
NodeOutputToHandleCast,
HandleToNodeRecordCast,
NodeRecordToHandleCast,
};
enum class HLMatLoadStoreOpcode {
ColMatLoad,
ColMatStore,
RowMatLoad,
RowMatStore,
};
extern const char *const HLPrefix;
HLOpcodeGroup GetHLOpcodeGroup(llvm::Function *F);
HLOpcodeGroup GetHLOpcodeGroupByName(const llvm::Function *F);
llvm::StringRef GetHLOpcodeGroupNameByAttr(llvm::Function *F);
llvm::StringRef GetHLLowerStrategy(llvm::Function *F);
unsigned GetHLOpcode(const llvm::CallInst *CI);
unsigned GetRowMajorOpcode(HLOpcodeGroup group, unsigned opcode);
void SetHLLowerStrategy(llvm::Function *F, llvm::StringRef S);
void SetHLWaveSensitive(llvm::Function *F);
bool IsHLWaveSensitive(llvm::Function *F);
// For intrinsic opcode.
unsigned GetUnsignedOpcode(unsigned opcode);
// For HLBinaryOpcode.
bool HasUnsignedOpcode(HLBinaryOpcode opcode);
HLBinaryOpcode GetUnsignedOpcode(HLBinaryOpcode opcode);
llvm::StringRef GetHLOpcodeGroupName(HLOpcodeGroup op);
namespace HLOperandIndex {
// Opcode parameter.
const unsigned kOpcodeIdx = 0;
// Used to initialize values that have no valid index in the HL overload.
const unsigned kInvalidIdx = UINT32_MAX;
// Matrix store.
const unsigned kMatStoreDstPtrOpIdx = 1;
const unsigned kMatStoreValOpIdx = 2;
// Matrix load.
const unsigned kMatLoadPtrOpIdx = 1;
// Normal subscipts.
const unsigned kSubscriptObjectOpIdx = 1;
const unsigned kSubscriptIndexOpIdx = 2;
// Double subscripts.
const unsigned kDoubleSubscriptMipLevelOpIdx = 3;
// Matrix subscripts.
const unsigned kMatSubscriptMatOpIdx = 1;
const unsigned kMatSubscriptSubOpIdx = 2;
// Matrix init.
const unsigned kMatArrayInitMatOpIdx = 1;
const unsigned kMatArrayInitFirstArgOpIdx = 2;
// Array Init.
const unsigned kArrayInitPtrOpIdx = 1;
const unsigned kArrayInitFirstArgOpIdx = 2;
// Normal Init.
const unsigned kInitFirstArgOpIdx = 1;
// Unary operators.
const unsigned kUnaryOpSrc0Idx = 1;
// Binary operators.
const unsigned kBinaryOpSrc0Idx = 1;
const unsigned kBinaryOpSrc1Idx = 2;
// Trinary operators.
const unsigned kTrinaryOpSrc0Idx = 1;
const unsigned kTrinaryOpSrc1Idx = 2;
const unsigned kTrinaryOpSrc2Idx = 3;
// Interlocked.
const unsigned kInterlockedDestOpIndex = 1;
const unsigned kInterlockedValueOpIndex = 2;
const unsigned kInterlockedOriginalValueOpIndex = 3;
// Interlocked method
const unsigned kInterlockedMethodValueOpIndex = 3;
// InterlockedCompareExchange.
const unsigned kInterlockedCmpDestOpIndex = 1;
const unsigned kInterlockedCmpCompareValueOpIndex = 2;
const unsigned kInterlockedCmpValueOpIndex = 3;
const unsigned kInterlockedCmpOriginalValueOpIndex = 4;
// Lerp.
const unsigned kLerpOpXIdx = 1;
const unsigned kLerpOpYIdx = 2;
const unsigned kLerpOpSIdx = 3;
// ProcessTessFactorIsoline.
const unsigned kProcessTessFactorRawDetailFactor = 1;
const unsigned kProcessTessFactorRawDensityFactor = 2;
const unsigned kProcessTessFactorRoundedDetailFactor = 3;
const unsigned kProcessTessFactorRoundedDensityFactor = 4;
// ProcessTessFactor.
const unsigned kProcessTessFactorRawEdgeFactor = 1;
const unsigned kProcessTessFactorInsideScale = 2;
const unsigned kProcessTessFactorRoundedEdgeFactor = 3;
const unsigned kProcessTessFactorRoundedInsideFactor = 4;
const unsigned kProcessTessFactorUnRoundedInsideFactor = 5;
// Reflect.
const unsigned kReflectOpIIdx = 1;
const unsigned kReflectOpNIdx = 2;
// Refract
const unsigned kRefractOpIIdx = 1;
const unsigned kRefractOpNIdx = 2;
const unsigned kRefractOpEtaIdx = 3;
// SmoothStep.
const unsigned kSmoothStepOpMinIdx = 1;
const unsigned kSmoothStepOpMaxIdx = 2;
const unsigned kSmoothStepOpXIdx = 3;
// Clamp
const unsigned kClampOpXIdx = 1;
const unsigned kClampOpMinIdx = 2;
const unsigned kClampOpMaxIdx = 3;
// Object functions.
const unsigned kHandleOpIdx = 1;
// Store.
const unsigned kStoreOffsetOpIdx = 2;
const unsigned kStoreValOpIdx = 3;
// Load.
const unsigned kBufLoadAddrOpIdx = 2;
const unsigned kBufLoadStatusOpIdx = 3;
const unsigned kRWTexLoadStatusOpIdx = 3;
const unsigned kTexLoadOffsetOpIdx = 3;
const unsigned kTexLoadStatusOpIdx = 4;
// Load for Texture2DMS
const unsigned kTex2DMSLoadSampleIdxOpIdx = 3;
const unsigned kTex2DMSLoadOffsetOpIdx = 4;
const unsigned kTex2DMSLoadStatusOpIdx = 5;
// mips.Operator.
const unsigned kMipLoadAddrOpIdx = 3;
const unsigned kMipLoadOffsetOpIdx = 4;
const unsigned kMipLoadStatusOpIdx = 5;
// Sample.
const unsigned kSampleSamplerArgIndex = 2;
const unsigned kSampleCoordArgIndex = 3;
const unsigned kSampleOffsetArgIndex = 4;
const unsigned kSampleClampArgIndex = 5;
const unsigned kSampleStatusArgIndex = 6;
// SampleG.
const unsigned kSampleGDDXArgIndex = 4;
const unsigned kSampleGDDYArgIndex = 5;
const unsigned kSampleGOffsetArgIndex = 6;
const unsigned kSampleGClampArgIndex = 7;
const unsigned kSampleGStatusArgIndex = 8;
// SampleCmp.
const unsigned kSampleCmpCmpValArgIndex = 4;
const unsigned kSampleCmpOffsetArgIndex = 5;
const unsigned kSampleCmpClampArgIndex = 6;
const unsigned kSampleCmpStatusArgIndex = 7;
// SampleCmpBias.
const unsigned kSampleCmpBCmpValArgIndex = 4;
const unsigned kSampleCmpBBiasArgIndex = 5;
const unsigned kSampleCmpBOffsetArgIndex = 6;
const unsigned kSampleCmpBClampArgIndex = 7;
const unsigned kSampleCmpBStatusArgIndex = 8;
// SampleCmpGrad.
const unsigned kSampleCmpGCmpValArgIndex = 4;
const unsigned kSampleCmpGDDXArgIndex = 5;
const unsigned kSampleCmpGDDYArgIndex = 6;
const unsigned kSampleCmpGOffsetArgIndex = 7;
const unsigned kSampleCmpGClampArgIndex = 8;
const unsigned kSampleCmpGStatusArgIndex = 9;
// SampleBias.
const unsigned kSampleBBiasArgIndex = 4;
const unsigned kSampleBOffsetArgIndex = 5;
const unsigned kSampleBClampArgIndex = 6;
const unsigned kSampleBStatusArgIndex = 7;
// SampleLevel.
const unsigned kSampleLLevelArgIndex = 4;
const unsigned kSampleLOffsetArgIndex = 5;
const unsigned kSampleLStatusArgIndex = 6;
// SampleCmpLevel
// the rest are the same as SampleCmp
const unsigned kSampleCmpLLevelArgIndex = 5;
const unsigned kSampleCmpLOffsetArgIndex = 6;
// SampleCmpLevelZero.
const unsigned kSampleCmpLZCmpValArgIndex = 4;
const unsigned kSampleCmpLZOffsetArgIndex = 5;
const unsigned kSampleCmpLZStatusArgIndex = 6;
// Gather.
const unsigned kGatherSamplerArgIndex = 2;
const unsigned kGatherCoordArgIndex = 3;
const unsigned kGatherOffsetArgIndex = 4;
const unsigned kGatherStatusArgIndex = 5;
const unsigned kGatherSampleOffsetArgIndex = 5;
const unsigned kGatherStatusWithSampleOffsetArgIndex = 8;
const unsigned kGatherCubeStatusArgIndex = 4;
// GatherCmp.
const unsigned kGatherCmpCmpValArgIndex = 4;
const unsigned kGatherCmpOffsetArgIndex = 5;
const unsigned kGatherCmpStatusArgIndex = 6;
const unsigned kGatherCmpSampleOffsetArgIndex = 6;
const unsigned kGatherCmpStatusWithSampleOffsetArgIndex = 9;
const unsigned kGatherCmpCubeStatusArgIndex = 5;
// WriteSamplerFeedback.
const unsigned kWriteSamplerFeedbackSampledArgIndex = 2;
const unsigned kWriteSamplerFeedbackSamplerArgIndex = 3;
const unsigned kWriteSamplerFeedbackCoordArgIndex = 4;
const unsigned kWriteSamplerFeedbackBias_BiasArgIndex = 5;
const unsigned kWriteSamplerFeedbackLevel_LodArgIndex = 5;
const unsigned kWriteSamplerFeedbackGrad_DdxArgIndex = 5;
const unsigned kWriteSamplerFeedbackGrad_DdyArgIndex = 6;
const unsigned kWriteSamplerFeedback_ClampArgIndex = 5;
const unsigned kWriteSamplerFeedbackBias_ClampArgIndex = 6;
const unsigned kWriteSamplerFeedbackGrad_ClampArgIndex = 7;
// StreamAppend.
const unsigned kStreamAppendStreamOpIndex = 1;
const unsigned kStreamAppendDataOpIndex = 2;
// Append.
const unsigned kAppendValOpIndex = 2;
// Interlocked.
const unsigned kObjectInterlockedDestOpIndex = 2;
const unsigned kObjectInterlockedValueOpIndex = 3;
const unsigned kObjectInterlockedOriginalValueOpIndex = 4;
// InterlockedCompareExchange.
const unsigned kObjectInterlockedCmpDestOpIndex = 2;
const unsigned kObjectInterlockedCmpCompareValueOpIndex = 3;
const unsigned kObjectInterlockedCmpValueOpIndex = 4;
const unsigned kObjectInterlockedCmpOriginalValueOpIndex = 5;
// GetSamplePosition.
const unsigned kGetSamplePositionSampleIdxOpIndex = 2;
// GetDimensions.
const unsigned kGetDimensionsMipLevelOpIndex = 2;
const unsigned kGetDimensionsMipWidthOpIndex = 3;
const unsigned kGetDimensionsNoMipWidthOpIndex = 2;
// WaveAllEqual.
const unsigned kWaveAllEqualValueOpIdx = 1;
// CreateHandle.
const unsigned kCreateHandleResourceOpIdx = 1;
const unsigned kCreateHandleIndexOpIdx = 2; // Only for array of cbuffer.
// Annotate(Node)(Record)Handle.
const unsigned kAnnotateHandleResourcePropertiesOpIdx = 2;
const unsigned kAnnotateHandleResourceTypeOpIdx = 3;
// TraceRay.
const unsigned kTraceRayRayDescOpIdx = 7;
const unsigned kTraceRayPayLoadOpIdx = 8;
// AllocateRayQuery
const unsigned kAllocateRayQueryRayFlagsIdx = 1;
const unsigned kAllocateRayQueryRayQueryFlagsIdx = 2;
// CallShader.
const unsigned kCallShaderPayloadOpIdx = 2;
// TraceRayInline.
const unsigned kTraceRayInlineRayDescOpIdx = 5;
// ReportIntersection.
const unsigned kReportIntersectionAttributeOpIdx = 3;
// DispatchMesh
const unsigned kDispatchMeshOpThreadX = 1;
const unsigned kDispatchMeshOpThreadY = 2;
const unsigned kDispatchMeshOpThreadZ = 3;
const unsigned kDispatchMeshOpPayload = 4;
// Work Graph
const unsigned kIncrementOutputCountCountIdx = 2;
const unsigned kBarrierMemoryTypeFlagsOpIdx = 1;
const unsigned kBarrierSemanticFlagsOpIdx = 2;
// Node Handles
const unsigned kAllocateRecordNumRecordsIdx = 2;
const unsigned kNodeOutputMetadataIDIdx = 1;
const unsigned kIndexNodeHandleArrayIDIdx = 2;
const unsigned kNodeInputRecordMetadataIDIdx = 1;
const unsigned kNodeHandleToResCastOpIdx = 1;
const unsigned kAnnotateNodeHandleNodePropIdx = 2;
const unsigned kAnnotateNodeRecordHandleNodeRecordPropIdx = 2;
// HitObject::MakeMiss
const unsigned kHitObjectMakeMiss_NumOp = 8;
const unsigned kHitObjectMakeMissRayDescOpIdx = 4;
// HitObject::TraceRay
const unsigned kHitObjectTraceRay_RayDescOpIdx = 8;
const unsigned kHitObjectTraceRay_NumOp = 10;
// HitObject::FromRayQuery
const unsigned kHitObjectFromRayQuery_WithAttrs_AttributeOpIdx = 4;
const unsigned kHitObjectFromRayQuery_WithAttrs_NumOp = 5;
} // namespace HLOperandIndex
llvm::Function *GetOrCreateHLFunction(llvm::Module &M,
llvm::FunctionType *funcTy,
HLOpcodeGroup group, unsigned opcode);
llvm::Function *GetOrCreateHLFunction(llvm::Module &M,
llvm::FunctionType *funcTy,
HLOpcodeGroup group,
llvm::StringRef *groupName,
llvm::StringRef *fnName, unsigned opcode);
llvm::Function *GetOrCreateHLFunction(llvm::Module &M,
llvm::FunctionType *funcTy,
HLOpcodeGroup group, unsigned opcode,
const llvm::AttributeSet &attribs);
llvm::Function *GetOrCreateHLFunction(llvm::Module &M,
llvm::FunctionType *funcTy,
HLOpcodeGroup group,
llvm::StringRef *groupName,
llvm::StringRef *fnName, unsigned opcode,
const llvm::AttributeSet &attribs);
llvm::Function *GetOrCreateHLFunctionWithBody(llvm::Module &M,
llvm::FunctionType *funcTy,
HLOpcodeGroup group,
unsigned opcode,
llvm::StringRef name);
llvm::Value *callHLFunction(llvm::Module &Module, HLOpcodeGroup OpcodeGroup,
unsigned Opcode, llvm::Type *RetTy,
llvm::ArrayRef<llvm::Value *> Args,
const llvm::AttributeSet &attribs,
llvm::IRBuilder<> &Builder);
llvm::Value *callHLFunction(llvm::Module &Module, HLOpcodeGroup OpcodeGroup,
unsigned Opcode, llvm::Type *RetTy,
llvm::ArrayRef<llvm::Value *> Args,
llvm::IRBuilder<> &Builder);
} // namespace hlsl