Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/imul-relax
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed Jul 12, 2019
2 parents c186e02 + 08111b7 commit f327fec
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 124 deletions.
25 changes: 6 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,14 @@ wasmer_download() {

# determine install directory if required
if [ -z "$INSTALL_DIRECTORY" ]; then
# findWasmerBinDirectory INSTALL_DIRECTORY
INSTALL_DIRECTORY="$HOME/.wasmer"
if [ -z "$WASMER_DIR" ]; then
# If WASMER_DIR is not present
INSTALL_DIRECTORY="$HOME/.wasmer"
else
# If WASMER_DIR is present
INSTALL_DIRECTORY="${WASMER_DIR}"
fi
fi
WASMER=INSTALL_DIRECTORY

# assemble expected release artifact name
BINARY="wasmer-${OS}-${ARCH}.tar.gz"
Expand Down
2 changes: 1 addition & 1 deletion lib/clif-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ hashbrown = "0.1"
target-lexicon = "0.4.0"
wasmparser = "0.32.1"
byteorder = "1"
nix = "0.13.0"
nix = "0.14.0"
libc = "0.2.49"
rayon = "1.0"

Expand Down
2 changes: 1 addition & 1 deletion lib/llvm-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hashbrown = "0.1.8"
smallvec = "0.6.8"
goblin = "0.0.20"
libc = "0.2.49"
nix = "0.13.0"
nix = "0.14.0"
capstone = { version = "0.5.0", optional = true }

[build-dependencies]
Expand Down
137 changes: 39 additions & 98 deletions lib/llvm-backend/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,102 +60,37 @@ fn type_to_llvm(intrinsics: &Intrinsics, ty: Type) -> BasicTypeEnum {
}
}

