Skip to content

Commit

Permalink
Merge pull request #2154 from wasmerio/feature/reference-types-llvm
Browse files Browse the repository at this point in the history
Implement reference types in compiler-llvm.
  • Loading branch information
nlewycky authored Mar 1, 2021
2 parents 148aa41 + 40f40bb commit d13c128
Show file tree
Hide file tree
Showing 11 changed files with 626 additions and 109 deletions.
15 changes: 8 additions & 7 deletions lib/cli/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,19 @@ impl CompilerOptions {
// Converts a kind into a filename, that we will use to dump
// the contents of the IR object file to.
fn types_to_signature(types: &[Type]) -> String {
types.iter().map(|ty| {
match ty {
types
.iter()
.map(|ty| match ty {
Type::I32 => "i".to_string(),
Type::I64 => "I".to_string(),
Type::F32 => "f".to_string(),
Type::F64 => "F".to_string(),
Type::V128 => "v".to_string(),
_ => {
unimplemented!("Function type not yet supported for generated signatures in debugging");
}
}
}).collect::<Vec<_>>().join("")
Type::ExternRef => "e".to_string(),
Type::FuncRef => "r".to_string(),
})
.collect::<Vec<_>>()
.join("")
}
// Converts a kind into a filename, that we will use to dump
// the contents of the IR object file to.
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
(
sig,
local_memory_index.index(),
VMBuiltinFunctionIndex::get_local_memory_copy_index(),
VMBuiltinFunctionIndex::get_memory_copy_index(),
)
} else {
(
Expand Down
12 changes: 6 additions & 6 deletions lib/compiler-llvm/src/abi/aarch64_systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ impl Abi for Aarch64SystemV {
Type::I32 | Type::F32 => 32,
Type::I64 | Type::F64 => 64,
Type::V128 => 128,
Type::ExternRef => unimplemented!("externref in the llvm backend"),
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
Type::ExternRef | Type::FuncRef => 64, /* pointer */
})
.collect::<Vec<i32>>();
match sig_returns_bitwidths.as_slice() {
Expand Down Expand Up @@ -285,8 +284,10 @@ impl Abi for Aarch64SystemV {
assert!(value.get_type() == intrinsics.i128_ty.as_basic_type_enum());
value
}
Type::ExternRef => unimplemented!("externref in the llvm backend"),
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
Type::ExternRef | Type::FuncRef => {
assert!(value.get_type() == intrinsics.funcref_ty.as_basic_type_enum());
value
}
}
};

Expand Down Expand Up @@ -322,8 +323,7 @@ impl Abi for Aarch64SystemV {
Type::I32 | Type::F32 => 32,
Type::I64 | Type::F64 => 64,
Type::V128 => 128,
Type::ExternRef => unimplemented!("externref in the llvm backend"),
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
Type::ExternRef | Type::FuncRef => 64, /* pointer */
})
.collect::<Vec<i32>>();

Expand Down
40 changes: 8 additions & 32 deletions lib/compiler-llvm/src/abi/x86_64_systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ impl Abi for X86_64SystemV {
Type::I32 | Type::F32 => 32,
Type::I64 | Type::F64 => 64,
Type::V128 => 128,
Type::ExternRef => unimplemented!("externref in the llvm backend"),
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
Type::ExternRef | Type::FuncRef => 64, /* pointer */
})
.collect::<Vec<i32>>();

Expand Down Expand Up @@ -316,26 +315,7 @@ impl Abi for X86_64SystemV {
);
builder.build_bitcast(value, intrinsics.f32_ty, "")
}
Type::I64 => {
assert!(
value.get_type() == intrinsics.i64_ty.as_basic_type_enum()
|| value.get_type() == intrinsics.f64_ty.as_basic_type_enum()
);
builder.build_bitcast(value, intrinsics.i64_ty, "")
}
Type::F64 => {
assert!(
value.get_type() == intrinsics.i64_ty.as_basic_type_enum()
|| value.get_type() == intrinsics.f64_ty.as_basic_type_enum()
);
builder.build_bitcast(value, intrinsics.f64_ty, "")
}
Type::V128 => {
assert!(value.get_type() == intrinsics.i128_ty.as_basic_type_enum());
value
}
Type::ExternRef => unimplemented!("externref in the llvm backend"),
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
_ => panic!("should only be called to repack 32-bit values"),
}
};

Expand Down Expand Up @@ -365,8 +345,7 @@ impl Abi for X86_64SystemV {
Type::I32 | Type::F32 => 32,
Type::I64 | Type::F64 => 64,
Type::V128 => 128,
Type::ExternRef => unimplemented!("externref in the llvm backend"),
Type::FuncRef => unimplemented!("funcref in the llvm backend"),
Type::ExternRef | Type::FuncRef => 64, /* pointer */
})
.collect::<Vec<i32>>();

Expand Down Expand Up @@ -475,15 +454,12 @@ impl Abi for X86_64SystemV {
.results()
.iter()
.map(|ty| match ty {
Type::I32 | Type::F32 => Ok(32),
Type::I64 | Type::F64 => Ok(64),
Type::V128 => Ok(128),
ty => Err(CompileError::Codegen(format!(
"is_sret: unimplemented wasmer_types type {:?}",
ty
))),
Type::I32 | Type::F32 => 32,
Type::I64 | Type::F64 => 64,
Type::V128 => 128,
Type::ExternRef | Type::FuncRef => 64, /* pointer */
})
.collect::<Result<Vec<i32>, _>>()?;
.collect::<Vec<i32>>();

Ok(!matches!(
func_sig_returns_bitwidths.as_slice(),
Expand Down
56 changes: 53 additions & 3 deletions lib/compiler-llvm/src/object_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,65 @@ where
{
// TODO: use perfect hash function?
let mut libcalls = HashMap::new();
libcalls.insert("wasmer_raise_trap".to_string(), LibCall::RaiseTrap);
libcalls.insert("truncf".to_string(), LibCall::TruncF32);
libcalls.insert("trunc".to_string(), LibCall::TruncF64);
libcalls.insert("ceilf".to_string(), LibCall::CeilF32);
libcalls.insert("ceil".to_string(), LibCall::CeilF64);
libcalls.insert("floorf".to_string(), LibCall::FloorF32);
libcalls.insert("floor".to_string(), LibCall::FloorF64);
libcalls.insert("nearbyintf".to_string(), LibCall::NearestF32);
libcalls.insert("nearbyint".to_string(), LibCall::NearestF64);
libcalls.insert("truncf".to_string(), LibCall::TruncF32);
libcalls.insert("trunc".to_string(), LibCall::TruncF64);
libcalls.insert("wasmer_f32_ceil".to_string(), LibCall::CeilF32);
libcalls.insert("wasmer_f64_ceil".to_string(), LibCall::CeilF64);
libcalls.insert("wasmer_f32_floor".to_string(), LibCall::FloorF32);
libcalls.insert("wasmer_f64_floor".to_string(), LibCall::FloorF64);
libcalls.insert("wasmer_f32_nearest".to_string(), LibCall::NearestF32);
libcalls.insert("wasmer_f64_nearest".to_string(), LibCall::NearestF64);
libcalls.insert("wasmer_f32_trunc".to_string(), LibCall::TruncF32);
libcalls.insert("wasmer_f64_trunc".to_string(), LibCall::TruncF64);
libcalls.insert("wasmer_memory32_size".to_string(), LibCall::Memory32Size);
libcalls.insert(
"wasmer_imported_memory32_size".to_string(),
LibCall::ImportedMemory32Size,
);
libcalls.insert("wasmer_table_copy".to_string(), LibCall::TableCopy);
libcalls.insert("wasmer_table_init".to_string(), LibCall::TableInit);
libcalls.insert("wasmer_table_fill".to_string(), LibCall::TableFill);
libcalls.insert("wasmer_table_size".to_string(), LibCall::TableSize);
libcalls.insert(
"wasmer_imported_table_size".to_string(),
LibCall::ImportedTableSize,
);
libcalls.insert("wasmer_table_get".to_string(), LibCall::TableGet);
libcalls.insert(
"wasmer_imported_table_get".to_string(),
LibCall::ImportedTableGet,
);
libcalls.insert("wasmer_table_set".to_string(), LibCall::TableSet);
libcalls.insert(
"wasmer_imported_table_set".to_string(),
LibCall::ImportedTableSet,
);
libcalls.insert("wasmer_table_grow".to_string(), LibCall::TableGrow);
libcalls.insert(
"wasmer_imported_table_grow".to_string(),
LibCall::ImportedTableGrow,
);
libcalls.insert("wasmer_func_ref".to_string(), LibCall::FuncRef);
libcalls.insert("wasmer_elem_drop".to_string(), LibCall::ElemDrop);
libcalls.insert("wasmer_memory32_copy".to_string(), LibCall::Memory32Copy);
libcalls.insert(
"wasmer_imported_memory32_copy".to_string(),
LibCall::ImportedMemory32Copy,
);
libcalls.insert("wasmer_memory32_fill".to_string(), LibCall::Memory32Fill);
libcalls.insert(
"wasmer_imported_memory32_fill".to_string(),
LibCall::ImportedMemory32Fill,
);
libcalls.insert("wasmer_memory32_init".to_string(), LibCall::Memory32Init);
libcalls.insert("wasmer_data_drop".to_string(), LibCall::DataDrop);
libcalls.insert("wasmer_raise_trap".to_string(), LibCall::RaiseTrap);
libcalls.insert("wasmer_probestack".to_string(), LibCall::Probestack);

let elf = goblin::elf::Elf::parse(&contents).map_err(map_goblin_err)?;
Expand Down
Loading

0 comments on commit d13c128

Please sign in to comment.