Bitcasting at control flow exits (#1272)
* Bitcast vectors immediately before a return * Bitcast vectors immediately before a block end * Use helper function for bitcasting arguments * Add FuncTranslationState::peekn_mut; allows mutating of peeked values * Bitcast values in place, avoiding an allocation Also, retrieves the correct EBB header types for bitcasting on Operator::End. * Bitcast values of a function with no explicit Wasm return instruction * Add Signature::return_types method This eliminates some duplicate code and avoids extra `use`s of `Vec`. * Add Signature::param_types method; only collect normal parameters in both this and Signature::return_types * Move normal_args to Signature::num_normal_params method This matches the organization of the other Signature::num_*_params methods. * Bitcast values of Operator::Call and Operator::CallIndirect * Add DataFlowGraph::ebb_param_types * Bitcast values of Operator::Br and Operator::BrIf * Bitcast values of Operator::BrTable
This commit is contained in:
@@ -14,6 +14,7 @@ use crate::isa::TargetIsa;
|
||||
use crate::packed_option::ReservedValue;
|
||||
use crate::write::write_operands;
|
||||
use crate::HashMap;
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt;
|
||||
use core::iter;
|
||||
use core::mem;
|
||||
@@ -776,6 +777,14 @@ impl DataFlowGraph {
|
||||
self.ebbs[ebb].params.as_slice(&self.value_lists)
|
||||
}
|
||||
|
||||
/// Get the types of the parameters on `ebb`.
|
||||
pub fn ebb_param_types(&self, ebb: Ebb) -> Vec<Type> {
|
||||
self.ebb_params(ebb)
|
||||
.iter()
|
||||
.map(|&v| self.value_type(v))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Append a parameter with type `ty` to `ebb`.
|
||||
pub fn append_ebb_param(&mut self, ebb: Ebb, ty: Type) -> Value {
|
||||
let param = self.values.next_key();
|
||||
|
||||
@@ -88,6 +88,16 @@ impl Signature {
|
||||
.count()
|
||||
}
|
||||
|
||||
/// Count the number of normal parameters in a signature.
|
||||
/// Exclude special-purpose parameters that represent runtime stuff and not WebAssembly
|
||||
/// arguments.
|
||||
pub fn num_normal_params(&self) -> usize {
|
||||
self.params
|
||||
.iter()
|
||||
.filter(|arg| arg.purpose == ArgumentPurpose::Normal)
|
||||
.count()
|
||||
}
|
||||
|
||||
/// Does this signature take an struct return pointer parameter?
|
||||
pub fn uses_struct_return_param(&self) -> bool {
|
||||
self.uses_special_param(ArgumentPurpose::StructReturn)
|
||||
@@ -102,6 +112,24 @@ impl Signature {
|
||||
.count()
|
||||
> 1
|
||||
}
|
||||
|
||||
/// Collect the normal parameter types of the signature; see `[ArgumentPurpose::Normal]`.
|
||||
pub fn param_types(&self) -> Vec<Type> {
|
||||
self.params
|
||||
.iter()
|
||||
.filter(|ap| ap.purpose == ArgumentPurpose::Normal)
|
||||
.map(|ap| ap.value_type)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Collect the normal return types of the signature; see `[ArgumentPurpose::Normal]`.
|
||||
pub fn return_types(&self) -> Vec<Type> {
|
||||
self.returns
|
||||
.iter()
|
||||
.filter(|ap| ap.purpose == ArgumentPurpose::Normal)
|
||||
.map(|ap| ap.value_type)
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper type capable of displaying a `Signature` with correct register names.
|
||||
|
||||
Reference in New Issue
Block a user