mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-29 17:34:34 +00:00
gb_internal LLVM backend
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise);
|
||||
gb_internal lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise);
|
||||
|
||||
lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) {
|
||||
gb_internal lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast *right, Type *type) {
|
||||
lbModule *m = p->module;
|
||||
|
||||
lbBlock *rhs = lb_create_block(p, "logical.cmp.rhs");
|
||||
@@ -113,7 +113,7 @@ lbValue lb_emit_logical_binary_expr(lbProcedure *p, TokenKind op, Ast *left, Ast
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) {
|
||||
gb_internal lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type) {
|
||||
switch (op) {
|
||||
case Token_Add:
|
||||
return x;
|
||||
@@ -283,7 +283,7 @@ lbValue lb_emit_unary_arith(lbProcedure *p, TokenKind op, lbValue x, Type *type)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, lbValue *res_) {
|
||||
gb_internal bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, lbValue *res_) {
|
||||
GB_ASSERT(is_type_array_like(type));
|
||||
Type *elem_type = base_array_type(type);
|
||||
|
||||
@@ -418,7 +418,7 @@ bool lb_try_direct_vector_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbVal
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
|
||||
gb_internal lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
|
||||
GB_ASSERT(is_type_array_like(lhs.type) || is_type_array_like(rhs.type));
|
||||
|
||||
lhs = lb_emit_conv(p, lhs, type);
|
||||
@@ -490,7 +490,7 @@ lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue r
|
||||
}
|
||||
}
|
||||
|
||||
bool lb_is_matrix_simdable(Type *t) {
|
||||
gb_internal bool lb_is_matrix_simdable(Type *t) {
|
||||
Type *mt = base_type(t);
|
||||
GB_ASSERT(mt->kind == Type_Matrix);
|
||||
|
||||
@@ -534,7 +534,7 @@ bool lb_is_matrix_simdable(Type *t) {
|
||||
}
|
||||
|
||||
|
||||
LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) {
|
||||
gb_internal LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) {
|
||||
Type *mt = base_type(matrix.type);
|
||||
GB_ASSERT(mt->kind == Type_Matrix);
|
||||
LLVMTypeRef elem_type = lb_type(p->module, mt->Matrix.elem);
|
||||
@@ -554,7 +554,7 @@ LLVMValueRef lb_matrix_to_vector(lbProcedure *p, lbValue matrix) {
|
||||
#endif
|
||||
}
|
||||
|
||||
LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) {
|
||||
gb_internal LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) {
|
||||
mt = base_type(mt);
|
||||
GB_ASSERT(mt->kind == Type_Matrix);
|
||||
|
||||
@@ -574,7 +574,7 @@ LLVMValueRef lb_matrix_trimmed_vector_mask(lbProcedure *p, Type *mt) {
|
||||
return mask;
|
||||
}
|
||||
|
||||
LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) {
|
||||
gb_internal LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) {
|
||||
LLVMValueRef vector = lb_matrix_to_vector(p, m);
|
||||
|
||||
Type *mt = base_type(m.type);
|
||||
@@ -592,7 +592,7 @@ LLVMValueRef lb_matrix_to_trimmed_vector(lbProcedure *p, lbValue m) {
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) {
|
||||
gb_internal lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) {
|
||||
if (is_type_array(m.type)) {
|
||||
i32 rank = type_math_rank(m.type);
|
||||
if (rank == 2) {
|
||||
@@ -669,7 +669,7 @@ lbValue lb_emit_matrix_tranpose(lbProcedure *p, lbValue m, Type *type) {
|
||||
return lb_addr_load(p, res);
|
||||
}
|
||||
|
||||
lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type *type) {
|
||||
gb_internal lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type *type) {
|
||||
lbAddr res = lb_add_local_generated(p, type, true);
|
||||
LLVMValueRef res_ptr = res.addr.value;
|
||||
unsigned alignment = cast(unsigned)gb_max(type_align_of(type), lb_alignof(LLVMTypeOf(vector)));
|
||||
@@ -681,7 +681,7 @@ lbValue lb_matrix_cast_vector_to_type(lbProcedure *p, LLVMValueRef vector, Type
|
||||
return lb_addr_load(p, res);
|
||||
}
|
||||
|
||||
lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) {
|
||||
gb_internal lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) {
|
||||
if (is_type_array(m.type)) {
|
||||
// no-op
|
||||
m.type = type;
|
||||
@@ -710,7 +710,7 @@ lbValue lb_emit_matrix_flatten(lbProcedure *p, lbValue m, Type *type) {
|
||||
}
|
||||
|
||||
|
||||
lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) {
|
||||
gb_internal lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type) {
|
||||
Type *mt = base_type(type);
|
||||
Type *at = base_type(a.type);
|
||||
Type *bt = base_type(b.type);
|
||||
@@ -741,7 +741,7 @@ lbValue lb_emit_outer_product(lbProcedure *p, lbValue a, lbValue b, Type *type)
|
||||
|
||||
}
|
||||
|
||||
lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
|
||||
gb_internal lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
|
||||
// TODO(bill): Handle edge case for f16 types on x86(-64) platforms
|
||||
|
||||
Type *xt = base_type(lhs.type);
|
||||
@@ -828,7 +828,7 @@ lbValue lb_emit_matrix_mul(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type)
|
||||
}
|
||||
}
|
||||
|
||||
lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
|
||||
gb_internal lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
|
||||
// TODO(bill): Handle edge case for f16 types on x86(-64) platforms
|
||||
|
||||
Type *mt = base_type(lhs.type);
|
||||
@@ -897,7 +897,7 @@ lbValue lb_emit_matrix_mul_vector(lbProcedure *p, lbValue lhs, lbValue rhs, Type
|
||||
return lb_addr_load(p, res);
|
||||
}
|
||||
|
||||
lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
|
||||
gb_internal lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type *type) {
|
||||
// TODO(bill): Handle edge case for f16 types on x86(-64) platforms
|
||||
|
||||
Type *mt = base_type(rhs.type);
|
||||
@@ -984,7 +984,7 @@ lbValue lb_emit_vector_mul_matrix(lbProcedure *p, lbValue lhs, lbValue rhs, Type
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) {
|
||||
gb_internal lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type, bool component_wise) {
|
||||
GB_ASSERT(is_type_matrix(lhs.type) || is_type_matrix(rhs.type));
|
||||
|
||||
if (op == Token_Mul && !component_wise) {
|
||||
@@ -1056,7 +1056,7 @@ lbValue lb_emit_arith_matrix(lbProcedure *p, TokenKind op, lbValue lhs, lbValue
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
|
||||
gb_internal lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
|
||||
if (is_type_array_like(lhs.type) || is_type_array_like(rhs.type)) {
|
||||
return lb_emit_arith_array(p, op, lhs, rhs, type);
|
||||
} else if (is_type_matrix(lhs.type) || is_type_matrix(rhs.type)) {
|
||||
@@ -1325,7 +1325,7 @@ handle_op:
|
||||
return {};
|
||||
}
|
||||
|
||||
lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
|
||||
ast_node(be, BinaryExpr, expr);
|
||||
|
||||
TypeAndValue tv = type_and_value_of_expr(expr);
|
||||
@@ -1472,7 +1472,7 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
gb_internal lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
lbModule *m = p->module;
|
||||
t = reduce_tuple_to_single_type(t);
|
||||
|
||||
@@ -2202,7 +2202,7 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
|
||||
return {};
|
||||
}
|
||||
|
||||
lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) {
|
||||
gb_internal lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right, Type *type) {
|
||||
GB_ASSERT((is_type_struct(type) || is_type_union(type)) && is_type_comparable(type));
|
||||
lbValue left_ptr = lb_address_from_load_or_generate_local(p, left);
|
||||
lbValue right_ptr = lb_address_from_load_or_generate_local(p, right);
|
||||
@@ -2230,7 +2230,7 @@ lbValue lb_compare_records(lbProcedure *p, TokenKind op_kind, lbValue left, lbVa
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right) {
|
||||
gb_internal lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue right) {
|
||||
Type *a = core_type(left.type);
|
||||
Type *b = core_type(right.type);
|
||||
|
||||
@@ -2642,7 +2642,7 @@ lbValue lb_emit_comp(lbProcedure *p, TokenKind op_kind, lbValue left, lbValue ri
|
||||
|
||||
|
||||
|
||||
lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
|
||||
gb_internal lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
|
||||
lbValue res = {};
|
||||
res.type = t_llvm_bool;
|
||||
Type *t = x.type;
|
||||
@@ -2803,7 +2803,7 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
|
||||
return {};
|
||||
}
|
||||
|
||||
lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbValue const &index) {
|
||||
gb_internal lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbValue const &index) {
|
||||
lbAddr v = lb_add_local_generated(p, type, false);
|
||||
lbValue ptr = lb_emit_struct_ep(p, v.addr, 0);
|
||||
lbValue idx = lb_emit_struct_ep(p, v.addr, 1);
|
||||
@@ -2813,7 +2813,7 @@ lbValue lb_make_soa_pointer(lbProcedure *p, Type *type, lbValue const &addr, lbV
|
||||
return lb_addr_load(p, v);
|
||||
}
|
||||
|
||||
lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
|
||||
ast_node(ue, UnaryExpr, expr);
|
||||
auto tv = type_and_value_of_expr(expr);
|
||||
|
||||
@@ -3023,8 +3023,8 @@ lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
|
||||
return lb_build_addr_ptr(p, ue->expr);
|
||||
}
|
||||
|
||||
lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr);
|
||||
lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr);
|
||||
gb_internal lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
||||
u16 prev_state_flags = p->state_flags;
|
||||
defer (p->state_flags = prev_state_flags);
|
||||
|
||||
@@ -3080,7 +3080,7 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
|
||||
return res;
|
||||
}
|
||||
|
||||
lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
|
||||
lbModule *m = p->module;
|
||||
|
||||
expr = unparen_expr(expr);
|
||||
@@ -3355,10 +3355,10 @@ lbValue lb_build_expr_internal(lbProcedure *p, Ast *expr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
lbAddr lb_get_soa_variable_addr(lbProcedure *p, Entity *e) {
|
||||
gb_internal lbAddr lb_get_soa_variable_addr(lbProcedure *p, Entity *e) {
|
||||
return map_must_get(&p->module->soa_values, e);
|
||||
}
|
||||
lbValue lb_get_using_variable(lbProcedure *p, Entity *e) {
|
||||
gb_internal lbValue lb_get_using_variable(lbProcedure *p, Entity *e) {
|
||||
GB_ASSERT(e->kind == Entity_Variable && e->flags & EntityFlag_Using);
|
||||
String name = e->token.string;
|
||||
Entity *parent = e->using_parent;
|
||||
@@ -3393,7 +3393,7 @@ lbValue lb_get_using_variable(lbProcedure *p, Entity *e) {
|
||||
|
||||
|
||||
|
||||
lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) {
|
||||
gb_internal lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) {
|
||||
GB_ASSERT(e != nullptr);
|
||||
if (e->kind == Entity_Constant) {
|
||||
Type *t = default_type(type_of_expr(expr));
|
||||
@@ -3427,7 +3427,7 @@ lbAddr lb_build_addr_from_entity(lbProcedure *p, Entity *e, Ast *expr) {
|
||||
return lb_addr(v);
|
||||
}
|
||||
|
||||
lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
|
||||
gb_internal lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue const &tv) {
|
||||
isize index_count = ce->args.count-1;
|
||||
lbAddr addr = lb_build_addr(p, ce->args[0]);
|
||||
if (index_count == 0) {
|
||||
@@ -3463,8 +3463,8 @@ lbAddr lb_build_array_swizzle_addr(lbProcedure *p, AstCallExpr *ce, TypeAndValue
|
||||
}
|
||||
|
||||
|
||||
lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr);
|
||||
lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr);
|
||||
gb_internal lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
expr = unparen_expr(expr);
|
||||
|
||||
// IMPORTANT NOTE(bill):
|
||||
@@ -3489,7 +3489,7 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
|
||||
return addr;
|
||||
}
|
||||
|
||||
void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *> const &elems, Array<lbCompoundLitElemTempData> *temp_data, Type *compound_type) {
|
||||
gb_internal void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *> const &elems, Array<lbCompoundLitElemTempData> *temp_data, Type *compound_type) {
|
||||
Type *bt = base_type(compound_type);
|
||||
Type *et = nullptr;
|
||||
switch (bt->kind) {
|
||||
@@ -3595,7 +3595,7 @@ void lb_build_addr_compound_lit_populate(lbProcedure *p, Slice<Ast *> const &ele
|
||||
}
|
||||
}
|
||||
}
|
||||
void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLitElemTempData> const &temp_data) {
|
||||
gb_internal void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLitElemTempData> const &temp_data) {
|
||||
for_array(i, temp_data) {
|
||||
auto td = temp_data[i];
|
||||
if (td.value.value != nullptr) {
|
||||
@@ -3614,7 +3614,7 @@ void lb_build_addr_compound_lit_assign_array(lbProcedure *p, Array<lbCompoundLit
|
||||
}
|
||||
}
|
||||
|
||||
lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) {
|
||||
ast_node(ie, IndexExpr, expr);
|
||||
|
||||
Type *t = base_type(type_of_expr(ie->expr));
|
||||
@@ -3833,7 +3833,7 @@ lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) {
|
||||
}
|
||||
|
||||
|
||||
lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) {
|
||||
ast_node(se, SliceExpr, expr);
|
||||
|
||||
lbValue low = lb_const_int(p->module, t_int, 0);
|
||||
@@ -4031,7 +4031,7 @@ lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) {
|
||||
}
|
||||
|
||||
|
||||
lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
ast_node(cl, CompoundLit, expr);
|
||||
|
||||
Type *type = type_of_expr(expr);
|
||||
@@ -4383,7 +4383,7 @@ lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
}
|
||||
|
||||
|
||||
lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) {
|
||||
gb_internal lbAddr lb_build_addr_internal(lbProcedure *p, Ast *expr) {
|
||||
switch (expr->kind) {
|
||||
case_ast_node(i, Implicit, expr);
|
||||
lbAddr v = {};
|
||||
|
||||
Reference in New Issue
Block a user