@@ -6081,6 +6081,28 @@ static unsigned getBufferOffsetForMMO(SDValue VOffset,
6081
6081
cast<ConstantSDNode>(Offset)->getSExtValue ();
6082
6082
}
6083
6083
6084
+ static unsigned getDSShaderTypeValue (const MachineFunction &MF) {
6085
+ switch (MF.getFunction ().getCallingConv ()) {
6086
+ case CallingConv::AMDGPU_PS:
6087
+ return 1 ;
6088
+ case CallingConv::AMDGPU_VS:
6089
+ return 2 ;
6090
+ case CallingConv::AMDGPU_GS:
6091
+ return 3 ;
6092
+ case CallingConv::AMDGPU_HS:
6093
+ case CallingConv::AMDGPU_LS:
6094
+ case CallingConv::AMDGPU_ES:
6095
+ report_fatal_error (" ds_ordered_count unsupported for this calling conv" );
6096
+ case CallingConv::AMDGPU_CS:
6097
+ case CallingConv::AMDGPU_KERNEL:
6098
+ case CallingConv::C:
6099
+ case CallingConv::Fast:
6100
+ default :
6101
+ // Assume other calling conventions are various compute callable functions
6102
+ return 0 ;
6103
+ }
6104
+ }
6105
+
6084
6106
SDValue SITargetLowering::LowerINTRINSIC_W_CHAIN (SDValue Op,
6085
6107
SelectionDAG &DAG) const {
6086
6108
unsigned IntrID = cast<ConstantSDNode>(Op.getOperand (1 ))->getZExtValue ();
@@ -6096,8 +6118,6 @@ SDValue SITargetLowering::LowerINTRINSIC_W_CHAIN(SDValue Op,
6096
6118
unsigned IndexOperand = M->getConstantOperandVal (7 );
6097
6119
unsigned WaveRelease = M->getConstantOperandVal (8 );
6098
6120
unsigned WaveDone = M->getConstantOperandVal (9 );
6099
- unsigned ShaderType;
6100
- unsigned Instruction;
6101
6121
6102
6122
unsigned OrderedCountIndex = IndexOperand & 0x3f ;
6103
6123
IndexOperand &= ~0x3f ;
@@ -6116,36 +6136,11 @@ SDValue SITargetLowering::LowerINTRINSIC_W_CHAIN(SDValue Op,
6116
6136
if (IndexOperand)
6117
6137
report_fatal_error (" ds_ordered_count: bad index operand" );
6118
6138
6119
- switch (IntrID) {
6120
- case Intrinsic::amdgcn_ds_ordered_add:
6121
- Instruction = 0 ;
6122
- break ;
6123
- case Intrinsic::amdgcn_ds_ordered_swap:
6124
- Instruction = 1 ;
6125
- break ;
6126
- }
6127
-
6128
6139
if (WaveDone && !WaveRelease)
6129
6140
report_fatal_error (" ds_ordered_count: wave_done requires wave_release" );
6130
6141
6131
- switch (DAG.getMachineFunction ().getFunction ().getCallingConv ()) {
6132
- case CallingConv::AMDGPU_CS:
6133
- case CallingConv::AMDGPU_KERNEL:
6134
- ShaderType = 0 ;
6135
- break ;
6136
- case CallingConv::AMDGPU_PS:
6137
- ShaderType = 1 ;
6138
- break ;
6139
- case CallingConv::AMDGPU_VS:
6140
- ShaderType = 2 ;
6141
- break ;
6142
- case CallingConv::AMDGPU_GS:
6143
- ShaderType = 3 ;
6144
- break ;
6145
- default :
6146
- report_fatal_error (" ds_ordered_count unsupported for this calling conv" );
6147
- }
6148
-
6142
+ unsigned Instruction = IntrID == Intrinsic::amdgcn_ds_ordered_add ? 0 : 1 ;
6143
+ unsigned ShaderType = getDSShaderTypeValue (DAG.getMachineFunction ());
6149
6144
unsigned Offset0 = OrderedCountIndex << 2 ;
6150
6145
unsigned Offset1 = WaveRelease | (WaveDone << 1 ) | (ShaderType << 2 ) |
6151
6146
(Instruction << 4 );
0 commit comments