static void set_descriptor(compile_t* c, reach_type_t* t, LLVMValueRef value) { if(t->underlying == TK_STRUCT) return; LLVMValueRef desc_ptr = LLVMBuildStructGEP(c->builder, value, 0, ""); LLVMValueRef store = LLVMBuildStore(c->builder, t->desc, desc_ptr); const char id[] = "tbaa"; LLVMSetMetadata(store, LLVMGetMDKindID(id, sizeof(id) - 1), c->tbaa_descptr); }
static LLVMValueRef assign_field(compile_t* c, LLVMValueRef l_value, LLVMValueRef r_value, ast_t* p_type, ast_t* r_type) { LLVMValueRef result = LLVMBuildLoad(c->builder, l_value, ""); // Cast the rvalue appropriately. LLVMTypeRef cast_type = LLVMGetElementType(LLVMTypeOf(l_value)); LLVMValueRef cast_value = gen_assign_cast(c, cast_type, r_value, r_type); if(cast_value == NULL) return NULL; // Store to the field. LLVMValueRef store = LLVMBuildStore(c->builder, cast_value, l_value); LLVMValueRef metadata = tbaa_metadata_for_type(c, p_type); const char id[] = "tbaa"; LLVMSetMetadata(result, LLVMGetMDKindID(id, sizeof(id) - 1), metadata); LLVMSetMetadata(store, LLVMGetMDKindID(id, sizeof(id) - 1), metadata); return result; }
int llvm_set_metadata(void) { LLVMBuilderRef b = LLVMCreateBuilder(); LLVMValueRef values[] = { LLVMConstInt(LLVMInt32Type(), 0, 0) }; // This used to trigger an assertion LLVMSetMetadata( LLVMBuildRetVoid(b), LLVMGetMDKindID("kind", 4), LLVMMDNode(values, 1)); LLVMDisposeBuilder(b); return 0; }
LLVMValueRef gen_fieldload(compile_t* c, ast_t* ast) { AST_GET_CHILDREN(ast, left, right); ast_t* l_type = ast_type(left); LLVMValueRef field = gen_fieldptr(c, ast); if(field == NULL) return NULL; assert((ast_id(l_type) == TK_NOMINAL) || (ast_id(l_type) == TK_TUPLETYPE)); // Don't load if we're reading from a tuple. if(ast_id(l_type) != TK_TUPLETYPE) { field = LLVMBuildLoad(c->builder, field, ""); LLVMValueRef metadata = tbaa_metadata_for_type(c, l_type); const char id[] = "tbaa"; LLVMSetMetadata(field, LLVMGetMDKindID(id, sizeof(id) - 1), metadata); } return field; }