Merge branch 'master' into feature/reference-types

This commit is contained in:
Mark McCaskey
2021-02-10 06:36:36 -08:00
84 changed files with 2074 additions and 857 deletions

View File

@ -12,7 +12,7 @@ use inkwell::{
module::{Linkage, Module},
passes::PassManager,
targets::{FileType, TargetMachine},
types::{BasicType, BasicTypeEnum, FloatMathType, IntType, PointerType, VectorType},
types::{BasicType, FloatMathType, IntType, PointerType, VectorType},
values::{
BasicValue, BasicValueEnum, FloatValue, FunctionValue, InstructionOpcode, InstructionValue,
IntValue, PhiValue, PointerValue, VectorValue,
@ -42,18 +42,6 @@ fn to_compile_error(err: impl std::error::Error) -> CompileError {
CompileError::Codegen(format!("{}", err))
}
// TODO: move this into inkwell.
fn const_zero(ty: BasicTypeEnum) -> BasicValueEnum {
match ty {
BasicTypeEnum::ArrayType(ty) => ty.const_zero().as_basic_value_enum(),
BasicTypeEnum::FloatType(ty) => ty.const_zero().as_basic_value_enum(),
BasicTypeEnum::IntType(ty) => ty.const_zero().as_basic_value_enum(),
BasicTypeEnum::PointerType(ty) => ty.const_zero().as_basic_value_enum(),
BasicTypeEnum::StructType(ty) => ty.const_zero().as_basic_value_enum(),
BasicTypeEnum::VectorType(ty) => ty.const_zero().as_basic_value_enum(),
}
}
pub struct FuncTranslator {
ctx: Context,
target_machine: TargetMachine,
@ -188,7 +176,7 @@ impl FuncTranslator {
let ty = type_to_llvm(&intrinsics, ty)?;
for _ in 0..count {
let alloca = insert_alloca(ty, "local");
cache_builder.build_store(alloca, const_zero(ty));
cache_builder.build_store(alloca, ty.const_zero());
locals.push(alloca);
}
}
@ -1745,7 +1733,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
self.state.push1(phi.as_basic_value());
} else {
let basic_ty = phi.as_basic_value().get_type();
let placeholder_value = const_zero(basic_ty);
let placeholder_value = basic_ty.const_zero();
self.state.push1(placeholder_value);
phi.as_instruction().erase_from_basic_block();
}
@ -6770,7 +6758,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> {
let res = self.builder.build_not(v, "");
self.state.push1(res);
}
Operator::I8x16AnyTrue | Operator::I16x8AnyTrue | Operator::I32x4AnyTrue => {
Operator::V128AnyTrue => {
// | Operator::I64x2AnyTrue
// Skip canonicalization, it never changes non-zero values to zero or vice versa.
let v = self.state.pop1()?.into_int_value();