@@ -257,6 +257,10 @@ class SPIRVInstructionSelector : public InstructionSelector {
257257 bool selectSpvThreadId (Register ResVReg, const SPIRVType *ResType,
258258 MachineInstr &I) const ;
259259
260+ bool selectWaveNOpInst (Register ResVReg, const SPIRVType *ResType,
261+ MachineInstr &I,
262+ unsigned Opcode,
263+ unsigned OperandCount) const ;
260264 bool selectWaveActiveAnyTrue (Register ResVReg, const SPIRVType *ResType,
261265 MachineInstr &I) const ;
262266
@@ -1952,41 +1956,47 @@ bool SPIRVInstructionSelector::selectSign(Register ResVReg,
19521956 return Result;
19531957}
19541958
1955- bool SPIRVInstructionSelector::selectWaveActiveAnyTrue (Register ResVReg,
1959+ bool SPIRVInstructionSelector::selectWaveNOpInst (Register ResVReg,
19561960 const SPIRVType *ResType,
1957- MachineInstr &I) const {
1958- assert (I.getNumOperands () == 3 );
1959- assert (I.getOperand (2 ).isReg ());
1961+ MachineInstr &I,
1962+ unsigned Opcode,
1963+ unsigned OperandCount) const {
1964+ assert (I.getNumOperands () == OperandCount);
1965+ for (unsigned j = 2 ; j < OperandCount; j++) {
1966+ assert (I.getOperand (j).isReg ());
1967+ }
19601968
19611969 MachineBasicBlock &BB = *I.getParent ();
19621970 SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType (32 , I, TII);
19631971
1964- return BuildMI (BB, I, I.getDebugLoc (), TII.get (SPIRV::OpGroupNonUniformAny ))
1972+ auto BMI = BuildMI (BB, I, I.getDebugLoc (), TII.get (Opcode ))
19651973 .addDef (ResVReg)
19661974 .addUse (GR.getSPIRVTypeID (ResType))
1967- .addUse (GR.getOrCreateConstInt (SPIRV::Scope::Subgroup, I, IntTy, TII))
1968- .addUse (I.getOperand (2 ).getReg ())
1969- .constrainAllUses (TII, TRI, RBI);
1975+ .addUse (GR.getOrCreateConstInt (SPIRV::Scope::Subgroup, I, IntTy, TII));
1976+
1977+ for (unsigned j = 2 ; j < OperandCount; j++) {
1978+ BMI.addUse (I.getOperand (j).getReg ());
1979+ }
1980+
1981+ return BMI.constrainAllUses (TII, TRI, RBI);
1982+ }
1983+
1984+
1985+ bool SPIRVInstructionSelector::selectWaveActiveAnyTrue (Register ResVReg,
1986+ const SPIRVType *ResType,
1987+ MachineInstr &I) const {
1988+ return selectWaveNOpInst (ResVReg, ResType, I, SPIRV::OpGroupNonUniformAny, 3 );
19701989}
19711990
19721991bool SPIRVInstructionSelector::selectWaveActiveCountBits (
19731992 Register ResVReg, const SPIRVType *ResType, MachineInstr &I) const {
1974- assert (I.getNumOperands () == 3 );
1975- assert (I.getOperand (2 ).isReg ());
1976- MachineBasicBlock &BB = *I.getParent ();
19771993
19781994 SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType (32 , I, TII);
19791995 SPIRVType *BallotType = GR.getOrCreateSPIRVVectorType (IntTy, 4 , I, TII);
19801996 Register BallotReg = MRI->createVirtualRegister (GR.getRegClass (BallotType));
1997+ bool Result = selectWaveNOpInst (BallotReg, BallotType, I, SPIRV::OpGroupNonUniformBallot, 3 );
19811998
1982- bool Result =
1983- BuildMI (BB, I, I.getDebugLoc (), TII.get (SPIRV::OpGroupNonUniformBallot))
1984- .addDef (BallotReg)
1985- .addUse (GR.getSPIRVTypeID (BallotType))
1986- .addUse (GR.getOrCreateConstInt (SPIRV::Scope::Subgroup, I, IntTy, TII))
1987- .addUse (I.getOperand (2 ).getReg ())
1988- .constrainAllUses (TII, TRI, RBI);
1989-
1999+ MachineBasicBlock &BB = *I.getParent ();
19902000 Result &=
19912001 BuildMI (BB, I, I.getDebugLoc (),
19922002 TII.get (SPIRV::OpGroupNonUniformBallotBitCount))
@@ -2003,22 +2013,7 @@ bool SPIRVInstructionSelector::selectWaveActiveCountBits(
20032013bool SPIRVInstructionSelector::selectWaveReadLaneAt (Register ResVReg,
20042014 const SPIRVType *ResType,
20052015 MachineInstr &I) const {
2006- assert (I.getNumOperands () == 4 );
2007- assert (I.getOperand (2 ).isReg ());
2008- assert (I.getOperand (3 ).isReg ());
2009- MachineBasicBlock &BB = *I.getParent ();
2010-
2011- // IntTy is used to define the execution scope, set to 3 to denote a
2012- // cross-lane interaction equivalent to a SPIR-V subgroup.
2013- SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType (32 , I, TII);
2014- return BuildMI (BB, I, I.getDebugLoc (),
2015- TII.get (SPIRV::OpGroupNonUniformShuffle))
2016- .addDef (ResVReg)
2017- .addUse (GR.getSPIRVTypeID (ResType))
2018- .addUse (GR.getOrCreateConstInt (SPIRV::Scope::Subgroup, I, IntTy, TII))
2019- .addUse (I.getOperand (2 ).getReg ())
2020- .addUse (I.getOperand (3 ).getReg ())
2021- .constrainAllUses (TII, TRI, RBI);
2016+ return selectWaveNOpInst (ResVReg, ResType, I, SPIRV::OpGroupNonUniformShuffle, 4 );
20222017}
20232018
20242019bool SPIRVInstructionSelector::selectBitreverse (Register ResVReg,
0 commit comments