@@ -6,7 +6,6 @@ use crate::{array_call_signature, CompiledFunction, ModuleTextBuilder};
6
6
use crate :: { builder:: LinkOptions , wasm_call_signature, BuiltinFunctionSignatures } ;
7
7
use anyhow:: { Context as _, Result } ;
8
8
use cranelift_codegen:: binemit:: CodeOffset ;
9
- use cranelift_codegen:: bitset:: CompoundBitSet ;
10
9
use cranelift_codegen:: ir:: condcodes:: IntCC ;
11
10
use cranelift_codegen:: ir:: { self , InstBuilder , MemFlags , UserExternalName , UserFuncName , Value } ;
12
11
use cranelift_codegen:: isa:: {
@@ -23,14 +22,15 @@ use std::any::Any;
23
22
use std:: cmp;
24
23
use std:: collections:: HashMap ;
25
24
use std:: mem;
25
+ use std:: ops:: Range ;
26
26
use std:: path;
27
27
use std:: sync:: { Arc , Mutex } ;
28
28
use wasmparser:: { FuncValidatorAllocations , FunctionBody } ;
29
29
use wasmtime_environ:: {
30
30
AddressMapSection , BuiltinFunctionIndex , CacheStore , CompileError , DefinedFuncIndex , FlagValue ,
31
31
FunctionBodyData , FunctionLoc , HostCall , ModuleTranslation , ModuleTypesBuilder , PtrSize ,
32
- RelocationTarget , StackMapInformation , StaticModuleIndex , TrapEncodingBuilder , TrapSentinel ,
33
- TripleExt , Tunables , VMOffsets , WasmFuncType , WasmFunctionInfo , WasmValType ,
32
+ RelocationTarget , StackMapSection , StaticModuleIndex , TrapEncodingBuilder , TrapSentinel ,
33
+ TripleExt , Tunables , VMOffsets , WasmFuncType , WasmValType ,
34
34
} ;
35
35
36
36
#[ cfg( feature = "component-model" ) ]
@@ -187,7 +187,7 @@ impl wasmtime_environ::Compiler for Compiler {
187
187
func_index : DefinedFuncIndex ,
188
188
input : FunctionBodyData < ' _ > ,
189
189
types : & ModuleTypesBuilder ,
190
- ) -> Result < ( WasmFunctionInfo , Box < dyn Any + Send > ) , CompileError > {
190
+ ) -> Result < Box < dyn Any + Send > , CompileError > {
191
191
let isa = & * self . isa ;
192
192
let module = & translation. module ;
193
193
let func_index = module. func_index ( func_index) ;
@@ -275,7 +275,7 @@ impl wasmtime_environ::Compiler for Compiler {
275
275
& mut func_env,
276
276
) ?;
277
277
278
- let ( info , func) = compiler. finish_with_info (
278
+ let func = compiler. finish_with_info (
279
279
Some ( ( & body, & self . tunables ) ) ,
280
280
& format ! ( "wasm_func_{}" , func_index. as_u32( ) ) ,
281
281
) ?;
@@ -284,7 +284,7 @@ impl wasmtime_environ::Compiler for Compiler {
284
284
log:: debug!( "{:?} translated in {:?}" , func_index, timing. total( ) ) ;
285
285
log:: trace!( "{:?} timing info\n {}" , func_index, timing) ;
286
286
287
- Ok ( ( info , Box :: new ( func) ) )
287
+ Ok ( Box :: new ( func) )
288
288
}
289
289
290
290
fn compile_array_to_wasm_trampoline (
@@ -450,6 +450,7 @@ impl wasmtime_environ::Compiler for Compiler {
450
450
}
451
451
let mut addrs = AddressMapSection :: default ( ) ;
452
452
let mut traps = TrapEncodingBuilder :: default ( ) ;
453
+ let mut stack_maps = StackMapSection :: default ( ) ;
453
454
454
455
let mut ret = Vec :: with_capacity ( funcs. len ( ) ) ;
455
456
for ( i, ( sym, func) ) in funcs. iter ( ) . enumerate ( ) {
@@ -459,6 +460,11 @@ impl wasmtime_environ::Compiler for Compiler {
459
460
let addr = func. address_map ( ) ;
460
461
addrs. push ( range. clone ( ) , & addr. instructions ) ;
461
462
}
463
+ clif_to_env_stack_maps (
464
+ & mut stack_maps,
465
+ range. clone ( ) ,
466
+ func. buffer . user_stack_maps ( ) ,
467
+ ) ;
462
468
traps. push ( range. clone ( ) , & func. traps ( ) . collect :: < Vec < _ > > ( ) ) ;
463
469
builder. append_padding ( self . linkopts . padding_between_functions ) ;
464
470
let info = FunctionLoc {
@@ -473,6 +479,7 @@ impl wasmtime_environ::Compiler for Compiler {
473
479
if self . tunables . generate_address_map {
474
480
addrs. append_to ( obj) ;
475
481
}
482
+ stack_maps. append_to ( obj) ;
476
483
traps. append_to ( obj) ;
477
484
478
485
Ok ( ret)
@@ -963,16 +970,14 @@ impl FunctionCompiler<'_> {
963
970
}
964
971
965
972
fn finish ( self , clif_filename : & str ) -> Result < CompiledFunction , CompileError > {
966
- let ( info, func) = self . finish_with_info ( None , clif_filename) ?;
967
- assert ! ( info. stack_maps. is_empty( ) ) ;
968
- Ok ( func)
973
+ self . finish_with_info ( None , clif_filename)
969
974
}
970
975
971
976
fn finish_with_info (
972
977
mut self ,
973
978
body_and_tunables : Option < ( & FunctionBody < ' _ > , & Tunables ) > ,
974
979
clif_filename : & str ,
975
- ) -> Result < ( WasmFunctionInfo , CompiledFunction ) , CompileError > {
980
+ ) -> Result < CompiledFunction , CompileError > {
976
981
let context = & mut self . cx . codegen_context ;
977
982
let isa = & * self . compiler . isa ;
978
983
@@ -994,7 +999,7 @@ impl FunctionCompiler<'_> {
994
999
write ! ( output, "{}" , context. func. display( ) ) . unwrap ( ) ;
995
1000
}
996
1001
997
- let mut compiled_code = compilation_result?;
1002
+ let compiled_code = compilation_result?;
998
1003
999
1004
// Give wasm functions, user defined code, a "preferred" alignment
1000
1005
// instead of the minimum alignment as this can help perf in niche
@@ -1054,45 +1059,35 @@ impl FunctionCompiler<'_> {
1054
1059
}
1055
1060
}
1056
1061
1057
- let stack_maps =
1058
- clif_to_env_stack_maps ( compiled_code. buffer . take_user_stack_maps ( ) . into_iter ( ) ) ;
1059
1062
compiled_function
1060
1063
. set_sized_stack_slots ( std:: mem:: take ( & mut context. func . sized_stack_slots ) ) ;
1061
1064
self . compiler . contexts . lock ( ) . unwrap ( ) . push ( self . cx ) ;
1062
1065
1063
- Ok ( (
1064
- WasmFunctionInfo {
1065
- start_srcloc : compiled_function. metadata ( ) . address_map . start_srcloc ,
1066
- stack_maps : stack_maps. into ( ) ,
1067
- } ,
1068
- compiled_function,
1069
- ) )
1066
+ Ok ( compiled_function)
1070
1067
}
1071
1068
}
1072
1069
1073
1070
/// Convert from Cranelift's representation of a stack map to Wasmtime's
1074
1071
/// compiler-agnostic representation.
1072
+ ///
1073
+ /// Here `section` is the wasmtime data section being created and `range` is the
1074
+ /// range of the function being added. The `clif_stack_maps` entry is the raw
1075
+ /// listing of stack maps from Cranelift.
1075
1076
fn clif_to_env_stack_maps (
1076
- clif_stack_maps : impl ExactSizeIterator < Item = ( CodeOffset , u32 , ir:: UserStackMap ) > ,
1077
- ) -> Vec < StackMapInformation > {
1078
- let mut stack_maps = Vec :: with_capacity ( clif_stack_maps. len ( ) ) ;
1079
- for ( code_offset, mapped_bytes, stack_map) in clif_stack_maps {
1080
- let mut bitset = CompoundBitSet :: new ( ) ;
1081
- for ( ty, offset) in stack_map. entries ( ) {
1077
+ section : & mut StackMapSection ,
1078
+ range : Range < u64 > ,
1079
+ clif_stack_maps : & [ ( CodeOffset , u32 , ir:: UserStackMap ) ] ,
1080
+ ) {
1081
+ for ( offset, frame_size, stack_map) in clif_stack_maps {
1082
+ let mut frame_offsets = Vec :: new ( ) ;
1083
+ for ( ty, frame_offset) in stack_map. entries ( ) {
1082
1084
assert_eq ! ( ty, ir:: types:: I32 ) ;
1083
- bitset. insert ( usize:: try_from ( offset) . unwrap ( ) ) ;
1084
- }
1085
- if bitset. is_empty ( ) {
1086
- continue ;
1085
+ frame_offsets. push ( frame_offset) ;
1087
1086
}
1088
- let stack_map = wasmtime_environ:: StackMap :: new ( mapped_bytes, bitset) ;
1089
- stack_maps. push ( StackMapInformation {
1090
- code_offset,
1091
- stack_map,
1092
- } ) ;
1087
+ let code_offset = range. start + u64:: from ( * offset) ;
1088
+ assert ! ( code_offset < range. end) ;
1089
+ section. push ( code_offset, * frame_size, frame_offsets. into_iter ( ) ) ;
1093
1090
}
1094
- stack_maps. sort_unstable_by_key ( |info| info. code_offset ) ;
1095
- stack_maps
1096
1091
}
1097
1092
1098
1093
fn declare_and_call (
0 commit comments