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

llvm-context: remove dead code #247

Merged
merged 3 commits into from
Feb 28, 2025
Merged
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
6 changes: 0 additions & 6 deletions crates/llvm-context/src/polkavm/context/address_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ pub enum AddressSpace {
Stack,
/// The heap memory.
Heap,
/// The generic memory page.
Storage,
/// The transient storage.
TransientStorage,
}

impl From<AddressSpace> for inkwell::AddressSpace {
fn from(value: AddressSpace) -> Self {
match value {
AddressSpace::Stack => Self::from(0),
AddressSpace::Heap => Self::from(1),
AddressSpace::Storage => Self::from(5),
AddressSpace::TransientStorage => Self::from(6),
}
}
}
41 changes: 0 additions & 41 deletions crates/llvm-context/src/polkavm/context/function/llvm_runtime.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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> {
Expand All @@ -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,
Expand All @@ -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,
}
}

Expand Down
16 changes: 0 additions & 16 deletions crates/llvm-context/src/polkavm/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading