diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index 37f3a55f62..0458a054b6 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -464,45 +464,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { - fn new_block<'b>(cx: &'a Self::CodegenCx, llfn: Self::Function, _name: &'b str) -> Self { - let cursor_fn = cx.builder.select_function_by_id(llfn.def_cx(cx)); - let label = cx.emit_with_cursor(cursor_fn).begin_block(None).unwrap(); - let cursor = cx.builder.select_block_by_id(label); + fn build(cx: &'a Self::CodegenCx, llbb: Self::BasicBlock) -> Self { + let cursor = cx.builder.select_block_by_id(llbb); + // FIXME(eddyb) change `Self::Function` to be more like a function index. + let current_fn = { + let emit = cx.emit_with_cursor(cursor); + let selected_function = emit.selected_function().unwrap(); + let selected_function = &emit.module_ref().functions[selected_function]; + let def_inst = selected_function.def.as_ref().unwrap(); + let def = def_inst.result_id.unwrap(); + let ty = def_inst.operands[1].unwrap_id_ref(); + def.with_type(ty) + }; Self { cx, cursor, - current_fn: llfn, - basic_block: label, - current_span: Default::default(), - } - } - - fn with_cx(cx: &'a Self::CodegenCx) -> Self { - // Note: all defaults here *must* be filled out by position_at_end - Self { - cx, - cursor: Default::default(), - current_fn: 0.with_type(0), - basic_block: Default::default(), - current_span: Default::default(), - } - } - - fn build_sibling_block(&self, _name: &str) -> Self { - let mut builder = self.emit_with_cursor(BuilderCursor { - function: self.cursor.function, - block: None, - }); - let new_bb = builder.begin_block(None).unwrap(); - let new_cursor = BuilderCursor { - function: self.cursor.function, - block: builder.selected_block(), - }; - Self { - cx: self.cx, - cursor: new_cursor, - current_fn: self.current_fn, - basic_block: new_bb, + current_fn, + basic_block: llbb, current_span: Default::default(), } } @@ -525,20 +503,42 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { .line(file, loc.line as u32, loc.col_display as u32); } - fn position_at_end(&mut self, llbb: Self::BasicBlock) { - let cursor = self.cx.builder.select_block_by_id(llbb); - let current_fn = { - let emit = self.emit_with_cursor(cursor); - let selected_function = emit.selected_function().unwrap(); - let selected_function = &emit.module_ref().functions[selected_function]; - let def_inst = selected_function.def.as_ref().unwrap(); - let def = def_inst.result_id.unwrap(); - let ty = def_inst.operands[1].unwrap_id_ref(); - def.with_type(ty) + // FIXME(eddyb) change `Self::Function` to be more like a function index. + fn append_block( + cx: &'a Self::CodegenCx, + llfn: Self::Function, + _name: &str, + ) -> Self::BasicBlock { + let cursor_fn = cx.builder.select_function_by_id(llfn.def_cx(cx)); + cx.emit_with_cursor(cursor_fn).begin_block(None).unwrap() + } + + fn append_sibling_block(&mut self, _name: &str) -> Self::BasicBlock { + self.emit_with_cursor(BuilderCursor { + function: self.cursor.function, + block: None, + }) + .begin_block(None) + .unwrap() + } + + fn build_sibling_block(&mut self, _name: &str) -> Self { + let mut builder = self.emit_with_cursor(BuilderCursor { + function: self.cursor.function, + block: None, + }); + let new_bb = builder.begin_block(None).unwrap(); + let new_cursor = BuilderCursor { + function: self.cursor.function, + block: builder.selected_block(), }; - self.cursor = cursor; - self.current_fn = current_fn; - self.basic_block = llbb; + Self { + cx: self.cx, + cursor: new_cursor, + current_fn: self.current_fn, + basic_block: new_bb, + current_span: Default::default(), + } } fn ret_void(&mut self) { @@ -2207,11 +2207,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { self.intcast(val, dest_ty, false) } - unsafe fn delete_basic_block(&mut self, _bb: Self::BasicBlock) { - // Ignore: If we were to delete the block, then other builder's selected_block index would become invalid, due - // to shifting blocks. - } - fn do_not_inline(&mut self, _llret: Self::Value) { // Ignore } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index d493a24b8c..a77240e1a8 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -6,7 +6,7 @@ use rspirv::spirv::Word; use rustc_codegen_ssa::mir::place::PlaceRef; use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, MiscMethods, StaticMethods}; use rustc_middle::bug; -use rustc_middle::mir::interpret::{AllocId, Allocation, GlobalAlloc, Pointer, ScalarMaybeUninit}; +use rustc_middle::mir::interpret::{alloc_range, Allocation, GlobalAlloc, ScalarMaybeUninit}; use rustc_middle::ty::layout::TyAndLayout; use rustc_mir::interpret::Scalar; use rustc_span::symbol::Symbol; @@ -415,10 +415,7 @@ impl<'tcx> CodegenCx<'tcx> { // only uses the input alloc_id in the case that the scalar is uninitilized // as part of the error output // tldr, the pointer here is only needed for the offset - let value = match alloc - .read_scalar(self, Pointer::new(AllocId(0), *offset), size) - .unwrap() - { + let value = match alloc.read_scalar(self, alloc_range(*offset, size)).unwrap() { ScalarMaybeUninit::Scalar(scalar) => { self.scalar_to_backend(scalar, &self.primitive_to_scalar(primitive), ty) } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs index 0ff1b7d9c2..2d18818dc6 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs @@ -292,7 +292,7 @@ impl<'tcx> CodegenCx<'tcx> { let mut op_entry_point_interface_operands = vec![]; - let mut bx = Builder::new_block(self, stub_fn, ""); + let mut bx = Builder::build(self, Builder::append_block(self, stub_fn, "")); let mut call_args = vec![]; let mut decoration_locations = FxHashMap::default(); for (entry_arg_abi, hir_param) in arg_abis.iter().zip(hir_params) { diff --git a/rust-toolchain b/rust-toolchain index f0747eae78..63715fb55f 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -5,5 +5,5 @@ # to the user in the error, instead of "error: invalid channel name '[toolchain]'". [toolchain] -channel = "nightly-2021-05-17" +channel = "nightly-2021-05-24" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/tests/ui/dis/ptr_read.stderr b/tests/ui/dis/ptr_read.stderr index 0505f343ed..7b3f693185 100644 --- a/tests/ui/dis/ptr_read.stderr +++ b/tests/ui/dis/ptr_read.stderr @@ -5,9 +5,9 @@ %8 = OpVariable %5 Function OpLine %9 319 5 OpStore %8 %10 -OpLine %11 694 8 +OpLine %11 696 8 OpCopyMemory %8 %4 -OpLine %11 695 8 +OpLine %11 697 8 %12 = OpLoad %13 %8 OpLine %14 7 13 OpStore %6 %12 diff --git a/tests/ui/dis/ptr_read_method.stderr b/tests/ui/dis/ptr_read_method.stderr index 0505f343ed..7b3f693185 100644 --- a/tests/ui/dis/ptr_read_method.stderr +++ b/tests/ui/dis/ptr_read_method.stderr @@ -5,9 +5,9 @@ %8 = OpVariable %5 Function OpLine %9 319 5 OpStore %8 %10 -OpLine %11 694 8 +OpLine %11 696 8 OpCopyMemory %8 %4 -OpLine %11 695 8 +OpLine %11 697 8 %12 = OpLoad %13 %8 OpLine %14 7 13 OpStore %6 %12 diff --git a/tests/ui/dis/ptr_write.stderr b/tests/ui/dis/ptr_write.stderr index e8953beb10..871d39e2fe 100644 --- a/tests/ui/dis/ptr_write.stderr +++ b/tests/ui/dis/ptr_write.stderr @@ -7,7 +7,7 @@ OpLine %9 7 35 %10 = OpLoad %11 %4 OpLine %9 7 13 OpStore %8 %10 -OpLine %12 878 8 +OpLine %12 880 8 OpCopyMemory %6 %8 OpLine %9 8 1 OpReturn diff --git a/tests/ui/dis/ptr_write_method.stderr b/tests/ui/dis/ptr_write_method.stderr index 96e4e02ab1..51983201c2 100644 --- a/tests/ui/dis/ptr_write_method.stderr +++ b/tests/ui/dis/ptr_write_method.stderr @@ -7,7 +7,7 @@ OpLine %9 7 37 %10 = OpLoad %11 %4 OpLine %12 1012 17 OpStore %8 %10 -OpLine %13 878 8 +OpLine %13 880 8 OpCopyMemory %6 %8 OpLine %9 8 1 OpReturn