mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 05:38:00 +00:00
llvm-context: remove dead code (#247)
- 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 <bigcyrill@hotmail.com> Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
@@ -8,10 +8,6 @@ pub enum AddressSpace {
|
||||
Stack,
|
||||
/// The heap memory.
|
||||
Heap,
|
||||
/// The generic memory page.
|
||||
Storage,
|
||||
/// The transient storage.
|
||||
TransientStorage,
|
||||
}
|
||||
|
||||
impl From<AddressSpace> for inkwell::AddressSpace {
|
||||
@@ -19,8 +15,6 @@ impl From<AddressSpace> 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user