Skip to content

Commit e8e524d

Browse files
committed
l2s: simplify and fix llvm 14
1 parent b383100 commit e8e524d

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

src/frontends/llvm/l2s.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const Node* convert_function(Parser* p, LLVMValueRef fn) {
111111
assert(fn_type->tag == FnType_TAG);
112112
assert(fn_type->payload.fn_type.param_types.count == params.count);
113113
Node* f = function(p->dst, params, LLVMGetValueName(fn), empty(a), fn_type->payload.fn_type.return_types);
114-
const Node* r = f;
114+
const Node* r = fn_addr_helper(a, f);
115115
insert_dict(LLVMValueRef, const Node*, p->map, fn, r);
116116

117117
if (LLVMCountBasicBlocks(fn) > 0) {

src/frontends/llvm/l2s_annotations.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ void add_annotation(Parser* p, const Node* n, ParsedAnnotation a) {
2222
}
2323
}
2424

25+
static const Node* assert_and_strip_fn_addr(const Node* fn) {
26+
assert(fn->tag == FnAddr_TAG);
27+
fn = fn->payload.fn_addr.fn;
28+
assert(fn->tag == Function_TAG);
29+
return fn;
30+
}
31+
2532
void process_llvm_annotations(Parser* p, LLVMValueRef global) {
2633
IrArena* a = get_module_arena(p->dst);
2734
const Type* t = convert_type(p, LLVMGlobalGetValueType(global));
@@ -51,40 +58,29 @@ void process_llvm_annotations(Parser* p, LLVMValueRef global) {
5158
if (annotation_payload->tag == GlobalVariable_TAG) {
5259
annotation_payload = annotation_payload->payload.global_variable.init;
5360
}
54-
const char* ostr = get_string_literal(a, annotation_payload);
61+
62+
NodeResolveConfig resolve_config = default_node_resolve_config();
63+
// both of those assumptions are hacky but this front-end is a hacky deal anyways.
64+
resolve_config.assume_globals_immutability = true;
65+
resolve_config.allow_incompatible_types = true;
66+
const char* ostr = get_string_literal(a, resolve_node_to_definition(annotation_payload, resolve_config));
5567
char* str = calloc(strlen(ostr) + 1, 1);
5668
memcpy(str, ostr, strlen(ostr) + 1);
5769
if (strcmp(strtok(str, "::"), "shady") == 0) {
5870
const Node* target = entry->payload.composite.contents.nodes[0];
59-
if (target->tag == RefDecl_TAG) {
60-
target = target->payload.ref_decl.decl;
61-
}
62-
while (target->tag == Constant_TAG) {
63-
const Node* instr = target->payload.constant.instruction;
64-
assert(instr->tag == PrimOp_TAG);
65-
switch (instr->payload.prim_op.op) {
66-
case quote_op:
67-
case reinterpret_op:
68-
case convert_op:
69-
case lea_op: target = first(instr->payload.prim_op.operands); break;
70-
default: assert(false);
71-
}
72-
}
73-
if (target->tag == RefDecl_TAG) {
74-
target = target->payload.ref_decl.decl;
75-
}
71+
target = resolve_node_to_definition(target, resolve_config);
7672

7773
char* keyword = strtok(NULL, "::");
7874
if (strcmp(keyword, "entry_point") == 0) {
79-
assert(target->tag == Function_TAG);
75+
target = assert_and_strip_fn_addr(target);
8076
add_annotation(p, target, (ParsedAnnotation) {
8177
.payload = annotation_value(a, (AnnotationValue) {
8278
.name = "EntryPoint",
8379
.value = string_lit_helper(a, strtok(NULL, "::"))
8480
})
8581
});
8682
} else if (strcmp(keyword, "workgroup_size") == 0) {
87-
assert(target->tag == Function_TAG);
83+
target = assert_and_strip_fn_addr(target);
8884
add_annotation(p, target, (ParsedAnnotation) {
8985
.payload = annotation_values(a, (AnnotationValues) {
9086
.name = "WorkgroupSize",

src/frontends/llvm/l2s_value.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const Node* convert_value(Parser* p, LLVMValueRef v) {
8181
Nodes annotations = singleton(annotation(a, (Annotation) { .name = "SkipOnInfer" }));
8282
annotations = empty(a);
8383
Node* decl = constant(p->dst, annotations, NULL, name);
84-
r = decl;
84+
r = ref_decl_helper(a, decl);
8585
insert_dict(LLVMTypeRef, const Type*, p->map, v, r);
8686
BodyBuilder* bb = begin_body(a);
8787
EmittedInstr emitted = convert_instruction(p, NULL, bb, v);

0 commit comments

Comments
 (0)