Browse Source

Correct max alignment handling throughout the llvm backend

gingerBill 3 years ago
parent
commit
aeacf3a9d8
6 changed files with 22 additions and 17 deletions
  1. 12 10
      src/build_settings.cpp
  2. 1 1
      src/llvm_abi.cpp
  3. 3 3
      src/llvm_backend_expr.cpp
  4. 4 1
      src/llvm_backend_general.cpp
  5. 1 1
      src/llvm_backend_stmt.cpp
  6. 1 1
      src/types.cpp

+ 12 - 10
src/build_settings.cpp

@@ -428,12 +428,13 @@ gb_global TargetMetrics target_essence_amd64 = {
 	str_lit("x86_64-pc-none-elf"),
 	str_lit("x86_64-pc-none-elf"),
 };
 };
 
 
+
 gb_global TargetMetrics target_freestanding_wasm32 = {
 gb_global TargetMetrics target_freestanding_wasm32 = {
 	TargetOs_freestanding,
 	TargetOs_freestanding,
 	TargetArch_wasm32,
 	TargetArch_wasm32,
 	4, 8, 16,
 	4, 8, 16,
 	str_lit("wasm32-freestanding-js"),
 	str_lit("wasm32-freestanding-js"),
-	str_lit(""),
+	str_lit("e-m:e-p:32:32-i64:64-n32:64-S128"),
 };
 };
 
 
 gb_global TargetMetrics target_js_wasm32 = {
 gb_global TargetMetrics target_js_wasm32 = {
@@ -441,15 +442,7 @@ gb_global TargetMetrics target_js_wasm32 = {
 	TargetArch_wasm32,
 	TargetArch_wasm32,
 	4, 8, 16,
 	4, 8, 16,
 	str_lit("wasm32-js-js"),
 	str_lit("wasm32-js-js"),
-	str_lit(""),
-};
-
-gb_global TargetMetrics target_js_wasm64 = {
-	TargetOs_js,
-	TargetArch_wasm64,
-	8, 8, 16,
-	str_lit("wasm64-js-js"),
-	str_lit(""),
+	str_lit("e-m:e-p:32:32-i64:64-n32:64-S128"),
 };
 };
 
 
 gb_global TargetMetrics target_wasi_wasm32 = {
 gb_global TargetMetrics target_wasi_wasm32 = {
@@ -457,6 +450,15 @@ gb_global TargetMetrics target_wasi_wasm32 = {
 	TargetArch_wasm32,
 	TargetArch_wasm32,
 	4, 8, 16,
 	4, 8, 16,
 	str_lit("wasm32-wasi-js"),
 	str_lit("wasm32-wasi-js"),
+	str_lit("e-m:e-p:32:32-i64:64-n32:64-S128"),
+};
+
+
+gb_global TargetMetrics target_js_wasm64 = {
+	TargetOs_js,
+	TargetArch_wasm64,
+	8, 8, 16,
+	str_lit("wasm64-js-js"),
 	str_lit(""),
 	str_lit(""),
 };
 };
 
 

+ 1 - 1
src/llvm_abi.cpp

@@ -294,7 +294,7 @@ i64 lb_alignof(LLVMTypeRef type) {
 			i64 elem_size = lb_sizeof(elem);
 			i64 elem_size = lb_sizeof(elem);
 			i64 count = LLVMGetVectorSize(type);
 			i64 count = LLVMGetVectorSize(type);
 			i64 size = count * elem_size;
 			i64 size = count * elem_size;
-			return gb_clamp(next_pow2(size), 1, build_context.max_align);
+			return gb_clamp(next_pow2(size), 1, build_context.max_simd_align);
 		}
 		}
 
 
 	}
 	}

+ 3 - 3
src/llvm_backend_expr.cpp

@@ -137,7 +137,7 @@ lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type)
 		lbAddr res_addr = lb_add_local(p, type, nullptr, false, 0, true);
 		lbAddr res_addr = lb_add_local(p, type, nullptr, false, 0, true);
 		lbValue res = lb_addr_get_ptr(p, res_addr);
 		lbValue res = lb_addr_get_ptr(p, res_addr);
 
 
