@@ -175,6 +175,9 @@ class SPIRVInstructionSelector : public InstructionSelector {
175
175
bool selectFmix (Register ResVReg, const SPIRVType *ResType,
176
176
MachineInstr &I) const ;
177
177
178
+ bool selectLength (Register ResVReg, const SPIRVType *ResType,
179
+ MachineInstr &I) const ;
180
+
178
181
bool selectFrac (Register ResVReg, const SPIRVType *ResType,
179
182
MachineInstr &I) const ;
180
183
@@ -1372,6 +1375,23 @@ bool SPIRVInstructionSelector::selectFmix(Register ResVReg,
1372
1375
.constrainAllUses (TII, TRI, RBI);
1373
1376
}
1374
1377
1378
+ bool SPIRVInstructionSelector::selectLength (Register ResVReg,
1379
+ const SPIRVType *ResType,
1380
+ MachineInstr &I) const {
1381
+
1382
+ assert (I.getNumOperands () == 3 );
1383
+ assert (I.getOperand (2 ).isReg ());
1384
+ MachineBasicBlock &BB = *I.getParent ();
1385
+
1386
+ return BuildMI (BB, I, I.getDebugLoc (), TII.get (SPIRV::OpExtInst))
1387
+ .addDef (ResVReg)
1388
+ .addUse (GR.getSPIRVTypeID (ResType))
1389
+ .addImm (static_cast <uint32_t >(SPIRV::InstructionSet::GLSL_std_450))
1390
+ .addImm (GL::Length)
1391
+ .addUse (I.getOperand (2 ).getReg ())
1392
+ .constrainAllUses (TII, TRI, RBI);
1393
+ }
1394
+
1375
1395
bool SPIRVInstructionSelector::selectFrac (Register ResVReg,
1376
1396
const SPIRVType *ResType,
1377
1397
MachineInstr &I) const {
@@ -2118,6 +2138,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
2118
2138
return selectAny (ResVReg, ResType, I);
2119
2139
case Intrinsic::spv_lerp:
2120
2140
return selectFmix (ResVReg, ResType, I);
2141
+ case Intrinsic::spv_length:
2142
+ return selectLength (ResVReg, ResType, I);
2121
2143
case Intrinsic::spv_frac:
2122
2144
return selectFrac (ResVReg, ResType, I);
2123
2145
case Intrinsic::spv_rsqrt:
0 commit comments