Skip to content

Commit

Permalink
prefix some things in check.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugobros3 committed Oct 9, 2024
1 parent f7e7850 commit b1f59cd
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 61 deletions.
1 change: 0 additions & 1 deletion include/shady/ir/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ String string(IrArena*, const char*);
// see also: format_string in util.h
String shd_fmt_string_irarena(IrArena* arena, const char* str, ...);
String unique_name(IrArena*, const char* base_name);
String name_type_safe(IrArena*, const Type*);

#endif
6 changes: 4 additions & 2 deletions include/shady/ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ static inline const Node* unit_type(IrArena* arena) {

Type* nominal_type(Module*, Nodes annotations, String name);

const Type* get_actual_mask_type(IrArena* arena);
const Type* shd_get_actual_mask_type(IrArena* arena);

String get_address_space_name(AddressSpace);
/// Returns false iff pointers in that address space can contain different data at the same address
/// (amongst threads in the same subgroup)
bool is_addr_space_uniform(IrArena*, AddressSpace);
bool shd_is_addr_space_uniform(IrArena*, AddressSpace);

String shd_get_type_name(IrArena* arena, const Type* t);

/// Is this a type that a value in the language can have ?
bool is_value_type(const Type*);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/c/emit_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void c_emit_global_variable_definition(Emitter* emitter, AddressSpace as, String

// ISPC wants uniform/varying annotations
if (emitter->config.dialect == CDialect_ISPC) {
bool uniform = is_addr_space_uniform(emitter->arena, as);
bool uniform = shd_is_addr_space_uniform(emitter->arena, as);
if (uniform)
name = shd_format_string_arena(emitter->arena->arena, "uniform %s", name);
else
Expand Down
6 changes: 3 additions & 3 deletions src/backend/c/emit_c_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static CTerm c_emit_value_(Emitter* emitter, FnEmitter* fn, Printer* p, const No
c_emit_decl(emitter, decl);

if (emitter->config.dialect == CDialect_ISPC && decl->tag == GlobalVariable_TAG) {
if (!is_addr_space_uniform(emitter->arena, decl->payload.global_variable.address_space) && !shd_is_decl_builtin(
if (!shd_is_addr_space_uniform(emitter->arena, decl->payload.global_variable.address_space) && !shd_is_decl_builtin(
decl)) {
assert(fn && "ISPC backend cannot statically refer to a varying variable");
return ispc_varying_ptr_helper(emitter, fn->instruction_printers[0], decl->type, *lookup_existing_term(emitter, NULL, decl));
Expand Down Expand Up @@ -933,7 +933,7 @@ static CTerm emit_instruction(Emitter* emitter, FnEmitter* fn, Printer* p, const
CAddr dereferenced = deref_term(emitter, c_emit_value(emitter, fn, payload.ptr));
CValue cvalue = to_cvalue(emitter, c_emit_value(emitter, fn, payload.value));
// ISPC lets you broadcast to a uniform address space iff the address is non-uniform, otherwise we need to do this
if (emitter->config.dialect == CDialect_ISPC && addr_uniform && is_addr_space_uniform(a, addr_type->payload.ptr_type.address_space) && !value_uniform)
if (emitter->config.dialect == CDialect_ISPC && addr_uniform && shd_is_addr_space_uniform(a, addr_type->payload.ptr_type.address_space) && !value_uniform)
cvalue = shd_format_string_arena(emitter->arena->arena, "extract(%s, count_trailing_zeros(lanemask()))", cvalue);

shd_print(p, "\n%s = %s;", dereferenced, cvalue);
Expand Down Expand Up @@ -987,7 +987,7 @@ static bool can_appear_at_top_level(Emitter* emitter, const Node* node) {
if (node->tag == RefDecl_TAG) {
const Node* decl = node->payload.ref_decl.decl;
if (decl->tag == GlobalVariable_TAG)
if (!is_addr_space_uniform(emitter->arena, decl->payload.global_variable.address_space) && !shd_is_decl_builtin(
if (!shd_is_addr_space_uniform(emitter->arena, decl->payload.global_variable.address_space) && !shd_is_decl_builtin(
decl))
//if (is_value(node) && !is_qualified_type_uniform(node->type))
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/backend/spirv/emit_spv_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static SpvId emit_ext_instr(Emitter* emitter, FnBuilder* fn_builder, BBBuilder b
assert(instr.operands.count == 2);
// SpvId scope_subgroup = spv_emit_value(emitter, fn_builder, int32_literal(emitter->arena, SpvScopeSubgroup));
// ad-hoc extension for my sanity
if (get_unqualified_type(instr.result_t) == get_actual_mask_type(emitter->arena)) {
if (get_unqualified_type(instr.result_t) == shd_get_actual_mask_type(emitter->arena)) {
const Type* i32x4 = pack_type(emitter->arena, (PackType) { .width = 4, .element_type = shd_uint32_type(emitter->arena) });
SpvId raw_result = spvb_group_ballot(bb_builder, spv_emit_type(emitter, i32x4), spv_emit_value(emitter, fn_builder, instr.operands.nodes[1]), spv_emit_value(emitter, fn_builder, shd_first(instr.operands)));
// TODO: why are we doing this in SPIR-V and not the IR ?
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/slim/infer.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static const Node* infer_value(Context* ctx, const Node* node, const Type* expec
bool expect_uniform = false;
if (expected_type) {
expect_uniform = deconstruct_qualified_type(&expected_type);
assert(is_subtype(expected_type, type));
assert(shd_is_subtype(expected_type, type));
}
return infer(ctx, node->payload.constrained.value, shd_as_qualified_type(type, expect_uniform));
}
Expand Down Expand Up @@ -237,7 +237,7 @@ static const Node* infer_value(Context* ctx, const Node* node, const Type* expec
const Node* elem_type = infer(ctx, node->payload.composite.type, NULL);
bool uniform = false;
if (elem_type && expected_type) {
assert(is_subtype(get_unqualified_type(expected_type), elem_type));
assert(shd_is_subtype(get_unqualified_type(expected_type), elem_type));
} else if (expected_type) {
uniform = deconstruct_qualified_type(&elem_type);
elem_type = expected_type;
Expand Down Expand Up @@ -266,7 +266,7 @@ static const Node* infer_value(Context* ctx, const Node* node, const Type* expec
assert(composite_t);
bool uniform = false;
if (composite_t && expected_type) {
assert(is_subtype(get_unqualified_type(expected_type), composite_t));
assert(shd_is_subtype(get_unqualified_type(expected_type), composite_t));
} else if (expected_type) {
uniform = deconstruct_qualified_type(&composite_t);
composite_t = expected_type;
Expand Down Expand Up @@ -300,7 +300,7 @@ static const Node* infer_case(Context* ctx, const Node* node, Nodes inferred_arg
// and do not use the provided param type if it is an untyped ptr
if (!param_type || param_type->tag != PtrType_TAG || param_type->payload.ptr_type.pointed_type)
param_type = inferred_arg_type.nodes[i];
assert(is_subtype(param_type, inferred_arg_type.nodes[i]));
assert(shd_is_subtype(param_type, inferred_arg_type.nodes[i]));
nparams[i] = param(a, param_type, old_param->name);
shd_register_processed(&body_context.rewriter, node->payload.basic_block.params.nodes[i], nparams[i]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/shady/analysis/verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void verify_nominal_node(const Node* fn, const Node* n) {
break;
}
case BasicBlock_TAG: {
assert(is_subtype(noret_type(n->arena), n->payload.basic_block.body->type));
assert(shd_is_subtype(noret_type(n->arena), n->payload.basic_block.body->type));
break;
}
case NominalType_TAG: {
Expand All @@ -91,7 +91,7 @@ static void verify_nominal_node(const Node* fn, const Node* n) {
const Type* t = n->payload.constant.value->type;
bool u = deconstruct_qualified_type(&t);
assert(u);
assert(is_subtype(n->payload.constant.type_hint, t));
assert(shd_is_subtype(n->payload.constant.type_hint, t));
}
break;
}
Expand All @@ -100,7 +100,7 @@ static void verify_nominal_node(const Node* fn, const Node* n) {
const Type* t = n->payload.global_variable.init->type;
bool u = deconstruct_qualified_type(&t);
assert(u);
assert(is_subtype(n->payload.global_variable.type, t));
assert(shd_is_subtype(n->payload.global_variable.type, t));
}
break;
}
Expand Down
Loading

0 comments on commit b1f59cd

Please sign in to comment.