Skip to content

Commit 356af2d

Browse files
committed
prefix more type-related stuff, move it to type.h
1 parent b1f59cd commit 356af2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+636
-619
lines changed

include/shady/ir/type.h

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,56 @@ Type* nominal_type(Module*, Nodes annotations, String name);
1515

1616
const Type* shd_get_actual_mask_type(IrArena* arena);
1717

18-
String get_address_space_name(AddressSpace);
19-
/// Returns false iff pointers in that address space can contain different data at the same address
20-
/// (amongst threads in the same subgroup)
21-
bool shd_is_addr_space_uniform(IrArena*, AddressSpace);
22-
23-
String shd_get_type_name(IrArena* arena, const Type* t);
18+
bool shd_is_subtype(const Type* supertype, const Type* type);
19+
void shd_check_subtype(const Type* supertype, const Type* type);
2420

2521
/// Is this a type that a value in the language can have ?
26-
bool is_value_type(const Type*);
22+
bool shd_is_value_type(const Type*);
2723

2824
/// Is this a valid data type (for usage in other types and as type arguments) ?
29-
bool is_data_type(const Type*);
25+
bool shd_is_data_type(const Type*);
26+
27+
bool shd_is_arithm_type(const Type*);
28+
bool shd_is_shiftable_type(const Type*);
29+
bool shd_has_boolean_ops(const Type*);
30+
bool shd_is_comparable_type(const Type*);
31+
bool shd_is_ordered_type(const Type*);
32+
bool shd_is_physical_ptr_type(const Type* t);
33+
bool shd_is_generic_ptr_type(const Type* t);
34+
35+
bool shd_is_reinterpret_cast_legal(const Type* src_type, const Type* dst_type);
36+
bool shd_is_conversion_legal(const Type* src_type, const Type* dst_type);
3037

3138
/// Returns the (possibly qualified) pointee type from a (possibly qualified) ptr type
32-
const Type* get_pointee_type(IrArena*, const Type*);
39+
const Type* shd_get_pointee_type(IrArena*, const Type*);
40+
41+
String shd_get_address_space_name(AddressSpace);
42+
/// Returns false iff pointers in that address space can contain different data at the same address
43+
/// (amongst threads in the same subgroup)
44+
bool shd_is_addr_space_uniform(IrArena*, AddressSpace);
45+
46+
String shd_get_type_name(IrArena* arena, const Type* t);
3347

3448
const Type* maybe_multiple_return(IrArena* arena, Nodes types);
3549
Nodes unwrap_multiple_yield_types(IrArena* arena, const Type* type);
3650

3751
/// Collects the annotated types in the list of variables
3852
/// NB: this is different from get_values_types, that function uses node.type, whereas this one uses node.payload.var.type
3953
/// This means this function works in untyped modules where node.type is NULL.
40-
Nodes get_param_types(IrArena* arena, Nodes variables);
54+
Nodes shd_get_param_types(IrArena* arena, Nodes variables);
4155

42-
Nodes get_values_types(IrArena*, Nodes);
56+
Nodes shd_get_values_types(IrArena*, Nodes);
4357

4458
// Qualified type helpers
4559
/// Ensures an operand has divergence-annotated type and extracts it
46-
const Type* get_unqualified_type(const Type*);
47-
bool is_qualified_type_uniform(const Type*);
48-
bool deconstruct_qualified_type(const Type**);
60+
const Type* shd_get_unqualified_type(const Type*);
61+
bool shd_is_qualified_type_uniform(const Type*);
62+
bool shd_deconstruct_qualified_type(const Type**);
4963

5064
const Type* shd_as_qualified_type(const Type* type, bool uniform);
5165

52-
Nodes strip_qualifiers(IrArena*, Nodes);
53-
Nodes add_qualifiers(IrArena*, Nodes, bool);
66+
Nodes shd_strip_qualifiers(IrArena*, Nodes);
67+
Nodes shd_add_qualifiers(IrArena*, Nodes, bool);
5468

5569
// Pack (vector) type helpers
5670
const Type* get_packed_type_element(const Type*);

src/backend/c/emit_c.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ void c_emit_global_variable_definition(Emitter* emitter, AddressSpace as, String
189189
break;
190190
}
191191
default: {
192-
prefix = shd_format_string_arena(emitter->arena->arena, "/* %s */", get_address_space_name(as));
193-
shd_warn_print("warning: address space %s not supported in CUDA for global variables\n", get_address_space_name(as));
192+
prefix = shd_format_string_arena(emitter->arena->arena, "/* %s */", shd_get_address_space_name(as));
193+
shd_warn_print("warning: address space %s not supported in CUDA for global variables\n", shd_get_address_space_name(as));
194194
break;
195195
}
196196
}
@@ -209,8 +209,8 @@ void c_emit_global_variable_definition(Emitter* emitter, AddressSpace as, String
209209
break;
210210
}
211211
default: {
212-
prefix = shd_format_string_arena(emitter->arena->arena, "/* %s */", get_address_space_name(as));
213-
shd_warn_print("warning: address space %s not supported in GLSL for global variables\n", get_address_space_name(as));
212+
prefix = shd_format_string_arena(emitter->arena->arena, "/* %s */", shd_get_address_space_name(as));
213+
shd_warn_print("warning: address space %s not supported in GLSL for global variables\n", shd_get_address_space_name(as));
214214
break;
215215
}
216216
}