fn trap_if_not_representatable_as_int(
fn trap_if_not_representable_as_int(
builder: &Builder,
intrinsics: &Intrinsics,
context: &Context,
function: &FunctionValue,
lower_bounds: f64,
lower_bound: f64,
upper_bound: f64,
value: FloatValue,
) {
enum FloatSize {
Bits32,
Bits64,
}

let failure_block = context.append_basic_block(function, "conversion_failure_block");
let continue_block = context.append_basic_block(function, "conversion_success_block");

let float_ty = value.get_type();
let (int_ty, float_size) = if float_ty == intrinsics.f32_ty {
(intrinsics.i32_ty, FloatSize::Bits32)
} else if float_ty == intrinsics.f64_ty {
(intrinsics.i64_ty, FloatSize::Bits64)
} else {
unreachable!()
};

let (exponent, invalid_exponent) = {
let float_bits = builder
.build_bitcast(value, int_ty, "float_bits")
.into_int_value();
let (shift_amount, exponent_mask, invalid_exponent) = match float_size {
FloatSize::Bits32 => (23, 0b01111111100000000000000000000000, 0b11111111),
FloatSize::Bits64 => (
52,
0b0111111111110000000000000000000000000000000000000000000000000000,
0b11111111111,
),
};

builder.build_and(
float_bits,
int_ty.const_int(exponent_mask, false),
"masked_bits",
);

(
builder.build_right_shift(
float_bits,
int_ty.const_int(shift_amount, false),
false,
"exponent",
),
invalid_exponent,
)
};

let is_invalid_float = builder.build_or(
builder.build_int_compare(
IntPredicate::EQ,
exponent,
int_ty.const_int(invalid_exponent, false),
"is_not_normal",
),
builder.build_or(
builder.build_float_compare(
FloatPredicate::ULT,
value,
float_ty.const_float(lower_bounds),
"less_than_lower_bounds",
),
builder.build_float_compare(
FloatPredicate::UGT,
value,
float_ty.const_float(upper_bound),
"greater_than_upper_bounds",
),
"float_not_in_bounds",
),
"is_invalid_float",
let lower_bound = float_ty.const_float(lower_bound);
let upper_bound = float_ty.const_float(upper_bound);

// The 'U' in the float predicate is short for "unordered" which means that
// the comparison will compare true if either operand is a NaN. Thus, NaNs
// are out of bounds.
let above_upper_bound_cmp =
builder.build_float_compare(FloatPredicate::UGT, value, upper_bound, "above_upper_bound");
let below_lower_bound_cmp =
builder.build_float_compare(FloatPredicate::ULT, value, lower_bound, "below_lower_bound");
let out_of_bounds = builder.build_or(
above_upper_bound_cmp,
below_lower_bound_cmp,
"out_of_bounds",
);

let is_invalid_float = builder
.build_call(
intrinsics.expect_i1,
&[
is_invalid_float.as_basic_value_enum(),
intrinsics.i1_ty.const_int(0, false).as_basic_value_enum(),
],
"is_invalid_float_expect",
)
.try_as_basic_value()
.left()
.unwrap()
.into_int_value();
let failure_block = context.append_basic_block(function, "conversion_failure_block");
let continue_block = context.append_basic_block(function, "conversion_success_block");

builder.build_conditional_branch(is_invalid_float, &failure_block, &continue_block);
builder.build_conditional_branch(out_of_bounds, &failure_block, &continue_block);
builder.position_at_end(&failure_block);
builder.build_call(
intrinsics.throw_trap,
Expand Down Expand Up @@ -1722,7 +1657,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I32TruncSF32 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1737,7 +1672,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I32TruncSF64 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1758,7 +1693,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I64TruncSF32 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1773,7 +1708,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I64TruncSF64 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1794,7 +1729,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I32TruncUF32 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1809,7 +1744,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I32TruncUF64 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1830,7 +1765,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I64TruncUF32 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand All @@ -1845,7 +1780,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
}
Operator::I64TruncUF64 => {
let v1 = state.pop1()?.into_float_value();
trap_if_not_representatable_as_int(
trap_if_not_representable_as_int(
builder,
intrinsics,
context,
Expand Down Expand Up @@ -2583,13 +2518,19 @@ impl ModuleCodeGenerator<LLVMFunctionCodeGenerator, LLVMBackend, CodegenError>
if cfg!(test) {
pass_manager.add_verifier_pass();
}
pass_manager.add_function_inlining_pass();
pass_manager.add_promote_memory_to_register_pass();
pass_manager.add_lower_expect_intrinsic_pass();
pass_manager.add_scalar_repl_aggregates_pass();
pass_manager.add_instruction_combining_pass();
pass_manager.add_cfg_simplification_pass();
pass_manager.add_gvn_pass();
pass_manager.add_jump_threading_pass();
pass_manager.add_correlated_value_propagation_pass();
pass_manager.add_sccp_pass();
pass_manager.add_instruction_combining_pass();
pass_manager.add_reassociate_pass();
pass_manager.add_cfg_simplification_pass();
pass_manager.add_aggressive_inst_combiner_pass();
pass_manager.add_merged_load_store_motion_pass();
pass_manager.add_new_gvn_pass();
pass_manager.add_aggressive_dce_pass();
pass_manager.add_bit_tracking_dce_pass();
pass_manager.add_slp_vectorize_pass();
pass_manager.run_on_module(&self.module);

// self.module.print_to_stderr();
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/wasmerio/wasmer"
edition = "2018"

[dependencies]
nix = "0.12.0"
nix = "0.14.0"
page_size = "0.4.1"
wasmparser = "0.32.1"
parking_lot = "0.7.1"
Expand Down
2 changes: 1 addition & 1 deletion lib/singlepass-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dynasm = "0.3.2"
dynasmrt = "0.3.1"
lazy_static = "1.2.0"
byteorder = "1"
nix = "0.13.0"
nix = "0.14.0"
libc = "0.2.49"
smallvec = "0.6.9"
hashbrown = "0.1"
Expand Down

0 comments on commit f327fec

Please sign in to comment.