-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
wasmtime: VMRuntimeLimits
pointer is already SSA
#8689
Merged
jameysharp
merged 2 commits into
bytecodealliance:main
from
jameysharp:limits-ptr-is-ssa
May 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ use cranelift_codegen::ir::pcc::Fact; | |
use cranelift_codegen::ir::types::*; | ||
use cranelift_codegen::ir::{ArgumentPurpose, Function, InstBuilder, MemFlags}; | ||
use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa}; | ||
use cranelift_entity::packed_option::ReservedValue; | ||
use cranelift_entity::{EntityRef, PrimaryMap, SecondaryMap}; | ||
use cranelift_frontend::FunctionBuilder; | ||
use cranelift_frontend::Variable; | ||
|
@@ -118,7 +119,7 @@ pub struct FuncEnvironment<'module_environment> { | |
/// VMRuntimeLimits` for this function's vmctx argument. This pointer is stored | ||
/// in the vmctx itself, but never changes for the lifetime of the function, | ||
/// so if we load it up front we can continue to use it throughout. | ||
vmruntime_limits_ptr: cranelift_frontend::Variable, | ||
vmruntime_limits_ptr: ir::Value, | ||
|
||
/// A cached epoch deadline value, when performing epoch-based | ||
/// interruption. Loaded from `VMRuntimeLimits` and reloaded after | ||
|
@@ -171,7 +172,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { | |
fuel_var: Variable::new(0), | ||
epoch_deadline_var: Variable::new(0), | ||
epoch_ptr_var: Variable::new(0), | ||
vmruntime_limits_ptr: Variable::new(0), | ||
vmruntime_limits_ptr: ir::Value::reserved_value(), | ||
|
||
// Start with at least one fuel being consumed because even empty | ||
// functions should consume at least some fuel. | ||
|
@@ -284,14 +285,13 @@ impl<'module_environment> FuncEnvironment<'module_environment> { | |
// function. This is possible since we know that the pointer never | ||
// changes for the lifetime of the function. | ||
let pointer_type = self.pointer_type(); | ||
builder.declare_var(self.vmruntime_limits_ptr, pointer_type); | ||
let vmctx = self.vmctx(builder.func); | ||
let base = builder.ins().global_value(pointer_type, vmctx); | ||
let offset = i32::try_from(self.offsets.vmctx_runtime_limits()).unwrap(); | ||
let interrupt_ptr = builder | ||
.ins() | ||
.load(pointer_type, ir::MemFlags::trusted(), base, offset); | ||
builder.def_var(self.vmruntime_limits_ptr, interrupt_ptr); | ||
self.vmruntime_limits_ptr = interrupt_ptr; | ||
} | ||
|
||
fn fuel_function_entry(&mut self, builder: &mut FunctionBuilder<'_>) { | ||
|
@@ -438,7 +438,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { | |
|
||
/// Loads the fuel consumption value from `VMRuntimeLimits` into `self.fuel_var` | ||
fn fuel_load_into_var(&mut self, builder: &mut FunctionBuilder<'_>) { | ||
let (addr, offset) = self.fuel_addr_offset(builder); | ||
let (addr, offset) = self.fuel_addr_offset(); | ||
let fuel = builder | ||
.ins() | ||
.load(ir::types::I64, ir::MemFlags::trusted(), addr, offset); | ||
|
@@ -448,7 +448,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> { | |
/// Stores the fuel consumption value from `self.fuel_var` into | ||
/// `VMRuntimeLimits`. | ||
fn fuel_save_from_var(&mut self, builder: &mut FunctionBuilder<'_>) { | ||
let (addr, offset) = self.fuel_addr_offset(builder); | ||
let (addr, offset) = self.fuel_addr_offset(); | ||
let fuel_consumed = builder.use_var(self.fuel_var); | ||
builder | ||
.ins() | ||
|
@@ -457,12 +457,9 @@ impl<'module_environment> FuncEnvironment<'module_environment> { | |
|
||
/// Returns the `(address, offset)` of the fuel consumption within | ||
/// `VMRuntimeLimits`, used to perform loads/stores later. | ||
fn fuel_addr_offset( | ||
&mut self, | ||
builder: &mut FunctionBuilder<'_>, | ||
) -> (ir::Value, ir::immediates::Offset32) { | ||
fn fuel_addr_offset(&mut self) -> (ir::Value, ir::immediates::Offset32) { | ||
( | ||
builder.use_var(self.vmruntime_limits_ptr), | ||
self.vmruntime_limits_ptr, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, can we debug assert that it has been initialized here? |
||
i32::from(self.offsets.ptr.vmruntime_limits_fuel_consumed()).into(), | ||
) | ||
} | ||
|
@@ -599,12 +596,11 @@ impl<'module_environment> FuncEnvironment<'module_environment> { | |
} | ||
|
||
fn epoch_load_deadline_into_var(&mut self, builder: &mut FunctionBuilder<'_>) { | ||
let interrupts = builder.use_var(self.vmruntime_limits_ptr); | ||
let deadline = | ||
builder.ins().load( | ||
ir::types::I64, | ||
ir::MemFlags::trusted(), | ||
interrupts, | ||
self.vmruntime_limits_ptr, | ||
ir::immediates::Offset32::new( | ||
self.offsets.ptr.vmruntime_limits_epoch_deadline() as i32 | ||
), | ||
|
@@ -1688,10 +1684,9 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m | |
} | ||
|
||
fn after_locals(&mut self, num_locals: usize) { | ||
self.vmruntime_limits_ptr = Variable::new(num_locals); | ||
self.fuel_var = Variable::new(num_locals + 1); | ||
self.epoch_deadline_var = Variable::new(num_locals + 2); | ||
self.epoch_ptr_var = Variable::new(num_locals + 3); | ||
self.fuel_var = Variable::new(num_locals); | ||
self.epoch_deadline_var = Variable::new(num_locals + 1); | ||
self.epoch_ptr_var = Variable::new(num_locals + 2); | ||
} | ||
|
||
fn translate_table_grow( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we debug assert that
self.vmruntime_limits_ptr
is the reserved value before we initialize it, to make sure that we aren't defining it multiple times? And/or use anOption
orPackedOption
for the field?