src/backend/c/emit_c_control_flow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static void emit_loop(Emitter* emitter, FnEmitter* fn, Printer* p, Loop loop) {
148148
arr[i] = unique_name(emitter->arena, "phi");
149149
}
150150
Strings param_names = shd_strings(emitter->arena, variables.count, arr);
151-
Strings eparams = emit_variable_declarations(emitter, fn, p, NULL, &param_names, get_param_types(emitter->arena, params), true, &loop.initial_args);
151+
Strings eparams = emit_variable_declarations(emitter, fn, p, NULL, &param_names, shd_get_param_types(emitter->arena, params), true, &loop.initial_args);
152152
for (size_t i = 0; i < params.count; i++)
153153
register_emitted(&sub_emiter, fn, params.nodes[i], term_from_cvalue(eparams.strings[i]));
154154

src/backend/c/emit_c_value.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ CTerm c_bind_intermediary_result(Emitter* emitter, Printer* p, const Type* t, CT
246246

247247
static const Type* get_first_op_scalar_type(Nodes ops) {
248248
const Type* t = shd_first(ops)->type;
249-
deconstruct_qualified_type(&t);
249+
shd_deconstruct_qualified_type(&t);
250250
deconstruct_maybe_packed_type(&t);
251251
return t;
252252
}
@@ -495,7 +495,7 @@ static CTerm emit_primop(Emitter* emitter, FnEmitter* fn, Printer* p, const Node
495495
const Node* offset = prim_op->operands.nodes[1];
496496
CValue c_offset = to_cvalue(emitter, c_emit_value(emitter, fn, offset));
497497
if (emitter->config.dialect == CDialect_GLSL) {
498-
if (get_unqualified_type(offset->type)->payload.int_type.width == IntTy64)
498+
if (shd_get_unqualified_type(offset->type)->payload.int_type.width == IntTy64)
499499
c_offset = shd_format_string_arena(arena->arena, "int(%s)", c_offset);
500500
}
501501
term = term_from_cvalue(shd_format_string_arena(arena->arena, "(%s %s %s)", src, prim_op->op == lshift_op ? "<<" : ">>", c_offset));
@@ -527,7 +527,7 @@ static CTerm emit_primop(Emitter* emitter, FnEmitter* fn, Printer* p, const Node
527527
}
528528
case convert_op: {
529529
CTerm src = c_emit_value(emitter, fn, shd_first(prim_op->operands));
530-
const Type* src_type = get_unqualified_type(shd_first(prim_op->operands)->type);
530+
const Type* src_type = shd_get_unqualified_type(shd_first(prim_op->operands)->type);
531531
const Type* dst_type = shd_first(prim_op->type_arguments);
532532
if (emitter->config.dialect == CDialect_GLSL) {
533533
if (is_glsl_scalar_type(src_type) && is_glsl_scalar_type(dst_type)) {
@@ -543,7 +543,7 @@ static CTerm emit_primop(Emitter* emitter, FnEmitter* fn, Printer* p, const Node
543543
}
544544
case reinterpret_op: {
545545
CTerm src_value = c_emit_value(emitter, fn, shd_first(prim_op->operands));
546-
const Type* src_type = get_unqualified_type(shd_first(prim_op->operands)->type);
546+
const Type* src_type = shd_get_unqualified_type(shd_first(prim_op->operands)->type);
547547
const Type* dst_type = shd_first(prim_op->type_arguments);
548548
switch (emitter->config.dialect) {
549549
case CDialect_CUDA:
@@ -625,7 +625,7 @@ static CTerm emit_primop(Emitter* emitter, FnEmitter* fn, Printer* p, const Node
625625
term = term_from_cvalue(dst);
626626
}
627627

628-
const Type* t = get_unqualified_type(shd_first(prim_op->operands)->type);
628+
const Type* t = shd_get_unqualified_type(shd_first(prim_op->operands)->type);
629629
for (size_t i = (insert ? 2 : 1); i < prim_op->operands.count; i++) {
630630
const Node* index = prim_op->operands.nodes[i];
631631
const IntLiteral* static_index = shd_resolve_to_int_literal(index);
@@ -678,8 +678,8 @@ static CTerm emit_primop(Emitter* emitter, FnEmitter* fn, Printer* p, const Node
678678
String rhs_e = to_cvalue(emitter, c_emit_value(emitter, fn, prim_op->operands.nodes[1]));
679679
const Type* lhs_t = lhs->type;
680680
const Type* rhs_t = rhs->type;
681-
bool lhs_u = deconstruct_qualified_type(&lhs_t);
682-
bool rhs_u = deconstruct_qualified_type(&rhs_t);
681+
bool lhs_u = shd_deconstruct_qualified_type(&lhs_t);
682+
bool rhs_u = shd_deconstruct_qualified_type(&rhs_t);
683683
size_t left_size = lhs_t->payload.pack_type.width;
684684
// size_t total_size = lhs_t->payload.pack_type.width + rhs_t->payload.pack_type.width;
685685
String suffixes = "xyzw";
@@ -793,13 +793,13 @@ static CTerm emit_ptr_composite_element(Emitter* emitter, FnEmitter* fn, Printer
793793
CTerm acc = c_emit_value(emitter, fn, lea.ptr);
794794

795795
const Type* src_qtype = lea.ptr->type;
796-
bool uniform = is_qualified_type_uniform(src_qtype);
797-
const Type* curr_ptr_type = get_unqualified_type(src_qtype);
796+
bool uniform = shd_is_qualified_type_uniform(src_qtype);
797+
const Type* curr_ptr_type = shd_get_unqualified_type(src_qtype);
798798
assert(curr_ptr_type->tag == PtrType_TAG);
799799

800-
const Type* pointee_type = get_pointee_type(arena, curr_ptr_type);
800+
const Type* pointee_type = shd_get_pointee_type(arena, curr_ptr_type);
801801
const Node* selector = lea.index;
802-
uniform &= is_qualified_type_uniform(selector->type);
802+
uniform &= shd_is_qualified_type_uniform(selector->type);
803803
switch (is_type(pointee_type)) {
804804
case ArrType_TAG: {
805805
CTerm index = c_emit_value(emitter, fn, selector);
@@ -859,8 +859,8 @@ static CTerm emit_ptr_array_element_offset(Emitter* emitter, FnEmitter* fn, Prin
859859
CTerm acc = c_emit_value(emitter, fn, lea.ptr);
860860

861861
const Type* src_qtype = lea.ptr->type;
862-
bool uniform = is_qualified_type_uniform(src_qtype);
863-
const Type* curr_ptr_type = get_unqualified_type(src_qtype);
862+
bool uniform = shd_is_qualified_type_uniform(src_qtype);
863+
const Type* curr_ptr_type = shd_get_unqualified_type(src_qtype);
864864
assert(curr_ptr_type->tag == PtrType_TAG);
865865

866866
const IntLiteral* offset_static_value = shd_resolve_to_int_literal(lea.offset);
@@ -869,9 +869,9 @@ static CTerm emit_ptr_array_element_offset(Emitter* emitter, FnEmitter* fn, Prin
869869
// we sadly need to drop to the value level (aka explicit pointer arithmetic) to do this
870870
// this means such code is never going to be legal in GLSL
871871
// also the cast is to account for our arrays-in-structs hack
872-
const Type* pointee_type = get_pointee_type(arena, curr_ptr_type);
872+
const Type* pointee_type = shd_get_pointee_type(arena, curr_ptr_type);
873873
acc = term_from_cvalue(shd_format_string_arena(arena->arena, "((%s) &(%s)[%s])", c_emit_type(emitter, curr_ptr_type, NULL), to_cvalue(emitter, acc), to_cvalue(emitter, offset)));
874-
uniform &= is_qualified_type_uniform(lea.offset->type);
874+
uniform &= shd_is_qualified_type_uniform(lea.offset->type);
875875
}
876876

877877
if (emitter->config.dialect == CDialect_ISPC)
@@ -893,7 +893,7 @@ static CTerm emit_alloca(Emitter* emitter, Printer* p, const Type* instr) {
893893
CTerm variable = (CTerm) { .value = NULL, .var = variable_name };
894894
c_emit_variable_declaration(emitter, p, get_allocated_type(instr), variable_name, true, NULL);
895895
if (emitter->config.dialect == CDialect_ISPC) {
896-
variable = ispc_varying_ptr_helper(emitter, p, get_unqualified_type(instr->type), variable);
896+
variable = ispc_varying_ptr_helper(emitter, p, shd_get_unqualified_type(instr->type), variable);
897897
}
898898
return variable;
899899
}
@@ -927,8 +927,8 @@ static CTerm emit_instruction(Emitter* emitter, FnEmitter* fn, Printer* p, const
927927
Store payload = instruction->payload.store;
928928
c_emit_mem(emitter, fn, payload.mem);
929929
const Type* addr_type = payload.ptr->type;
930-
bool addr_uniform = deconstruct_qualified_type(&addr_type);
931-
bool value_uniform = is_qualified_type_uniform(payload.value->type);
930+
bool addr_uniform = shd_deconstruct_qualified_type(&addr_type);
931+
bool value_uniform = shd_is_qualified_type_uniform(payload.value->type);
932932
assert(addr_type->tag == PtrType_TAG);
933933
CAddr dereferenced = deref_term(emitter, c_emit_value(emitter, fn, payload.ptr));
934934
CValue cvalue = to_cvalue(emitter, c_emit_value(emitter, fn, payload.value));

src/backend/spirv/emit_spv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void emit_function(Emitter* emitter, const Node* node) {
9494
const Type* param_type = param->payload.param.type;
9595
SpvId param_id = spvb_parameter(fn_builder.base, spv_emit_type(emitter, param_type));
9696
spv_register_emitted(emitter, false, param, param_id);
97-
deconstruct_qualified_type(&param_type);
97+
shd_deconstruct_qualified_type(&param_type);
9898
if (param_type->tag == PtrType_TAG && param_type->payload.ptr_type.address_space == AsGlobal) {
9999
spvb_decorate(emitter->file_builder, param_id, SpvDecorationAliased, 0, NULL);
100100
}

src/backend/spirv/emit_spv_control_flow.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ static void emit_match(Emitter* emitter, FnBuilder* fn_builder, BBBuilder bb_bui
5252
spv_emit_mem(emitter, fn_builder, match.mem);
5353
SpvId join_bb_id = spv_find_emitted(emitter, fn_builder, match.tail);
5454

55-
assert(get_unqualified_type(match.inspect->type)->tag == Int_TAG);
55+
assert(shd_get_unqualified_type(match.inspect->type)->tag == Int_TAG);
5656
SpvId inspectee = spv_emit_value(emitter, fn_builder, match.inspect);
5757

5858
SpvId default_id = spv_find_emitted(emitter, fn_builder, match.default_case);
5959

6060
const Type* inspectee_t = match.inspect->type;
61-
deconstruct_qualified_type(&inspectee_t);
61+
shd_deconstruct_qualified_type(&inspectee_t);
6262
assert(inspectee_t->tag == Int_TAG);
6363
size_t literal_width = inspectee_t->payload.int_type.width == IntTy64 ? 2 : 1;
6464
size_t literal_case_entry_size = literal_width + 1;
@@ -93,7 +93,7 @@ static void emit_loop(Emitter* emitter, FnBuilder* fn_builder, BBBuilder bb_buil
9393
Nodes body_params = get_abstraction_params(loop_instr.body);
9494
LARRAY(SpvbPhi*, loop_continue_phis, body_params.count);
9595
for (size_t i = 0; i < body_params.count; i++) {
96-
SpvId loop_param_type = spv_emit_type(emitter, get_unqualified_type(body_params.nodes[i]->type));
96+
SpvId loop_param_type = spv_emit_type(emitter, shd_get_unqualified_type(body_params.nodes[i]->type));
9797

9898
SpvId continue_phi_id = spvb_fresh_id(emitter->file_builder);
9999
SpvbPhi* continue_phi = spvb_add_phi(continue_builder, loop_param_type, continue_phi_id);

src/backend/spirv/emit_spv_type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ SpvStorageClass spv_emit_addr_space(Emitter* emitter, AddressSpace address_space
3232
case AsUniformConstant: return SpvStorageClassUniformConstant;
3333

3434
default: {
35-
shd_error_print("Cannot emit address space %s.\n", get_address_space_name(address_space));
35+
shd_error_print("Cannot emit address space %s.\n", shd_get_address_space_name(address_space));
3636
shd_error_die();
3737
SHADY_UNREACHABLE;
3838
}
@@ -215,7 +215,7 @@ SpvId spv_emit_type(Emitter* emitter, const Type* type) {
215215
case Type_JoinPointType_TAG: shd_error("These must be lowered beforehand")
216216
}
217217

218-
if (is_data_type(type)) {
218+
if (shd_is_data_type(type)) {
219219
if (type->tag == PtrType_TAG && type->payload.ptr_type.address_space == AsGlobal) {
220220
//TypeMemLayout elem_mem_layout = get_mem_layout(emitter->arena, type->payload.ptr_type.pointed_type);
221221
//spvb_decorate(emitter->file_builder, new, SpvDecorationArrayStride, 1, (uint32_t[]) {elem_mem_layout.size_in_bytes});

0 commit comments

Comments
 (0)