Skip to content

Instantly share code, notes, and snippets.

@Praetonus
Created July 21, 2017 20:59
Show Gist options
  • Save Praetonus/6dc9d32daf96fed807c6bb8cc7eae29c to your computer and use it in GitHub Desktop.
Save Praetonus/6dc9d32daf96fed807c6bb8cc7eae29c to your computer and use it in GitHub Desktop.
diff --git i/src/libponyc/codegen/gencall.c w/src/libponyc/codegen/gencall.c
index 06f62ec92..f2007da29 100644
--- i/src/libponyc/codegen/gencall.c
+++ w/src/libponyc/codegen/gencall.c
@@ -271,8 +271,12 @@ static void set_descriptor(compile_t* c, reach_type_t* t, LLVMValueRef value)
LLVMValueRef desc_ptr = LLVMBuildStructGEP(c->builder, value, 0, "");
LLVMValueRef store = LLVMBuildStore(c->builder,
((compile_type_t*)t->c_type)->desc, desc_ptr);
+#if PONY_LLVM >= 400
+ tbaa_tag(c, c->tbaa_descptr, store);
+#else
const char id[] = "tbaa";
LLVMSetMetadata(store, LLVMGetMDKindID(id, sizeof(id) - 1), c->tbaa_descptr);
+#endif
}
static void set_method_external_interface(reach_type_t* t, const char* name,
diff --git i/src/libponyc/codegen/gendesc.c w/src/libponyc/codegen/gendesc.c
index af275666d..60e32bff9 100644
--- i/src/libponyc/codegen/gendesc.c
+++ w/src/libponyc/codegen/gendesc.c
@@ -506,9 +506,13 @@ static LLVMValueRef desc_field(compile_t* c, LLVMValueRef desc, int index)
{
LLVMValueRef ptr = LLVMBuildStructGEP(c->builder, desc, index, "");
LLVMValueRef field = LLVMBuildLoad(c->builder, ptr, "");
+#if PONY_LLVM >= 400
+ tbaa_tag(c, c->tbaa_descriptor, field);
+#else
const char id[] = "tbaa";
LLVMSetMetadata(field, LLVMGetMDKindID(id, sizeof(id) - 1),
c->tbaa_descriptor);
+#endif
return field;
}
@@ -516,8 +520,12 @@ LLVMValueRef gendesc_fetch(compile_t* c, LLVMValueRef object)
{
LLVMValueRef ptr = LLVMBuildStructGEP(c->builder, object, 0, "");
LLVMValueRef desc = LLVMBuildLoad(c->builder, ptr, "");
+#if PONY_LLVM >= 400
+ tbaa_tag(c, c->tbaa_descptr, desc);
+#else
const char id[] = "tbaa";
LLVMSetMetadata(desc, LLVMGetMDKindID(id, sizeof(id) - 1), c->tbaa_descptr);
+#endif
return desc;
}
@@ -551,8 +559,12 @@ LLVMValueRef gendesc_vtable(compile_t* c, LLVMValueRef desc, size_t colour)
LLVMValueRef func_ptr = LLVMBuildInBoundsGEP(c->builder, vtable, gep, 2, "");
LLVMValueRef fun = LLVMBuildLoad(c->builder, func_ptr, "");
+#if PONY_LLVM >= 400
+ tbaa_tag(c, c->tbaa_descriptor, fun);
+#else
const char id[] = "tbaa";
LLVMSetMetadata(fun, LLVMGetMDKindID(id, sizeof(id) - 1), c->tbaa_descriptor);
+#endif
return fun;
}
@@ -583,9 +595,13 @@ LLVMValueRef gendesc_fieldinfo(compile_t* c, LLVMValueRef desc, size_t index)
LLVMValueRef field_desc = LLVMBuildInBoundsGEP(c->builder, fields, gep, 2,
"");
LLVMValueRef field_info = LLVMBuildLoad(c->builder, field_desc, "");
+#if PONY_LLVM >= 400
+ tbaa_tag(c, c->tbaa_descriptor, field_info);
+#else
const char id[] = "tbaa";
LLVMSetMetadata(field_info, LLVMGetMDKindID(id, sizeof(id) - 1),
c->tbaa_descriptor);
+#endif
return field_info;
}
@@ -670,9 +686,13 @@ LLVMValueRef gendesc_istrait(compile_t* c, LLVMValueRef desc, ast_t* type)
LLVMValueRef index = LLVMBuildInBoundsGEP(c->builder, bitmap, args, 2, "");
index = LLVMBuildLoad(c->builder, index, "");
+#if PONY_LLVM >= 400
+ tbaa_tag(c, c->tbaa_descriptor, index);
+#else
const char id[] = "tbaa";
LLVMSetMetadata(index, LLVMGetMDKindID(id, sizeof(id) - 1),
c->tbaa_descriptor);
+#endif
LLVMValueRef has_trait = LLVMBuildAnd(c->builder, index, mask, "");
has_trait = LLVMBuildICmp(c->builder, LLVMIntNE, has_trait,
diff --git i/src/libponyc/codegen/gentype.c w/src/libponyc/codegen/gentype.c
index 9137c1f3b..f98ce2c17 100644
--- i/src/libponyc/codegen/gentype.c
+++ w/src/libponyc/codegen/gentype.c
@@ -144,16 +144,16 @@ static LLVMValueRef make_tbaa_root(LLVMContextRef ctx)
return LLVMMDNodeInContext(ctx, &mdstr, 1);
}
-#if PONY_LLVM < 400
-
static LLVMValueRef make_tbaa_descriptor(LLVMContextRef ctx, LLVMValueRef root)
{
const char str[] = "Type descriptor";
LLVMValueRef params[3];
params[0] = LLVMMDStringInContext(ctx, str, sizeof(str) - 1);
params[1] = root;
+#if PONY_LLVM < 400
params[2] = LLVMConstInt(LLVMInt64TypeInContext(ctx), 1, false);
- return LLVMMDNodeInContext(ctx, params, 3);
+#endif
+ return LLVMMDNodeInContext(ctx, params, PONY_LLVM < 400 ? 3 : 2);
}
static LLVMValueRef make_tbaa_descptr(LLVMContextRef ctx, LLVMValueRef root)
@@ -165,8 +165,6 @@ static LLVMValueRef make_tbaa_descptr(LLVMContextRef ctx, LLVMValueRef root)
return LLVMMDNodeInContext(ctx, params, 2);
}
-#endif
-
static void compile_type_free(void* p)
{
POOL_FREE(compile_type_t, p);
@@ -816,13 +814,8 @@ bool gentypes(compile_t* c)
c->tbaa_root = make_tbaa_root(c->context);
-#if PONY_LLVM >= 400
- c->tbaa_descriptor = NULL;
- c->tbaa_descptr = NULL;
-#else
c->tbaa_descriptor = make_tbaa_descriptor(c->context, c->tbaa_root);
c->tbaa_descptr = make_tbaa_descptr(c->context, c->tbaa_root);
-#endif
allocate_compile_types(c);
genprim_builtins(c);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment