From 77e0344d8050a25c8ecf38467eae4ccded01ee5a Mon Sep 17 00:00:00 2001 From: xermicus Date: Fri, 28 Feb 2025 15:38:42 +0100 Subject: [PATCH] llvm-context: remove dead code (#247) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove the __sha3 function symbol: this is provided by the pallet - remove the storage address spaces: they are not mapped into memory --------- Signed-off-by: Cyrill Leutwiler Co-authored-by: Alexander Theißen --- .../src/polkavm/context/address_space.rs | 6 --- .../polkavm/context/function/llvm_runtime.rs | 41 ------------------- .../llvm-context/src/polkavm/context/mod.rs | 16 -------- 3 files changed, 63 deletions(-) diff --git a/crates/llvm-context/src/polkavm/context/address_space.rs b/crates/llvm-context/src/polkavm/context/address_space.rs index 75cb64f..bc6d5c3 100644 --- a/crates/llvm-context/src/polkavm/context/address_space.rs +++ b/crates/llvm-context/src/polkavm/context/address_space.rs @@ -8,10 +8,6 @@ pub enum AddressSpace { Stack, /// The heap memory. Heap, - /// The generic memory page. - Storage, - /// The transient storage. - TransientStorage, } impl From for inkwell::AddressSpace { @@ -19,8 +15,6 @@ impl From for inkwell::AddressSpace { match value { AddressSpace::Stack => Self::from(0), AddressSpace::Heap => Self::from(1), - AddressSpace::Storage => Self::from(5), - AddressSpace::TransientStorage => Self::from(6), } } } diff --git a/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs b/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs index 92d0b82..b8d8216 100644 --- a/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs +++ b/crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs @@ -1,9 +1,6 @@ //! The LLVM runtime functions. -use inkwell::types::BasicType; - use crate::optimizer::Optimizer; -use crate::polkavm::context::address_space::AddressSpace; use crate::polkavm::context::function::declaration::Declaration as FunctionDeclaration; use crate::polkavm::context::function::Function; @@ -19,9 +16,6 @@ pub struct LLVMRuntime<'ctx> { pub exp: FunctionDeclaration<'ctx>, /// The corresponding LLVM runtime function. pub sign_extend: FunctionDeclaration<'ctx>, - - /// The corresponding LLVM runtime function. - pub sha3: FunctionDeclaration<'ctx>, } impl<'ctx> LLVMRuntime<'ctx> { @@ -37,9 +31,6 @@ impl<'ctx> LLVMRuntime<'ctx> { /// The corresponding runtime function name. pub const FUNCTION_SIGNEXTEND: &'static str = "__signextend"; - /// The corresponding runtime function name. - pub const FUNCTION_SHA3: &'static str = "__sha3"; - /// A shortcut constructor. pub fn new( llvm: &'ctx inkwell::context::Context, @@ -65,43 +56,11 @@ impl<'ctx> LLVMRuntime<'ctx> { Function::set_default_attributes(llvm, sign_extend, optimizer); Function::set_pure_function_attributes(llvm, sign_extend); - let sha3 = Self::declare( - module, - Self::FUNCTION_SHA3, - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .fn_type( - vec![ - llvm.ptr_type(AddressSpace::Heap.into()) - .as_basic_type_enum() - .into(), - llvm.custom_width_int_type(revive_common::BIT_LENGTH_WORD as u32) - .as_basic_type_enum() - .into(), - llvm.custom_width_int_type(revive_common::BIT_LENGTH_BOOLEAN as u32) - .as_basic_type_enum() - .into(), - ] - .as_slice(), - false, - ), - Some(inkwell::module::Linkage::External), - ); - Function::set_default_attributes(llvm, sha3, optimizer); - Function::set_attributes( - llvm, - sha3, - //vec![Attribute::ArgMemOnly, Attribute::ReadOnly], - &[], - false, - ); - Self { add_mod, mul_mod, exp, sign_extend, - - sha3, } } diff --git a/crates/llvm-context/src/polkavm/context/mod.rs b/crates/llvm-context/src/polkavm/context/mod.rs index 6558fe2..d521196 100644 --- a/crates/llvm-context/src/polkavm/context/mod.rs +++ b/crates/llvm-context/src/polkavm/context/mod.rs @@ -788,9 +788,6 @@ where panic!("revive runtime function {name} should return a value") })) } - AddressSpace::Storage | AddressSpace::TransientStorage => { - unreachable!("should use the runtime function") - } AddressSpace::Stack => { let value = self .builder() @@ -823,9 +820,6 @@ where ]; self.build_call(declaration, &arguments, "heap_store"); } - AddressSpace::Storage | AddressSpace::TransientStorage => { - unreachable!("should use the runtime function") - } AddressSpace::Stack => { let instruction = self.builder.build_store(pointer.value, value).unwrap(); instruction @@ -870,9 +864,6 @@ where where T: BasicType<'ctx>, { - assert_ne!(pointer.address_space, AddressSpace::Storage); - assert_ne!(pointer.address_space, AddressSpace::TransientStorage); - let value = unsafe { self.builder .build_gep(pointer.r#type, pointer.value, indexes, name) @@ -1298,13 +1289,6 @@ where inkwell::attributes::AttributeLoc::Param(index as u32), self.llvm.create_enum_attribute(Attribute::NoFree as u32, 0), ); - if function == self.llvm_runtime().sha3 { - call_site_value.add_attribute( - inkwell::attributes::AttributeLoc::Param(index as u32), - self.llvm - .create_enum_attribute(Attribute::ReadOnly as u32, 0), - ); - } if Some(argument.get_type()) == function.r#type.get_return_type() { if function .r#type