@@ -263,6 +263,21 @@ static void lowerExpectAssume(IntrinsicInst *II) {
263
263
return ;
264
264
}
265
265
266
+ static bool toSpvOverloadedIntrinsic (IntrinsicInst *II, Intrinsic::ID NewID,
267
+ ArrayRef<unsigned > OpNos) {
268
+ Function *F = nullptr ;
269
+ if (OpNos.empty ()) {
270
+ F = Intrinsic::getDeclaration (II->getModule (), NewID);
271
+ } else {
272
+ SmallVector<Type *, 4 > Tys;
273
+ for (unsigned OpNo : OpNos)
274
+ Tys.push_back (II->getOperand (OpNo)->getType ());
275
+ F = Intrinsic::getDeclaration (II->getModule (), NewID, Tys);
276
+ }
277
+ II->setCalledFunction (F);
278
+ return true ;
279
+ }
280
+
266
281
static void lowerUMulWithOverflow (IntrinsicInst *UMulIntrinsic) {
267
282
// Get a separate function - otherwise, we'd have to rework the CFG of the
268
283
// current one. Then simply replace the intrinsic uses with a call to the new
@@ -290,22 +305,35 @@ bool SPIRVPrepareFunctions::substituteIntrinsicCalls(Function *F) {
290
305
if (!CF || !CF->isIntrinsic ())
291
306
continue ;
292
307
auto *II = cast<IntrinsicInst>(Call);
293
- if (II->getIntrinsicID () == Intrinsic::memset ||
294
- II->getIntrinsicID () == Intrinsic::bswap)
308
+ switch (II->getIntrinsicID ()) {
309
+ case Intrinsic::memset:
310
+ case Intrinsic::bswap:
295
311
Changed |= lowerIntrinsicToFunction (II);
296
- else if (II->getIntrinsicID () == Intrinsic::fshl ||
297
- II->getIntrinsicID () == Intrinsic::fshr) {
312
+ break ;
313
+ case Intrinsic::fshl:
314
+ case Intrinsic::fshr:
298
315
lowerFunnelShifts (II);
299
316
Changed = true ;
300
- } else if (II->getIntrinsicID () == Intrinsic::umul_with_overflow) {
317
+ break ;
318
+ case Intrinsic::umul_with_overflow:
301
319
lowerUMulWithOverflow (II);
302
320
Changed = true ;
303
- } else if (II->getIntrinsicID () == Intrinsic::assume ||
304
- II->getIntrinsicID () == Intrinsic::expect) {
321
+ break ;
322
+ case Intrinsic::assume:
323
+ case Intrinsic::expect: {
305
324
const SPIRVSubtarget &STI = TM.getSubtarget <SPIRVSubtarget>(*F);
306
325
if (STI.canUseExtension (SPIRV::Extension::SPV_KHR_expect_assume))
307
326
lowerExpectAssume (II);
308
327
Changed = true ;
328
+ } break ;
329
+ case Intrinsic::lifetime_start:
330
+ Changed |= toSpvOverloadedIntrinsic (
331
+ II, Intrinsic::SPVIntrinsics::spv_lifetime_start, {1 });
332
+ break ;
333
+ case Intrinsic::lifetime_end:
334
+ Changed |= toSpvOverloadedIntrinsic (
335
+ II, Intrinsic::SPVIntrinsics::spv_lifetime_end, {1 });
336
+ break ;
309
337
}
310
338
}
311
339
}
0 commit comments