-		bool inline_array_arith = type_size_of(type) <= build_context.max_align;
+		bool inline_array_arith = lb_can_try_to_inline_array_arith(type);
 
 
 		i32 count = cast(i32)get_array_type_count(tl);
 		i32 count = cast(i32)get_array_type_count(tl);
 
 
@@ -436,7 +436,7 @@ lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue r
 		return direct_vector_res;
 		return direct_vector_res;
 	}
 	}
 
 
-	bool inline_array_arith = type_size_of(type) <= build_context.max_align;
+	bool inline_array_arith = lb_can_try_to_inline_array_arith(type);
 	if (inline_array_arith) {
 	if (inline_array_arith) {
 
 
 		auto dst_ptrs = slice_make<lbValue>(temporary_allocator(), n);
 		auto dst_ptrs = slice_make<lbValue>(temporary_allocator(), n);
@@ -2303,7 +2303,7 @@ lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue ri
 			cmp_op = Token_And;
 			cmp_op = Token_And;
 		}
 		}
 
 
-		bool inline_array_arith = type_size_of(tl) <= build_context.max_align;
+		bool inline_array_arith = lb_can_try_to_inline_array_arith(tl);
 		i32 count = 0;
 		i32 count = 0;
 		switch (tl->kind) {
 		switch (tl->kind) {
 		case Type_Array:           count = cast(i32)tl->Array.count;           break;
 		case Type_Array:           count = cast(i32)tl->Array.count;           break;

+ 4 - 1
src/llvm_backend_general.cpp

@@ -591,6 +591,9 @@ bool lb_try_update_alignment(lbValue ptr, unsigned alignment) {
 	return lb_try_update_alignment(ptr.value, alignment);
 	return lb_try_update_alignment(ptr.value, alignment);
 }
 }
 
 
+bool lb_can_try_to_inline_array_arith(Type *t) {
+	return type_size_of(t) <= build_context.max_simd_align;
+}
 
 
 bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) {
 bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) {
 	Type *array_type = base_type(type_deref(ptr.type));
 	Type *array_type = base_type(type_deref(ptr.type));
@@ -599,7 +602,7 @@ bool lb_try_vector_cast(lbModule *m, lbValue ptr, LLVMTypeRef *vector_type_) {
 	Type *elem_type = base_array_type(array_type);
 	Type *elem_type = base_array_type(array_type);
 
 
 	// TODO(bill): Determine what is the correct limit for doing vector arithmetic
 	// TODO(bill): Determine what is the correct limit for doing vector arithmetic
-	if (type_size_of(array_type) <= build_context.max_align &&
+	if (lb_can_try_to_inline_array_arith(array_type) &&
 	    is_type_valid_vector_elem(elem_type)) {
 	    is_type_valid_vector_elem(elem_type)) {
 		// Try to treat it like a vector if possible
 		// Try to treat it like a vector if possible
 		bool possible = false;
 		bool possible = false;

+ 1 - 1
src/llvm_backend_stmt.cpp

@@ -1796,7 +1796,7 @@ void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs,
 
 
 	lbValue rhs = lb_emit_conv(p, value, lhs_type);
 	lbValue rhs = lb_emit_conv(p, value, lhs_type);
 
 
-	bool inline_array_arith = type_size_of(array_type) <= build_context.max_align;
+	bool inline_array_arith = lb_can_try_to_inline_array_arith(array_type);
 
 
 
 
 	if (lhs.kind == lbAddr_Swizzle) {
 	if (lhs.kind == lbAddr_Swizzle) {

+ 1 - 1
src/types.cpp

@@ -1428,7 +1428,7 @@ i64 matrix_align_of(Type *t, struct TypePath *tp) {
 	}
 	}
 	GB_ASSERT(min_alignment >= elem_align);
 	GB_ASSERT(min_alignment >= elem_align);
 	
 	
-	i64 align = gb_min(min_alignment, build_context.max_align);
+	i64 align = gb_min(min_alignment, build_context.max_simd_align);
 	return align;
 	return align;
 }
 }