Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asm: implicit label after return or abort terminator #718

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::builder_spirv::{BuilderCursor, SpirvValue};
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use rspirv::dr;
use rspirv::grammar::{LogicalOperand, OperandKind, OperandQuantifier};
use rspirv::grammar::{reflect, LogicalOperand, OperandKind, OperandQuantifier};
use rspirv::spirv::{
FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags, SelectionControl, StorageClass, Word,
Expand Down Expand Up @@ -70,8 +70,13 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> {
options: InlineAsmOptions,
_line_spans: &[Span],
) {
if !options.is_empty() {
self.err(&format!("asm flags not supported: {:?}", options));
const SUPPORTED_OPTIONS: InlineAsmOptions = InlineAsmOptions::NORETURN;
let unsupported_options = options & !SUPPORTED_OPTIONS;
if !unsupported_options.is_empty() {
self.err(&format!(
"asm flags not supported: {:?}",
unsupported_options
));
}
// vec of lines, and each line is vec of tokens
let mut tokens = vec![vec![]];
Expand Down Expand Up @@ -328,10 +333,24 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
}
return;
}
_ => {

op => {
self.emit()
.insert_into_block(dr::InsertPoint::End, inst)
.unwrap();

// Return or abort terminators will also end the current block and start a new one.
// The new block is transparent to the actual builder cursor.
if reflect::is_return_or_abort(op) {
let label = self.emit().id();
self.emit()
.insert_into_block(
dr::InsertPoint::End,
dr::Instruction::new(Op::Label, None, Some(label), vec![]),
)
.unwrap();
}

return;
}
};
Expand Down
5 changes: 1 addition & 4 deletions crates/spirv-std/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,5 @@ pub unsafe fn vector_insert_dynamic<T: Scalar, V: Vector<T, N>, const N: usize>(
#[doc(alias = "OpKill", alias = "discard")]
#[allow(clippy::empty_loop)]
pub fn kill() -> ! {
unsafe {
asm!("OpKill", "%unused = OpLabel");
}
loop {}
unsafe { asm!("OpKill", options(noreturn)) }
}
6 changes: 2 additions & 4 deletions crates/spirv-std/src/arch/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ pub unsafe fn report_intersection(hit: f32, hit_kind: u32) -> bool {
#[inline]
#[allow(clippy::empty_loop)]
pub unsafe fn ignore_intersection() -> ! {
asm!("OpIgnoreIntersectionKHR", "%unused = OpLabel");
loop {}
asm!("OpIgnoreIntersectionKHR", options(noreturn));
}

/// Terminates the invocation that executes it, stops the ray traversal, accepts
Expand All @@ -57,8 +56,7 @@ pub unsafe fn ignore_intersection() -> ! {
#[inline]
#[allow(clippy::empty_loop)]
pub unsafe fn terminate_ray() -> ! {
asm!("OpTerminateRayKHR", "%unused = OpLabel");
loop {}
asm!("OpTerminateRayKHR", options(noreturn));
}

/// Invoke a callable shader.
Expand Down
2 changes: 1 addition & 1 deletion crates/spirv-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub use glam;
#[cfg(all(not(test), target_arch = "spirv"))]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo<'_>) -> ! {
loop {}
unsafe { asm!("", options(noreturn)) }
}

#[cfg(all(not(test), target_arch = "spirv"))]
Expand Down
6 changes: 2 additions & 4 deletions crates/spirv-std/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ impl AccelerationStructure {
"%ret = OpTypeAccelerationStructureKHR",
"%result = OpConvertUToAccelerationStructureKHR %ret {id}",
"OpReturnValue %result",
"%blah = OpLabel",
id = in(reg) id,
options(noreturn)
}
loop {}
}

/// Converts a vector of two 32 bit integers into an [`AccelerationStructure`].
Expand All @@ -47,10 +46,9 @@ impl AccelerationStructure {
"%id = OpLoad _ {id}",
"%result = OpConvertUToAccelerationStructureKHR %ret %id",
"OpReturnValue %result",
"%blah = OpLabel",
id = in(reg) &id,
options(noreturn),
}
loop {}
}

#[spirv_std_macros::gpu_only]
Expand Down
6 changes: 2 additions & 4 deletions crates/spirv-std/src/runtime_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ impl<T> RuntimeArray<T> {
asm! {
"%result = OpAccessChain _ {arr} {index}",
"OpReturnValue %result",
"%unused = OpLabel",
arr = in(reg) self,
index = in(reg) index,
options(noreturn),
}
loop {}
}

#[spirv_std_macros::gpu_only]
Expand All @@ -30,10 +29,9 @@ impl<T> RuntimeArray<T> {
asm! {
"%result = OpAccessChain _ {arr} {index}",
"OpReturnValue %result",
"%unused = OpLabel",
arr = in(reg) self,
index = in(reg) index,
options(noreturn),
}
loop {}
}
}