Skip to content

Commit 88b2468

Browse files
Firestar99LegNeato
authored andcommitted
add undef_zombie()
1 parent 9a533a3 commit 88b2468

File tree

3 files changed

+46
-78
lines changed

3 files changed

+46
-78
lines changed

crates/rustc_codegen_spirv/src/builder/intrinsics.rs

+10-24
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,10 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
292292
let res3 = self.or(res3, res4);
293293
self.or(res1, res3)
294294
}
295-
other => {
296-
let undef = self.undef(ret_ty);
297-
self.zombie(
298-
undef.def(self),
299-
&format!("bswap not implemented for int width {other}"),
300-
);
301-
undef
302-
}
295+
other => self.undef_zombie(
296+
ret_ty,
297+
&format!("bswap not implemented for int width {other}"),
298+
),
303299
};
304300

305301
// Cast back to the original signed type if necessary
@@ -310,11 +306,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
310306
}
311307
}
312308

313-
sym::compare_bytes => {
314-
let undef = self.undef(ret_ty);
315-
self.zombie(undef.def(self), "memcmp not implemented");
316-
undef
317-
}
309+
sym::compare_bytes => self.undef_zombie(ret_ty, "memcmp not implemented"),
318310

319311
_ => {
320312
// Call the fallback body instead of generating the intrinsic code
@@ -397,12 +389,10 @@ impl Builder<'_, '_> {
397389
.unwrap()
398390
}
399391
_ => {
400-
let undef = self.undef(ty).def(self);
401-
self.zombie(
402-
undef,
392+
return self.undef_zombie(
393+
ty,
403394
&format!("count_ones() on unsupported {ty:?} bit integer type"),
404395
);
405-
undef
406396
}
407397
}
408398
.with_type(u32)
@@ -461,12 +451,10 @@ impl Builder<'_, '_> {
461451
.unwrap()
462452
}
463453
_ => {
464-
let undef = self.undef(ty).def(self);
465-
self.zombie(
466-
undef,
454+
return self.undef_zombie(
455+
ty,
467456
&format!("bit_reverse() on unsupported {ty:?} bit integer type"),
468457
);
469-
undef
470458
}
471459
}
472460
.with_type(ty)
@@ -559,11 +547,9 @@ impl Builder<'_, '_> {
559547
}
560548
}
561549
_ => {
562-
let undef = self.undef(ty).def(self);
563-
self.zombie(undef, &format!(
550+
return self.undef_zombie(ty, &format!(
564551
"count_leading_trailing_zeros() on unsupported {ty:?} bit integer type"
565552
));
566-
undef
567553
}
568554
};
569555

crates/rustc_codegen_spirv/src/builder/libm_intrinsics.rs

+18-54
Original file line numberDiff line numberDiff line change
@@ -261,94 +261,58 @@ impl Builder<'_, '_> {
261261
self.sub(exp, one)
262262
}
263263
LibmIntrinsic::Custom(LibmCustomIntrinsic::Erf) => {
264-
let undef = self.undef(result_type);
265-
self.zombie(undef.def(self), "Erf not supported yet");
266-
undef
264+
self.undef_zombie(result_type, "Erf not supported yet")
267265
}
268266
LibmIntrinsic::Custom(LibmCustomIntrinsic::Erfc) => {
269-
let undef = self.undef(result_type);
270-
self.zombie(undef.def(self), "Erfc not supported yet");
271-
undef
267+
self.undef_zombie(result_type, "Erfc not supported yet")
272268
}
273269
LibmIntrinsic::Custom(LibmCustomIntrinsic::Fdim) => {
274-
let undef = self.undef(result_type);
275-
self.zombie(undef.def(self), "Fdim not supported yet");
276-
undef
270+
self.undef_zombie(result_type, "Fdim not supported yet")
277271
}
278272
LibmIntrinsic::Custom(LibmCustomIntrinsic::Hypot) => {
279-
let undef = self.undef(result_type);
280-
self.zombie(undef.def(self), "Hypot not supported yet");
281-
undef
273+
self.undef_zombie(result_type, "Hypot not supported yet")
282274
}
283275
LibmIntrinsic::Custom(LibmCustomIntrinsic::Ilogb) => {
284-
let undef = self.undef(result_type);
285-
self.zombie(undef.def(self), "Ilogb not supported yet");
286-
undef
276+
self.undef_zombie(result_type, "Ilogb not supported yet")
287277
}
288278
LibmIntrinsic::Custom(LibmCustomIntrinsic::J0) => {
289-
let undef = self.undef(result_type);
290-
self.zombie(undef.def(self), "J0 not supported yet");
291-
undef
279+
self.undef_zombie(result_type, "J0 not supported yet")
292280
}
293281
LibmIntrinsic::Custom(LibmCustomIntrinsic::Y0) => {
294-
let undef = self.undef(result_type);
295-
self.zombie(undef.def(self), "Y0 not supported yet");
296-
undef
282+
self.undef_zombie(result_type, "Y0 not supported yet")
297283
}
298284
LibmIntrinsic::Custom(LibmCustomIntrinsic::J1) => {
299-
let undef = self.undef(result_type);
300-
self.zombie(undef.def(self), "J1 not supported yet");
301-
undef
285+
self.undef_zombie(result_type, "J1 not supported yet")
302286
}
303287
LibmIntrinsic::Custom(LibmCustomIntrinsic::Y1) => {
304-
let undef = self.undef(result_type);
305-
self.zombie(undef.def(self), "Y1 not supported yet");
306-
undef
288+
self.undef_zombie(result_type, "Y1 not supported yet")
307289
}
308290
LibmIntrinsic::Custom(LibmCustomIntrinsic::Jn) => {
309-
let undef = self.undef(result_type);
310-
self.zombie(undef.def(self), "Jn not supported yet");
311-
undef
291+
self.undef_zombie(result_type, "Jn not supported yet")
312292
}
313293
LibmIntrinsic::Custom(LibmCustomIntrinsic::Yn) => {
314-
let undef = self.undef(result_type);
315-
self.zombie(undef.def(self), "Yn not supported yet");
316-
undef
294+
self.undef_zombie(result_type, "Yn not supported yet")
317295
}
318296
LibmIntrinsic::Custom(LibmCustomIntrinsic::Lgamma) => {
319-
let undef = self.undef(result_type);
320-
self.zombie(undef.def(self), "Lgamma not supported yet");
321-
undef
297+
self.undef_zombie(result_type, "Lgamma not supported yet")
322298
}
323299
LibmIntrinsic::Custom(LibmCustomIntrinsic::LgammaR) => {
324-
let undef = self.undef(result_type);
325-
self.zombie(undef.def(self), "LgammaR not supported yet");
326-
undef
300+
self.undef_zombie(result_type, "LgammaR not supported yet")
327301
}
328302
LibmIntrinsic::Custom(LibmCustomIntrinsic::Tgamma) => {
329-
let undef = self.undef(result_type);
330-
self.zombie(undef.def(self), "Tgamma not supported yet");
331-
undef
303+
self.undef_zombie(result_type, "Tgamma not supported yet")
332304
}
333305
LibmIntrinsic::Custom(LibmCustomIntrinsic::NextAfter) => {
334-
let undef = self.undef(result_type);
335-
self.zombie(undef.def(self), "NextAfter not supported yet");
336-
undef
306+
self.undef_zombie(result_type, "NextAfter not supported yet")
337307
}
338308
LibmIntrinsic::Custom(LibmCustomIntrinsic::Remainder) => {
339-
let undef = self.undef(result_type);
340-
self.zombie(undef.def(self), "Remainder not supported yet");
341-
undef
309+
self.undef_zombie(result_type, "Remainder not supported yet")
342310
}
343311
LibmIntrinsic::Custom(LibmCustomIntrinsic::RemQuo) => {
344-
let undef = self.undef(result_type);
345-
self.zombie(undef.def(self), "RemQuo not supported yet");
346-
undef
312+
self.undef_zombie(result_type, "RemQuo not supported yet")
347313
}
348314
LibmIntrinsic::Custom(LibmCustomIntrinsic::Scalbn) => {
349-
let undef = self.undef(result_type);
350-
self.zombie(undef.def(self), "Scalbn not supported yet");
351-
undef
315+
self.undef_zombie(result_type, "Scalbn not supported yet")
352316
}
353317
}
354318
}

crates/rustc_codegen_spirv/src/builder/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6060
}
6161
}
6262

63+
pub fn undef_zombie(&self, word: Word, reason: &str) -> SpirvValue {
64+
if let Some(current_span) = self.current_span {
65+
self.undef_zombie_with_span(word, current_span, reason)
66+
} else {
67+
self.undef_zombie_no_span(word, reason)
68+
}
69+
}
70+
pub fn undef_zombie_with_span(&self, ty: Word, span: Span, reason: &str) -> SpirvValue {
71+
let undef = self.undef(ty);
72+
self.zombie_with_span(undef.def(self), span, reason);
73+
undef
74+
}
75+
pub fn undef_zombie_no_span(&self, ty: Word, reason: &str) -> SpirvValue {
76+
let undef = self.undef(ty);
77+
self.zombie_no_span(undef.def(self), reason);
78+
undef
79+
}
80+
6381
pub fn validate_atomic(&self, ty: Word, to_zombie: Word) {
6482
if !self.i8_i16_atomics_allowed {
6583
match self.lookup_type(ty) {

0 commit comments

Comments
 (0)