Skip to content

Commit 60bd521

Browse files
committed
address spaces are no longer inherently logical or physical
1 parent e35eb46 commit 60bd521

32 files changed

+197
-209
lines changed

include/shady/grammar.json

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,32 @@
22
"address-spaces": [
33
{
44
"name": "Generic",
5-
"llvm-id": 0,
6-
"physical": true
5+
"llvm-id": 0
76
},
87
{
9-
"name": "GlobalPhysical",
8+
"name": "Global",
109
"description": "Global memory, all threads see the same data (not necessarily consistent!)",
11-
"llvm-id": 1,
12-
"physical": true
10+
"llvm-id": 1
1311
},
1412
{
15-
"name": "SharedPhysical",
13+
"name": "Shared",
1614
"description": "Points into workgroup-private memory (aka shared memory)",
17-
"llvm-id": 3,
18-
"physical": true
15+
"llvm-id": 3
1916
},
2017
{
21-
"name": "SubgroupPhysical",
18+
"name": "Subgroup",
2219
"description": [
2320
"Points into subgroup-private memory",
2421
"All threads in a subgroup see the same contents for the same address, but threads in different subgroups see different data.",
2522
"Needs to be lowered to something else since targets do not understand this" ],
26-
"llvm-id": 9,
27-
"physical": true
23+
"llvm-id": 9
2824
},
2925
{
30-
"name": "PrivatePhysical",
26+
"name": "Private",
3127
"description": [
3228
"Points into thread-private memory (all threads see different contents for the same address)"
3329
],
34-
"llvm-id": 5,
35-
"physical": true
36-
},
37-
{
38-
"name": "GlobalLogical",
39-
"llvm-id": 388
40-
},
41-
{
42-
"name": "SharedLogical",
43-
"llvm-id": 387
44-
},
45-
{
46-
"name": "SubgroupLogical",
47-
"llvm-id": 386
48-
},
49-
{
50-
"name": "PrivateLogical",
51-
"llvm-id": 385
30+
"llvm-id": 5
5231
},
5332
{
5433
"name": "Input",
@@ -74,8 +53,8 @@
7453
"llvm-id": 392
7554
},
7655
{
77-
"name": "FunctionLogical",
78-
"description": "Weird SPIR-V nonsense: this is like PrivateLogical, but with non-static lifetimes (ie function lifetime)",
56+
"name": "Function",
57+
"description": "Weird SPIR-V nonsense: this is like Private, but with non-static lifetimes (ie function lifetime)",
7958
"llvm-id": 393
8059
},
8160
{

include/shady/ir.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ typedef struct {
7373
bool validate_builtin_types; // do @Builtins variables need to match their type in builtins.h ?
7474
bool is_simt;
7575

76-
bool allow_subgroup_memory;
77-
bool allow_shared_memory;
76+
struct {
77+
bool physical;
78+
bool allowed;
79+
} address_spaces[NumAddressSpaces];
7880

7981
struct {
8082
/// Selects which type the subgroup intrinsic primops use to manipulate masks
@@ -278,7 +280,6 @@ typedef struct CompilerConfig_ {
278280
struct {
279281
bool spv_shuffle_instead_of_broadcast_first;
280282
bool force_join_point_lifting;
281-
bool assume_no_physical_global_ptrs;
282283
bool restructure_everything;
283284
bool recover_structure;
284285
} hacks;

samples/fib.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ fn fib varying u32(varying u32 n) {
55
}
66

77
@Builtin("SubgroupLocalInvocationId")
8-
input u32 subgroup_local_id;
8+
var input u32 subgroup_local_id;
99

1010
@Builtin("SubgroupId")
11-
uniform input u32 subgroup_id;
11+
var uniform input u32 subgroup_id;
1212

1313
@EntryPoint("Compute") @WorkgroupSize(32, 1, 1) fn main() {
1414
val n = subgroup_local_id % u32 16;

src/driver/cli.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ F(lower.emulate_physical_memory, emulate-physical-memory) \
9393
F(lower.emulate_generic_ptrs, emulate-generic-pointers) \
9494
F(dynamic_scheduling, dynamic-scheduling) \
9595
F(hacks.force_join_point_lifting, lift-join-points) \
96-
F(hacks.assume_no_physical_global_ptrs, assume-no-physical-global-ptrs) \
9796
F(logging.print_internal, print-internal) \
9897
F(logging.print_generated, print-builtin) \
9998
F(logging.print_generated, print-generated) \

src/frontends/llvm/l2s_annotations.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ static const Node* assert_and_strip_fn_addr(const Node* fn) {
2929
return fn;
3030
}
3131

32+
static const Node* look_past_stuff(const Node* thing) {
33+
if (thing->tag == Constant_TAG) {
34+
const Node* instr = thing->payload.constant.instruction;
35+
assert(instr->tag == PrimOp_TAG);
36+
thing = instr;
37+
}
38+
if (thing->tag == PrimOp_TAG) {
39+
switch (thing->payload.prim_op.op) {
40+
case reinterpret_op:
41+
case convert_op:
42+
case lea_op: thing = first(thing->payload.prim_op.operands); break;
43+
default: assert(false);
44+
}
45+
}
46+
return thing;
47+
}
48+
3249
void process_llvm_annotations(Parser* p, LLVMValueRef global) {
3350
IrArena* a = get_module_arena(p->dst);
3451
const Type* t = convert_type(p, LLVMGlobalGetValueType(global));
@@ -39,19 +56,11 @@ void process_llvm_annotations(Parser* p, LLVMValueRef global) {
3956
assert(value->tag == Composite_TAG && value->payload.composite.contents.count == arr_size);
4057
for (size_t i = 0; i < arr_size; i++) {
4158
const Node* entry = value->payload.composite.contents.nodes[i];
59+
entry = look_past_stuff(entry);
4260
assert(entry->tag == Composite_TAG);
4361
const Node* annotation_payload = entry->payload.composite.contents.nodes[1];
4462
// eliminate dummy reinterpret cast
45-
if (annotation_payload->tag == Constant_TAG) {
46-
const Node* instr = annotation_payload->payload.constant.instruction;
47-
assert(instr->tag == PrimOp_TAG);
48-
switch (instr->payload.prim_op.op) {
49-
case reinterpret_op:
50-
case convert_op:
51-
case lea_op: annotation_payload = first(instr->payload.prim_op.operands); break;
52-
default: assert(false);
53-
}
54-
}
63+
annotation_payload = look_past_stuff(annotation_payload);
5564
if (annotation_payload->tag == RefDecl_TAG) {
5665
annotation_payload = annotation_payload->payload.ref_decl.decl;
5766
}

src/frontends/llvm/l2s_instr.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ EmittedInstr convert_instruction(Parser* p, Node* fn_or_bb, BodyBuilder* b, LLVM
219219
case LLVMAlloca: {
220220
assert(t->tag == PtrType_TAG);
221221
const Type* allocated_t = convert_type(p, LLVMGetAllocatedType(instr));
222-
const Type* allocated_ptr_t = ptr_type(a, (PtrType) { .pointed_type = allocated_t, .address_space = AsPrivatePhysical });
222+
const Type* allocated_ptr_t = ptr_type(a, (PtrType) { .pointed_type = allocated_t, .address_space = AsPrivate });
223223
r = first(bind_instruction_explicit_result_types(b, prim_op_helper(a, alloca_op, singleton(allocated_t), empty(a)), singleton(allocated_ptr_t), NULL));
224224
if (UNTYPED_POINTERS) {
225-
const Type* untyped_ptr_t = ptr_type(a, (PtrType) { .pointed_type = unit_type(a), .address_space = AsPrivatePhysical });
225+
const Type* untyped_ptr_t = ptr_type(a, (PtrType) { .pointed_type = unit_type(a), .address_space = AsPrivate });
226226
r = first(bind_instruction_outputs_count(b, prim_op_helper(a, reinterpret_op, singleton(untyped_ptr_t), singleton(r)), 1, NULL));
227227
}
228228
r = prim_op_helper(a, convert_op, singleton(t), singleton(r));
@@ -308,24 +308,13 @@ EmittedInstr convert_instruction(Parser* p, Node* fn_or_bb, BodyBuilder* b, LLVM
308308
if (src_t->tag == PtrType_TAG && t->tag == PtrType_TAG) {
309309
if ((t->payload.ptr_type.address_space == AsGeneric)) {
310310
switch (src_t->payload.ptr_type.address_space) {
311-
case AsPrivatePhysical:
312-
case AsSubgroupPhysical:
313-
case AsSharedPhysical:
314-
case AsGlobalPhysical:
315-
op = convert_op;
316-
break;
317311
case AsGeneric: // generic-to-generic isn't a conversion.
318312
break;
319313
default: {
320-
warn_print("Cannot cast address space %s to Generic! Ignoring.\n", get_address_space_name(src_t->payload.ptr_type.address_space));
321-
r = quote_helper(a, singleton(src));
322-
goto shortcut;
314+
op = convert_op;
315+
break;
323316
}
324317
}
325-
} else if (!is_physical_as(t->payload.ptr_type.address_space)) {
326-
warn_print("Cannot cast address space %s since it's non-physical. Ignoring.\n", get_address_space_name(src_t->payload.ptr_type.address_space));
327-
r = quote_helper(a, singleton(src));
328-
goto shortcut;
329318
}
330319
} else {
331320
assert(opcode != LLVMAddrSpaceCast);

src/frontends/slim/parser.c

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -996,30 +996,48 @@ static const Node* accept_fn_decl(ctxparams, Nodes annotations) {
996996
}
997997

998998
static const Node* accept_global_var_decl(ctxparams, Nodes annotations) {
999-
AddressSpace as;
1000-
if (accept_token(ctx, private_tok))
1001-
as = AsPrivateLogical;
1002-
else if (accept_token(ctx, shared_tok))
1003-
as = AsSharedLogical;
1004-
else if (accept_token(ctx, subgroup_tok))
1005-
as = AsSubgroupLogical;
1006-
else if (accept_token(ctx, global_tok))
1007-
as = AsGlobalLogical;
1008-
else if (accept_token(ctx, extern_tok))
1009-
as = AsExternal;
1010-
else if (accept_token(ctx, input_tok))
1011-
as = AsInput;
1012-
else if (accept_token(ctx, output_tok))
1013-
as = AsOutput;
1014-
else if (accept_token(ctx, uniform_tok)) {
1015-
if (accept_token(ctx, input_tok)) {
999+
if (!accept_token(ctx, var_tok))
1000+
return NULL;
1001+
1002+
AddressSpace as = NumAddressSpaces;
1003+
bool uniform = false, logical = false;
1004+
while (true) {
1005+
AddressSpace nas = accept_address_space(ctx);
1006+
if (nas != NumAddressSpaces) {
1007+
if (as != NumAddressSpaces && as != nas) {
1008+
error("Conflicting address spaces for definition: %s and %s.\n", get_address_space_name(as), get_address_space_name(nas));
1009+
}
1010+
as = nas;
1011+
continue;
1012+
}
1013+
if (accept_token(ctx, logical_tok)) {
1014+
logical = true;
1015+
continue;
1016+
}
1017+
if (accept_token(ctx, uniform_tok)) {
1018+
uniform = true;
1019+
continue;
1020+
}
1021+
break;
1022+
}
1023+
1024+
if (as == NumAddressSpaces) {
1025+
error("Address space required for global variable declaration.\n");
1026+
}
1027+
1028+
if (uniform) {
1029+
if (as == AsInput)
10161030
as = AsUInput;
1017-
} else {
1018-
expect(false && "expected 'input'");
1019-
return NULL;
1031+
else {
1032+
error("'uniform' can only be used with 'input' currently.\n");
10201033
}
1021-
} else
1022-
return NULL;
1034+
}
1035+
1036+
if (logical) {
1037+
annotations = append_nodes(arena, annotations, annotation(arena, (Annotation) {
1038+
.name = "Logical"
1039+
}));
1040+
}
10231041

10241042
const Type* type = accept_unqualified_type(ctx);
10251043
expect(type);

src/frontends/slim/token.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TEXT_TOKEN(input) \
2626
TEXT_TOKEN(output) \
2727
TOKEN(extern, "extern") \
2828
TEXT_TOKEN(generic) \
29+
TEXT_TOKEN(logical) \
2930
TEXT_TOKEN(var) \
3031
TEXT_TOKEN(val) \
3132
TEXT_TOKEN(let) \

src/frontends/spirv/s2s.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,33 +203,36 @@ AddressSpace convert_storage_class(SpvStorageClass class) {
203203
switch (class) {
204204
case SpvStorageClassInput: return AsInput;
205205
case SpvStorageClassOutput: return AsOutput;
206-
case SpvStorageClassWorkgroup: return AsSharedPhysical;
207-
case SpvStorageClassCrossWorkgroup: return AsGlobalPhysical;
208-
case SpvStorageClassPhysicalStorageBuffer: return AsGlobalPhysical;
209-
case SpvStorageClassPrivate: return AsPrivatePhysical;
210-
case SpvStorageClassFunction: return AsPrivatePhysical;
206+
case SpvStorageClassWorkgroup: return AsShared;
207+
case SpvStorageClassCrossWorkgroup: return AsGlobal;
208+
case SpvStorageClassPhysicalStorageBuffer: return AsGlobal;
209+
case SpvStorageClassPrivate: return AsPrivate;
210+
case SpvStorageClassFunction: return AsPrivate;
211211
case SpvStorageClassGeneric: return AsGeneric;
212212
case SpvStorageClassPushConstant: return AsPushConstant;
213213
case SpvStorageClassAtomicCounter:
214-
error("TODO");
214+
break;
215215
case SpvStorageClassImage: return AsImage;
216-
error("TODO");
217-
case SpvStorageClassStorageBuffer: return AsGlobalLogical;
216+
break;
217+
case SpvStorageClassStorageBuffer: return AsShaderStorageBufferObject;
218218
case SpvStorageClassUniformConstant:
219-
case SpvStorageClassUniform: return AsGlobalPhysical; // TODO: should probably depend on CL/VK flavours!
219+
case SpvStorageClassUniform: return AsGlobal; // TODO: should probably depend on CL/VK flavours!
220220
case SpvStorageClassCallableDataKHR:
221221
case SpvStorageClassIncomingCallableDataKHR:
222222
case SpvStorageClassRayPayloadKHR:
223223
case SpvStorageClassHitAttributeKHR:
224224
case SpvStorageClassIncomingRayPayloadKHR:
225225
case SpvStorageClassShaderRecordBufferKHR:
226-
error("Unsupported");
226+
break;
227227
case SpvStorageClassCodeSectionINTEL:
228228
case SpvStorageClassDeviceOnlyINTEL:
229229
case SpvStorageClassHostOnlyINTEL:
230230
case SpvStorageClassMax:
231-
error("Unsupported");
231+
break;
232+
default:
233+
break;
232234
}
235+
error("s2s: Unsupported storage class: %d\n", class);
233236
}
234237

235238
typedef struct {

src/shady/api/generator_grammar.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ static void generate_address_spaces(Growy* g, json_object* address_spaces) {
1010
}
1111
growy_append_formatted(g, "\tNumAddressSpaces,\n");
1212
growy_append_formatted(g, "} AddressSpace;\n\n");
13-
14-
growy_append_formatted(g, "static inline bool is_physical_as(AddressSpace as) {\n");
15-
growy_append_formatted(g, "\tswitch(as) {\n");
16-
for (size_t i = 0; i < json_object_array_length(address_spaces); i++) {
17-
json_object* as = json_object_array_get_idx(address_spaces, i);
18-
String name = json_object_get_string(json_object_object_get(as, "name"));
19-
if (json_object_get_boolean(json_object_object_get(as, "physical")))
20-
growy_append_formatted(g, "\t\tcase As%s: return true;\n", name);
21-
}
22-
growy_append_formatted(g, "\t\tdefault: return false;\n");
23-
growy_append_formatted(g, "\t}\n");
24-
growy_append_formatted(g, "}\n\n");
2513
}
2614

2715
static void generate_node_tags(Growy* g, json_object* nodes) {

0 commit comments

Comments
 (0)