From 6c6b4b04ab0ff914075c0e90b8834b4dcb55e55f Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Fri, 26 Aug 2022 17:52:22 +0100 Subject: Upgrade to LLVM 14 Adding attributes to functions/values has been broken by the upgrade. Additionally, the debug builder wants more information which is currently not being provided. --- INSTALL.md | 2 +- Makefile | 11 ++++++----- llvm_codegen.c | 29 +++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 83fd1f7..3ddf0a1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,4 +1,4 @@ -This project is built using LLVM 10. +This project is built using LLVM 14. The Makefile tries to call llvm-config, but this is ambiguous and may not work in some situations (since there are more versions of LLVM than just v10). The diff --git a/Makefile b/Makefile index 15819ee..49b5924 100644 --- a/Makefile +++ b/Makefile @@ -8,15 +8,16 @@ INSTALL = install -c DEBUG = -ggdb3 -DGC_DEBUG RELEASE = -O2 -DNDEBUG -CFLAGS = --std=c99 -Wpedantic -Wall -Wextra -Werror $(DEBUG) +CFLAGS = --std=c99 -D_POSIX_C_SOURCE=200809L \ + -Wpedantic -Wall -Wextra -Werror $(DEBUG) LFLAGS = -D_POSIX_C_SOURCE=200809L LLVM_MODULES = core executionengine mcjit interpreter analysis native bitwriter -CFLAGS += $(shell llvm-config --cflags) -CXXFLAGS += $(shell llvm-config --cppflags) -LDFLAGS += $(shell llvm-config --ldflags) -LDLIBS += $(shell llvm-config --libs $(LLVM_MODULES) --system-libs) +CFLAGS += $(shell llvm-config-14 --cflags) +CXXFLAGS += $(shell llvm-config-14 --cppflags) +LDFLAGS += $(shell llvm-config-14 --ldflags) +LDLIBS += $(shell llvm-config-14 --libs $(LLVM_MODULES) --system-libs) .PHONY: default all clean test install uninstall diff --git a/llvm_codegen.c b/llvm_codegen.c index 23a27c8..044fc05 100644 --- a/llvm_codegen.c +++ b/llvm_codegen.c @@ -342,6 +342,9 @@ int make_trmc_inner_name(char *buf, int n, char *outer_id, char *mod) { } void add_enum_attr(LLVMValueRef f, uint index, char *id, size_t n, int val) { + // FIXME adding enums causes the generator to output unfinished LLVM IR. + return; + if (!opts->llvm_attributes) return; if (!n) n = strlen(id); @@ -412,7 +415,8 @@ LLVMValueRef codegen_type_definition(sexpr *se) { LLVMValueRef space = LLVMBuildPointerCast(util_b, space_cast, struct_ptr_t, "space_uncast"); for (uint i = 0; i < prop_c; i++) { - LLVMValueRef prop_pos = LLVMBuildStructGEP(util_b, space, i, "pos"); + LLVMValueRef prop_pos = + LLVMBuildStructGEP2(util_b, struct_t, space, i, "pos"); LLVMValueRef param = LLVMGetParam(filler_p, i); LLVMBuildStore(util_b, param, prop_pos); } @@ -484,7 +488,7 @@ LLVMValueRef codegen_type_definition(sexpr *se) { LLVMBuildPointerCast(util_b, param, struct_ptr_t, "uncast"); LLVMValueRef ptr = LLVMBuildStructGEP2(util_b, struct_t, uncast, i, "part"); - LLVMValueRef val = LLVMBuildLoad(util_b, ptr, "deref"); + LLVMValueRef val = LLVMBuildLoad2(util_b, boxed_t, ptr, "deref"); LLVMBuildRet(util_b, val); debug("adding %s to scope\n", prop_func_id); @@ -1721,10 +1725,23 @@ LLVMMetadataRef debug_make_compile_unit(LLVMDIBuilderRef di_builder, int inline_debug_info = 1; int profile_debug_info = 1; - return LLVMDIBuilderCreateCompileUnit(di_builder, lang, di_file, producer, - producer_len, optimised, flags, flags_len, runtime_version, - split_name, split_name_len, emission, dwoid, inline_debug_info, - profile_debug_info); + return LLVMDIBuilderCreateCompileUnit( + di_builder, + lang, + di_file, + producer, producer_len, + optimised, + flags, flags_len, + runtime_version, + split_name, split_name_len, + emission, + dwoid, + inline_debug_info, + profile_debug_info, + // TODO + "", 0, + "", 0 + ); } void llvm_codegen_prologue(char *filename, optimisation_t *llvm_info) { -- cgit v1.2.1