From 8e273e8111ebc6edbcad168054abce82ae35f715 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Wed, 19 Jun 2024 15:48:33 -0700 Subject: [PATCH 01/12] Switch fakeasm to use snprintf (#663) --- tests/fakeasm.t | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/fakeasm.t b/tests/fakeasm.t index 09998825c..5355bcfbb 100644 --- a/tests/fakeasm.t +++ b/tests/fakeasm.t @@ -4,7 +4,7 @@ local op = setmetatable({},{ __index = function(self,idx) return idx end }) C = terralib.includec("stdio.h") -local function emit(buf,...) +local function emit(buf,bufsiz,...) local str = "" local operands = {} for i = 1,select("#",...) do @@ -14,18 +14,18 @@ local function emit(buf,...) if e then table.insert(operands,v) end end str = str.."\n" - return `C.sprintf(buf,str,operands) + return `C.snprintf(buf,bufsiz,str,operands) end emit = macro(emit) local c = "as28" -terra what(buf : rawstring) +terra what(buf : rawstring, bufsiz : uint64) var b = 3 - emit(buf,1,3,4,3+3,op.what,b + 3) + emit(buf,bufsiz,1,3,4,3+3,op.what,b + 3) end local buf = terralib.new(int8[128]) -what(buf) +what(buf,128) local ffi = require("ffi") local s = ffi.string(buf) assert("1 3 4 6 what 6 \n" == s) From e8249497eb0e83b5831e6e5465fae650fb70e9e9 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Wed, 19 Jun 2024 16:16:14 -0700 Subject: [PATCH 02/12] Switch to snprintf throughout codebase (#664) --- src/lparser.cpp | 12 ++++++------ src/tcwrapper.cpp | 2 +- src/terra.cpp | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lparser.cpp b/src/lparser.cpp index 5843f2c9f..82ac34a10 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -961,14 +961,14 @@ static void doquote(LexState *ls, int isexp) { } // buf should be at least 128 chars -static void number_type(LexState *ls, int flags, char *buf) { +static void number_type(LexState *ls, int flags, char *buf, size_t bufsiz) { if (ls->in_terra) { if (flags & F_ISINTEGER) { const char *sign = (flags & F_ISUNSIGNED) ? "u" : ""; const char *sz = (flags & F_IS8BYTES) ? "64" : ""; - sprintf(buf, "%sint%s", sign, sz); + snprintf(buf, bufsiz, "%sint%s", sign, sz); } else { - sprintf(buf, "%s", (flags & F_IS8BYTES) ? "double" : "float"); + snprintf(buf, bufsiz, "%s", (flags & F_IS8BYTES) ? "double" : "float"); } } } @@ -997,11 +997,11 @@ static void simpleexp(LexState *ls) { case TK_NUMBER: { char buf[128]; int flags = ls->t.seminfo.flags; - number_type(ls, flags, &buf[0]); + number_type(ls, flags, &buf[0], sizeof(buf)); if (flags & F_ISINTEGER) { push_integer(ls, ls->t.seminfo.i); push_literal(ls, buf); - sprintf(buf, "%" PRIu64, ls->t.seminfo.i); + snprintf(buf, sizeof(buf), "%" PRIu64, ls->t.seminfo.i); push_string(ls, buf); add_field(ls, -2, "stringvalue"); @@ -2053,7 +2053,7 @@ static void converttokentolua(LexState *ls, Token *t) { lua_pushstring(ls->L, ""); lua_setfield(ls->L, -2, "type"); int flags = t->seminfo.flags; - number_type(ls, flags, &buf[0]); + number_type(ls, flags, &buf[0], sizeof(buf)); push_type(ls, buf); lua_setfield(ls->L, -2, "valuetype"); if (flags & F_IS8BYTES && flags & F_ISINTEGER) { diff --git a/src/tcwrapper.cpp b/src/tcwrapper.cpp index 24c5881a5..6fd5b0aa5 100644 --- a/src/tcwrapper.cpp +++ b/src/tcwrapper.cpp @@ -99,7 +99,7 @@ class IncludeCVisitor : public RecursiveASTVisitor { std::string declstr; if (it->isAnonymousStructOrUnion()) { char buf[32]; - sprintf(buf, "_%d", anonname++); + snprintf(buf, sizeof(buf), "_%d", anonname++); declstr = buf; } else { declstr = declname.getAsString(); diff --git a/src/terra.cpp b/src/terra.cpp index e06372a48..d5405434c 100644 --- a/src/terra.cpp +++ b/src/terra.cpp @@ -572,8 +572,9 @@ int terra_loadfile(lua_State *L, const char *file) { if (c == '\n') ungetc(c, ctx.fp); /* keep line count accurate */ } if (file) { - char *name = (char *)malloc(strlen(file) + 2); - sprintf(name, "@%s", file); + size_t name_size = strlen(file) + 2; + char *name = (char *)malloc(name_size); + snprintf(name, name_size, "@%s", file); int r = terra_load(L, reader_file, &ctx, name); free(name); fclose(ctx.fp); From dff6c92e5ebc414b340edb62c500a214eaf0494e Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Wed, 19 Jun 2024 16:47:18 -0700 Subject: [PATCH 03/12] Support for SPIR-V code generation (#652) --- src/tcompiler.cpp | 81 ++++++++++++++++++++++++++++++-------------- src/terralib.lua | 13 ++++--- tests/addressspace.t | 26 ++++++++++++++ 3 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 tests/addressspace.t diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index deb7247c3..6c1d24ef1 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -762,14 +762,15 @@ struct CCallingConv { lua_State *L; terra_CompilerState *C; Types *Ty; - bool pass_struct_as_exploded_values; bool return_empty_struct_as_void; - bool wasm_cconv; bool aarch64_cconv; + bool amdgpu_cconv; bool ppc64_cconv; int ppc64_float_limit; int ppc64_int_limit; bool ppc64_count_used; + bool spirv_cconv; + bool wasm_cconv; CCallingConv(TerraCompilationUnit *CU_, Types *Ty_) : CU(CU_), @@ -777,19 +778,20 @@ struct CCallingConv { L(CU_->T->L), C(CU_->T->C), Ty(Ty_), - pass_struct_as_exploded_values(false), return_empty_struct_as_void(false), - wasm_cconv(false), aarch64_cconv(false), + amdgpu_cconv(false), ppc64_cconv(false), ppc64_float_limit(0), ppc64_int_limit(0), - ppc64_count_used(false) { + ppc64_count_used(false), + spirv_cconv(false), + wasm_cconv(false) { auto Triple = CU->TT->tm->getTargetTriple(); switch (Triple.getArch()) { case Triple::ArchType::amdgcn: { return_empty_struct_as_void = true; - pass_struct_as_exploded_values = true; + amdgpu_cconv = true; } break; case Triple::ArchType::aarch64: case Triple::ArchType::aarch64_be: { @@ -806,16 +808,27 @@ struct CCallingConv { ppc64_int_limit = 8; ppc64_count_used = true; } break; +#if LLVM_VERSION >= 150 + case Triple::ArchType::spirv32: + case Triple::ArchType::spirv64: { + return_empty_struct_as_void = true; + spirv_cconv = true; + } break; +#endif case Triple::ArchType::wasm32: case Triple::ArchType::wasm64: { wasm_cconv = true; } break; + default: + break; } switch (Triple.getOS()) { case Triple::OSType::Win32: { return_empty_struct_as_void = true; } break; + default: + break; } } @@ -1088,11 +1101,11 @@ struct CCallingConv { return Argument(C_PRIMITIVE, t, usei1 ? Type::getInt1Ty(*CU->TT->ctx) : NULL); } - if (wasm_cconv && !WasmIsSingletonOrEmpty(t->type)) { + if ((wasm_cconv && !WasmIsSingletonOrEmpty(t->type)) || spirv_cconv) { return Argument(C_AGGREGATE_MEM, t); } - if (pass_struct_as_exploded_values) { + if (amdgpu_cconv) { return Argument(C_AGGREGATE_REG, t, t->type); } @@ -1128,7 +1141,7 @@ struct CCallingConv { return Argument(C_AGGREGATE_REG, t, StructType::get(*CU->TT->ctx, elements)); } - void Classify(Obj *ftype, Obj *params, Classification *info) { + void Classify(Obj *ftype, CallingConv::ID cconv, Obj *params, Classification *info) { Obj fparams, returntype; ftype->obj("parameters", &fparams); ftype->obj("returntype", &returntype); @@ -1161,13 +1174,13 @@ struct CCallingConv { CreateFunctionType(info, fparams.size(), ftype->boolean("isvararg")); } - Classification *ClassifyFunction(Obj *fntyp) { + Classification *ClassifyFunction(Obj *fntyp, CallingConv::ID cconv) { Classification *info = (Classification *)CU->symbols->getud(fntyp); if (!info) { info = new Classification(); // TODO: fix leak Obj params; fntyp->obj("parameters", ¶ms); - Classify(fntyp, ¶ms, info); + Classify(fntyp, cconv, ¶ms, info); CU->symbols->setud(fntyp, info); } return info; @@ -1279,8 +1292,9 @@ struct CCallingConv { } } - Function *CreateFunction(Module *M, Obj *ftype, const Twine &name) { - Classification *info = ClassifyFunction(ftype); + Function *CreateFunction(Module *M, Obj *ftype, CallingConv::ID cconv, + const Twine &name) { + Classification *info = ClassifyFunction(ftype, cconv); Function *fn = Function::Create(info->fntype, Function::InternalLinkage, name, M); AttributeFnOrCall(fn, info); return fn; @@ -1311,7 +1325,7 @@ struct CCallingConv { } void EmitEntry(IRBuilder<> *B, Obj *ftype, Function *func, std::vector *variables) { - Classification *info = ClassifyFunction(ftype); + Classification *info = ClassifyFunction(ftype, func->getCallingConv()); assert(info->paramtypes.size() == variables->size()); Function::arg_iterator ai = func->arg_begin(); if (info->returntype.kind == C_AGGREGATE_MEM) @@ -1359,7 +1373,7 @@ struct CCallingConv { } } void EmitReturn(IRBuilder<> *B, Obj *ftype, Function *function, Value *result) { - Classification *info = ClassifyFunction(ftype); + Classification *info = ClassifyFunction(ftype, function->getCallingConv()); ArgumentKind kind = info->returntype.kind; if (C_AGGREGATE_REG == kind && @@ -1420,10 +1434,10 @@ struct CCallingConv { } } - Value *EmitCall(IRBuilder<> *B, Obj *ftype, Obj *paramtypes, Value *callee, - std::vector *actuals) { + Value *EmitCall(IRBuilder<> *B, Obj *ftype, CallingConv::ID cconv, Obj *paramtypes, + Value *callee, std::vector *actuals) { Classification info; - Classify(ftype, paramtypes, &info); + Classify(ftype, cconv, paramtypes, &info); std::vector arguments; @@ -1867,16 +1881,25 @@ struct FunctionEmitter { if (fstate->func) return fstate; } + CallingConv::ID callingconv = CallingConv::MaxID; + if (funcobj->hasfield("callingconv")) { + callingconv = ParseCallingConv(funcobj->string("callingconv")); + } + Obj ftype; funcobj->obj("type", &ftype); // function name is $+name so that it can't conflict with any symbols imported // from the C namespace - fstate->func = CC->CreateFunction( - M, &ftype, Twine(StringRef((isextern) ? "" : "$"), name)); + fstate->func = + CC->CreateFunction(M, &ftype, callingconv, + Twine(StringRef((isextern) ? "" : "$"), name)); if (isextern) { // Set external linkage for extern functions. fstate->func->setLinkage(GlobalValue::ExternalLinkage); } + if (callingconv != CallingConv::MaxID) { + fstate->func->setCallingConv(callingconv); + } if (funcobj->hasfield("alwaysinline")) { if (funcobj->boolean("alwaysinline")) { @@ -1891,10 +1914,6 @@ struct FunctionEmitter { fstate->func->addFnAttr(Attribute::NoInline); } } - if (funcobj->hasfield("callingconv")) { - const char *callingconv = funcobj->string("callingconv"); - fstate->func->setCallingConv(ParseCallingConv(callingconv)); - } if (funcobj->hasfield("noreturn")) { if (funcobj->boolean("noreturn")) { fstate->func->addFnAttr(Attribute::NoReturn); @@ -2810,7 +2829,12 @@ struct FunctionEmitter { #if LLVM_VERSION < 170 return B->CreateBitCast(v, toT->type); #else - return v; + if (fromT->type->getPointerAddressSpace() != + toT->type->getPointerAddressSpace()) { + return B->CreateAddrSpaceCast(v, toT->type); + } else { + return v; + } #endif } else { assert(toT->type->isIntegerTy()); @@ -3205,6 +3229,11 @@ struct FunctionEmitter { call->obj("value", &func); + CallingConv::ID callingconv = CallingConv::MaxID; + if (func.hasfield("callingconv")) { + callingconv = ParseCallingConv(func.string("callingconv")); + } + Value *fn = emitExp(&func); Obj fnptrtyp; @@ -3220,7 +3249,7 @@ struct FunctionEmitter { setInsertBlock(bb); deferred.push_back(bb); } - Value *r = CC->EmitCall(B, &fntyp, ¶mtypes, fn, &actuals); + Value *r = CC->EmitCall(B, &fntyp, callingconv, ¶mtypes, fn, &actuals); setInsertBlock(cur); // defer may have changed it return r; } diff --git a/src/terralib.lua b/src/terralib.lua index cc6b2d60a..8ea57c61f 100644 --- a/src/terralib.lua +++ b/src/terralib.lua @@ -1277,7 +1277,12 @@ do if status then return r end end return self.name - elseif self:ispointer() then return "&"..tostring(self.type) + elseif self:ispointer() then + if not self.addressspace or self.addressspace == 0 then + return "&"..tostring(self.type) + else + return "pointer("..tostring(self.type)..","..tostring(self.addressspace)..")" + end elseif self:isvector() then return "vector("..tostring(self.type)..","..tostring(self.N)..")" elseif self:isfunction() then return mkstring(self.parameters,"{",",",self.isvararg and " ...}" or "}").." -> "..tostring(self.returntype) elseif self:isarray() then @@ -2455,15 +2460,15 @@ function typecheck(topexp,luaenv,simultaneousdefinitions) end local function ascompletepointer(exp) --convert pointer like things into pointers to _complete_ types exp.type.type:tcomplete(exp) - return (insertcast(exp,terra.types.pointer(exp.type.type))) --parens are to truncate to 1 argument + return (insertcast(exp,terra.types.pointer(exp.type.type, exp.type.addressspace))) --parens are to truncate to 1 argument end -- subtracting 2 pointers if pointerlike(l.type) and pointerlike(r.type) and l.type.type == r.type.type and e.operator == tokens["-"] then return e:copy { operands = List {ascompletepointer(l),ascompletepointer(r)} }:withtype(terra.types.ptrdiff) elseif pointerlike(l.type) and r.type:isintegral() then -- adding or subtracting a int to a pointer - return e:copy {operands = List {ascompletepointer(l),r} }:withtype(terra.types.pointer(l.type.type)) + return e:copy {operands = List {ascompletepointer(l),r} }:withtype(terra.types.pointer(l.type.type, l.type.addressspace)) elseif l.type:isintegral() and pointerlike(r.type) then - return e:copy {operands = List {ascompletepointer(r),l} }:withtype(terra.types.pointer(r.type.type)) + return e:copy {operands = List {ascompletepointer(r),l} }:withtype(terra.types.pointer(r.type.type, r.type.addressspace)) else return meetbinary(e,"isarithmeticorvector",l,r) end diff --git a/tests/addressspace.t b/tests/addressspace.t new file mode 100644 index 000000000..78653feef --- /dev/null +++ b/tests/addressspace.t @@ -0,0 +1,26 @@ +-- Tests of pointers with address spaces. + +-- The exact meaning of this depends on the target, but at least basic +-- code compilation should work. + +local function ptr1(ty) + -- A pointer in address space 1. + return terralib.types.pointer(ty, 1) +end + +terra test(x : &int, y : ptr1(int)) + -- Should be able to do math on pointers with non-zero address spaces: + var a = [ptr1(int8)](y) + var b = a + 8 + var c = [ptr1(int)](b) + var d = c - y + y = c + + -- Casts should work: + y = [ptr1(int)](x) + x = [&int](y) + + return d +end +test:compile() +print(test) From 5754074c1519cb6ef375fd54f0afe30090bcf508 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Wed, 19 Jun 2024 21:04:14 -0700 Subject: [PATCH 04/12] Fix read out of bounds with empty file (#665) --- src/lparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lparser.cpp b/src/lparser.cpp index 82ac34a10..f0eea74b3 100644 --- a/src/lparser.cpp +++ b/src/lparser.cpp @@ -2326,8 +2326,8 @@ int luaY_parser(terra_State *T, ZIO *z, const char *name, int firstchar) { lexstate.output_buffer.data); } // loadbuffer doesn't like null terminators, so rewind to before them - while (lexstate.output_buffer.data[lexstate.output_buffer.N - 1] == '\0' && - lexstate.output_buffer.N > 0) { + while (lexstate.output_buffer.N > 0 && + lexstate.output_buffer.data[lexstate.output_buffer.N - 1] == '\0') { lexstate.output_buffer.N--; } From f673dd84648e2ef84e86347afb65680233dd9aa5 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Fri, 21 Jun 2024 11:18:22 -0700 Subject: [PATCH 05/12] Cleanup warnings and tests (#666) --- src/tcompiler.cpp | 2 -- src/tcwrapper.cpp | 3 --- tests/class.t | 3 +-- tests/class3.t | 7 ++----- tests/class4.t | 2 +- tests/class5.t | 3 +-- tests/lib/javalike.t | 12 ++++++++---- 7 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index 6c1d24ef1..df93db3d7 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -2870,7 +2870,6 @@ struct FunctionEmitter { Value *v = emitAddressOf(&obj); Obj entryType; Value *result = emitStructSelect(&typ, v, offset, &entryType); - Type *ttype = getType(&typ)->type; if (!exp->boolean("lvalue")) result = B->CreateLoad(getType(&entryType)->type, result); return result; @@ -3011,7 +3010,6 @@ struct FunctionEmitter { Value *a_result = B->CreateExtractValue(a, ArrayRef(0)); Value *a_success = B->CreateExtractValue(a, ArrayRef(1)); Value *a_success_i8 = B->CreateZExt(a_success, B->getInt8Ty()); - Type *elt_types[2] = {a_result->getType(), B->getInt8Ty()}; Type *result_type = typeOfValue(exp)->type; Value *result = UndefValue::get(result_type); result = B->CreateInsertValue(result, a_result, ArrayRef(0)); diff --git a/src/tcwrapper.cpp b/src/tcwrapper.cpp index 6fd5b0aa5..afaad2d3d 100644 --- a/src/tcwrapper.cpp +++ b/src/tcwrapper.cpp @@ -802,9 +802,6 @@ void InitHeaderSearchFlagsAndArgs(std::string const &TripleStr, HeaderSearchOpti } clang::driver::ToolChain const &TC = C->getDefaultToolChain(); - std::string path = TC.GetLinkerPath(); - const char *link = path.c_str(); - for (auto &i : TC.getProgramPaths()) link = i.c_str(); llvm::opt::ArgStringList IncludeArgs; TC.AddClangSystemIncludeArgs(C->getArgs(), IncludeArgs); diff --git a/tests/class.t b/tests/class.t index 0a90e1838..8a97b19bb 100644 --- a/tests/class.t +++ b/tests/class.t @@ -1,5 +1,5 @@ -IO = terralib.includec("stdio.h") local Class = require("lib/javalike") +local IO = Class.C struct A(Class()) { a : int @@ -104,7 +104,6 @@ end assert(12 == foobar2()) -local IO = terralib.includec("stdio.h") struct Animal(Class()) { data : int } diff --git a/tests/class3.t b/tests/class3.t index 5f0edd0e2..3669eb880 100644 --- a/tests/class3.t +++ b/tests/class3.t @@ -1,8 +1,5 @@ - -C = terralib.includec("stdio.h") - local Class = require("lib/javalike") - +local C = Class.C local Prints = Class.Interface("Prints",{ print = {} -> {} }) @@ -32,4 +29,4 @@ terra test() p:print() end -test() \ No newline at end of file +test() diff --git a/tests/class4.t b/tests/class4.t index a50db7a3e..051ed55fe 100644 --- a/tests/class4.t +++ b/tests/class4.t @@ -21,4 +21,4 @@ terra bar() a:draw() end -bar() \ No newline at end of file +bar() diff --git a/tests/class5.t b/tests/class5.t index 432ad5185..17c0c226a 100644 --- a/tests/class5.t +++ b/tests/class5.t @@ -1,6 +1,5 @@ - -IO = terralib.includec("stdio.h") local Class = require("lib/javalike") +local IO = Class.C struct A(Class()) { a : int; diff --git a/tests/lib/javalike.t b/tests/lib/javalike.t index 331a429fe..228f2f922 100644 --- a/tests/lib/javalike.t +++ b/tests/lib/javalike.t @@ -1,7 +1,11 @@ local List = terralib.newlist -local malloc = terralib.externfunction("malloc", uint64 -> &opaque) -local free = terralib.externfunction("free", &opaque -> {}) -local printf = terralib.externfunction("printf", terralib.types.funcpointer({rawstring},int,true)) +local C = terralib.includecstring [[ +#include "stdio.h" +#include "stdlib.h" +]] +local malloc = C.malloc +local free = C.free +local printf = C.printf local function createvtable(T) return end @@ -157,4 +161,4 @@ local function Interface(name,methodlist_) return iface end -return setmetatable({ Interface = Interface }, { __call = Class }) \ No newline at end of file +return setmetatable({ Interface = Interface, C = C }, { __call = Class }) From af046fb46ab5a4c2e4ac196f68241520aae17a1e Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Fri, 21 Jun 2024 20:30:23 -0700 Subject: [PATCH 06/12] Add support for LLVM 18 (#662) --- .github/workflows/main.yml | 16 +++++++++++++--- CHANGES.md | 3 ++- cmake/Modules/FindClang.cmake | 3 +++ release/share/terra/README.md | 1 + src/llvmheaders.h | 12 ++++++++++-- src/llvmheaders_180.h | 34 ++++++++++++++++++++++++++++++++++ src/tcompiler.cpp | 32 +++++++++++++++++++++++++++++--- src/tcuda.cpp | 8 +++++++- src/tllvmutil.cpp | 14 +++++++++++++- tests/constantinits.t | 5 ----- travis.sh | 8 +++++++- 11 files changed, 119 insertions(+), 17 deletions(-) create mode 100644 src/llvmheaders_180.h diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a8f0c2ed9..85ad1bf8f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: os: ['macos-12', 'windows-2022'] - llvm: ['11', '12', '13', '14', '15', '16', '17'] + llvm: ['11', '12', '13', '14', '15', '16', '17', '18'] cuda: ['0', '1'] lua: ['luajit', 'moonjit'] exclude: @@ -28,7 +28,7 @@ jobs: - os: 'macos-12' cuda: '1' - # Windows: exclude LLVM 12-17 + # Windows: exclude LLVM 12-18 - os: 'windows-2022' llvm: '12' - os: 'windows-2022' @@ -41,6 +41,8 @@ jobs: llvm: '16' - os: 'windows-2022' llvm: '17' + - os: 'windows-2022' + llvm: '18' # CUDA: only LLVM 11 - llvm: '12' @@ -55,6 +57,8 @@ jobs: cuda: '1' - llvm: '17' cuda: '1' + - llvm: '18' + cuda: '1' # Moonjit: only LLVM 12 - llvm: '11' @@ -69,6 +73,8 @@ jobs: lua: 'moonjit' - llvm: '17' lua: 'moonjit' + - llvm: '18' + lua: 'moonjit' steps: - uses: actions/checkout@v1 - run: ./travis.sh @@ -93,7 +99,7 @@ jobs: strategy: matrix: distro: ['ubuntu-18.04'] - llvm: ['11', '12.0.1', '13.0.1', '14.0.6', '15.0.2', '16.0.3', '17.0.5'] + llvm: ['11', '12.0.1', '13.0.1', '14.0.6', '15.0.2', '16.0.3', '17.0.5', '18.1.7'] lua: ['luajit', 'moonjit'] cuda: ['0', '1'] test: ['1'] @@ -111,6 +117,8 @@ jobs: cuda: '1' - llvm: '17.0.5' cuda: '1' + - llvm: '18.1.7' + cuda: '1' # Moonjit with LLVM 14 only: - llvm: '11' @@ -125,6 +133,8 @@ jobs: lua: 'moonjit' - llvm: '17.0.5' lua: 'moonjit' + - llvm: '18.1.7' + lua: 'moonjit' include: # Defaults: diff --git a/CHANGES.md b/CHANGES.md index 7e70eae03..c63785ffd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,8 @@ ## Added features - * Support for LLVM 17 + * Support for LLVM 17 and 18 + * Experimental support for SPIR-V code generation (e.g., for Intel GPUs) ## Fixed Bugs diff --git a/cmake/Modules/FindClang.cmake b/cmake/Modules/FindClang.cmake index f9466f560..2e89b62bc 100644 --- a/cmake/Modules/FindClang.cmake +++ b/cmake/Modules/FindClang.cmake @@ -38,6 +38,9 @@ FIND_AND_ADD_CLANG_LIB(clangBasic) if(LLVM_VERSION_MAJOR GREATER 14) FIND_AND_ADD_CLANG_LIB(clangSupport) endif() +if(LLVM_VERSION_MAJOR GREATER 17) + FIND_AND_ADD_CLANG_LIB(clangAPINotes) +endif() find_path(CLANG_INCLUDE_DIRS clang/Basic/Version.h HINTS ${LLVM_INCLUDE_DIRS}) diff --git a/release/share/terra/README.md b/release/share/terra/README.md index 3095224d1..f73739be9 100644 --- a/release/share/terra/README.md +++ b/release/share/terra/README.md @@ -150,6 +150,7 @@ The current recommended version of LLVM is **13**. The following versions are al | 15 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | | 16 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | | 17 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | +| 18 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | \* Please note that AMD GPU support is currently experimental. diff --git a/src/llvmheaders.h b/src/llvmheaders.h index ba9ac0b39..5a52588cb 100644 --- a/src/llvmheaders.h +++ b/src/llvmheaders.h @@ -19,7 +19,11 @@ #include "llvm/IR/LegacyPassManager.h" +#if LLVM_VERSION < 170 #include "llvm/Support/Host.h" +#else +#include "llvm/TargetParser/Host.h" +#endif #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" @@ -32,7 +36,9 @@ #include "llvm/Support/Program.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/IPO.h" +#if LLVM_VERSION < 180 #include "llvm/Transforms/Vectorize.h" +#endif #if LLVM_VERSION < 170 #include "llvm/Transforms/IPO/PassManagerBuilder.h" #else @@ -62,11 +68,13 @@ #include "llvmheaders_160.h" #elif LLVM_VERSION < 180 #include "llvmheaders_170.h" +#elif LLVM_VERSION < 190 +#include "llvmheaders_180.h" #else #error "unsupported LLVM version" // for OSX code completion -#define LLVM_VERSION 170 -#include "llvmheaders_170.h" +#define LLVM_VERSION 180 +#include "llvmheaders_180.h" #endif #define UNIQUEIFY(T, x) (std::unique_ptr(x)) diff --git a/src/llvmheaders_180.h b/src/llvmheaders_180.h new file mode 100644 index 000000000..348eff0f6 --- /dev/null +++ b/src/llvmheaders_180.h @@ -0,0 +1,34 @@ +#include "llvm/IR/CallingConv.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/DataLayout.h" +#include "llvm/IR/Instructions.h" +#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/InlineAsm.h" +#include "llvm/Analysis/CallGraphSCCPass.h" +#include "llvm/Analysis/CallGraph.h" +#include "llvm/IR/DIBuilder.h" +#include "llvm/IR/DebugInfo.h" +#include "llvm/IR/Mangler.h" +//#include "llvm/ExecutionEngine/ObjectImage.h" +#include "llvm/IR/Verifier.h" +#include "llvm/Linker/Linker.h" +#include "llvm/IR/CFG.h" +#include "llvm/IR/InstVisitor.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" + +#include "llvm/Support/VirtualFileSystem.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Rewrite/Frontend/Rewriters.h" +#include "llvm/IR/DiagnosticPrinter.h" +#include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/Object/SymbolSize.h" + +#include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/Support/Error.h" + +#define LLVM_PATH_TYPE std::string +#define RAW_FD_OSTREAM_NONE sys::fs::OF_None +#define RAW_FD_OSTREAM_BINARY sys::fs::OF_None diff --git a/src/tcompiler.cpp b/src/tcompiler.cpp index df93db3d7..1084845dc 100644 --- a/src/tcompiler.cpp +++ b/src/tcompiler.cpp @@ -304,7 +304,12 @@ int terra_inittarget(lua_State *L) { // GV tables CodeModel::Small, #endif - CodeGenOpt::Aggressive); +#if LLVM_VERSION < 180 + CodeGenOpt::Aggressive +#else + CodeGenOptLevel::Aggressive +#endif + ); TT->external = new Module("external", *TT->ctx); TT->external->setTargetTriple(TT->Triple); lua_pushlightuserdata(L, TT); @@ -404,7 +409,13 @@ static void InitializeJIT(TerraCompilationUnit *CU) { .setMAttrs(mattrs) .setEngineKind(EngineKind::JIT) .setTargetOptions(CU->TT->tm->Options) - .setOptLevel(CodeGenOpt::Aggressive) + .setOptLevel( +#if LLVM_VERSION < 180 + CodeGenOpt::Aggressive +#else + CodeGenOptLevel::Aggressive +#endif + ) .setMCJITMemoryManager(std::make_unique(CU)) #if LLVM_VERSION < 120 .setUseOrcMCJITReplacement(true) @@ -545,7 +556,11 @@ class Types { CreatePrimitiveType(typ, t); } break; case T_niltype: { +#if LLVM_VERSION < 170 t->type = Type::getInt8PtrTy(*CU->TT->ctx); +#else + t->type = PointerType::get(*CU->TT->ctx, 0); +#endif } break; case T_opaque: { t->type = Type::getInt8Ty(*CU->TT->ctx); @@ -586,7 +601,13 @@ class Types { } break; } } - Type *FunctionPointerType() { return Type::getInt8PtrTy(*CU->TT->ctx); } + Type *FunctionPointerType() { +#if LLVM_VERSION < 170 + return Type::getInt8PtrTy(*CU->TT->ctx); +#else + return PointerType::get(*CU->TT->ctx, 0); +#endif + } bool LookupTypeCache(Obj *typ, TType **t) { *t = (TType *)CU->symbols->getud(typ); // try to look up the cached type if (*t == NULL) { @@ -1673,7 +1694,9 @@ static CallingConv::ID ParseCallingConv(const char *cc) { init = true; ccmap["fastcc"] = CallingConv::Fast; ccmap["coldcc"] = CallingConv::Cold; +#if LLVM_VERSION < 180 ccmap["webkit_jscc"] = CallingConv::WebKit_JS; +#endif ccmap["anyregcc"] = CallingConv::AnyReg; ccmap["preserve_mostcc"] = CallingConv::PreserveMost; ccmap["preserve_allcc"] = CallingConv::PreserveAll; @@ -2005,6 +2028,9 @@ struct FunctionEmitter { cast(fstate->func->getEntryBlock().getTerminator()); Constant *r = dyn_cast(term->getReturnValue()); assert(r || !"constant expression was not constant"); +#if LLVM_VERSION >= 170 + CU->fam.clear(*fstate->func, fstate->func->getName()); +#endif fstate->func->eraseFromParent(); return r; } diff --git a/src/tcuda.cpp b/src/tcuda.cpp index 02ccdd408..bc440ffcd 100644 --- a/src/tcuda.cpp +++ b/src/tcuda.cpp @@ -151,7 +151,13 @@ void moduleToPTX(terra_State *T, llvm::Module *M, int major, int minor, std::str PMB.Inliner = llvm::createFunctionInliningPass(PMB.OptLevel, 0, false); PMB.LoopVectorize = false; #endif - auto FileType = llvm::CGFT_AssemblyFile; + auto FileType = +#if LLVM_VERSION < 180 + llvm::CGFT_AssemblyFile +#else + llvm::CodeGenFileType::AssemblyFile +#endif + ; llvm::legacy::PassManager PM; #if LLVM_VERSION < 160 diff --git a/src/tllvmutil.cpp b/src/tllvmutil.cpp index d7c9e5995..a41d709d1 100644 --- a/src/tllvmutil.cpp +++ b/src/tllvmutil.cpp @@ -330,7 +330,19 @@ bool llvmutil_emitobjfile(Module *Mod, TargetMachine *TM, bool outputobjectfile, Mod->setDataLayout(TM->createDataLayout()); #endif - CodeGenFileType ft = outputobjectfile ? CGFT_ObjectFile : CGFT_AssemblyFile; + CodeGenFileType ft = outputobjectfile ? +#if LLVM_VERSION < 180 + CGFT_ObjectFile +#else + CodeGenFileType::ObjectFile +#endif + : +#if LLVM_VERSION < 180 + CGFT_AssemblyFile +#else + CodeGenFileType::AssemblyFile +#endif + ; emitobjfile_t &destf = dest; diff --git a/tests/constantinits.t b/tests/constantinits.t index f38cb4222..c78853ca7 100644 --- a/tests/constantinits.t +++ b/tests/constantinits.t @@ -1,8 +1,3 @@ -if terralib.llvm_version >= 170 and require("ffi").os == "Linux" then - print("Skipping broken test on Linux, see #644") - return -- FIXME: https://github.com/terralang/terra/issues/644 -end - function failit(match,fn) local success,msg = xpcall(fn,debug.traceback) --print(msg) diff --git a/travis.sh b/travis.sh index 1f3704f29..5670ba3eb 100755 --- a/travis.sh +++ b/travis.sh @@ -33,7 +33,13 @@ if [[ $(uname) = Linux ]]; then exit 1 elif [[ $(uname) = Darwin ]]; then - if [[ $LLVM_VERSION = 17 ]]; then + if [[ $LLVM_VERSION = 18 ]]; then + curl -L -O https://github.com/terralang/llvm-build/releases/download/llvm-18.1.7/clang+llvm-18.1.7-x86_64-apple-darwin.tar.xz + tar xf clang+llvm-18.1.7-x86_64-apple-darwin.tar.xz + ln -s clang+llvm-18.1.7-x86_64-apple-darwin/bin/llvm-config llvm-config-17 + ln -s clang+llvm-18.1.7-x86_64-apple-darwin/bin/clang clang-17 + export CMAKE_PREFIX_PATH=$PWD/clang+llvm-18.1.7-x86_64-apple-darwin + elif [[ $LLVM_VERSION = 17 ]]; then curl -L -O https://github.com/terralang/llvm-build/releases/download/llvm-17.0.5/clang+llvm-17.0.5-x86_64-apple-darwin.tar.xz tar xf clang+llvm-17.0.5-x86_64-apple-darwin.tar.xz ln -s clang+llvm-17.0.5-x86_64-apple-darwin/bin/llvm-config llvm-config-17 From 7c14775887e1cfdbeb9d7e1b80bb9a7a90276013 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Fri, 21 Jun 2024 22:15:39 -0700 Subject: [PATCH 07/12] Update to newer FreeBSD image and fix build (#667) --- .cirrus.yml | 4 ++-- cmake/Modules/GetLuaJIT.cmake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 3da6d48de..cf7f97904 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -2,8 +2,7 @@ freebsd_task: name: FreeBSD freebsd_instance: matrix: - image_family: freebsd-13-2 - # image_family: freebsd-12-3 + image_family: freebsd-14-0 env: matrix: LLVM_VERSION: 11 @@ -13,6 +12,7 @@ freebsd_task: LLVM_VERSION: 15 LLVM_VERSION: 16 LLVM_VERSION: 17 + LLVM_VERSION: 18 install_script: pkg install -y bash coreutils cmake gmake llvm$LLVM_VERSION script: | export CC=cc diff --git a/cmake/Modules/GetLuaJIT.cmake b/cmake/Modules/GetLuaJIT.cmake index c977e087a..207b17593 100644 --- a/cmake/Modules/GetLuaJIT.cmake +++ b/cmake/Modules/GetLuaJIT.cmake @@ -162,7 +162,7 @@ else() DEPENDS ${LUAJIT_SOURCE_DIR} # MACOSX_DEPLOYMENT_TARGET is a workaround for https://github.com/LuaJIT/LuaJIT/issues/484 # see also https://github.com/LuaJIT/LuaJIT/issues/575 - COMMAND ${MAKE_EXE} install "PREFIX=${LUAJIT_INSTALL_PREFIX}" "CC=${CMAKE_C_COMPILER}" "STATIC_CC=${CMAKE_C_COMPILER} -fPIC" CCDEBUG=$<$:-g> XCFLAGS=-DLUAJIT_ENABLE_GC64 MACOSX_DEPLOYMENT_TARGET=10.7 + COMMAND ${CMAKE_COMMAND} -E env --unset=MAKEFLAGS ${MAKE_EXE} install "PREFIX=${LUAJIT_INSTALL_PREFIX}" "CC=${CMAKE_C_COMPILER}" "STATIC_CC=${CMAKE_C_COMPILER} -fPIC" CCDEBUG=$<$:-g> XCFLAGS=-DLUAJIT_ENABLE_GC64 MACOSX_DEPLOYMENT_TARGET=10.7 WORKING_DIRECTORY ${LUAJIT_SOURCE_DIR} VERBATIM ) From e6ce24d091018f66b702ccecd180aca37eb6917b Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Sat, 22 Jun 2024 09:17:01 -0700 Subject: [PATCH 08/12] Update README support table. --- release/share/terra/README.md | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/release/share/terra/README.md b/release/share/terra/README.md index f73739be9..b961b2d40 100644 --- a/release/share/terra/README.md +++ b/release/share/terra/README.md @@ -112,11 +112,12 @@ Building Terra If the binary releases are not appropriate, then you can also build Terra from source. Terra has the following dependencies: - * A working C/C++ compiler (GCC, Clang, MSVC, etc.) - * Windows only: Visual Studio 2013, 2015, 2017 or 2019 + * A working C/C++ compiler (GCC, Clang, MSVC, etc.) that supports at least C++ 17 + * Windows only: Visual Studio 2022 (other versions may work but are untested) * CMake (version 3.5 or greater) + * Linux, macOS, FreeBSD only: GNU Make (required for building LuaJIT) * LLVM and Clang (see suppport table below) - * LuaJIT (note this is downloaded and installed automatically be default) + * LuaJIT (note this is downloaded and installed automatically by default) * *Optional:* CUDA On recent versions of Ubuntu, you can get these dependencies with: @@ -141,18 +142,20 @@ pkg install -y cmake llvm13 The current recommended version of LLVM is **13**. The following versions are also supported: -| Version | Linux | macOS | FreeBSD | Windows | CUDA | AMD GPU \* | Notes | -| ------- | ----- | ----- | ------- | ------- | ---- | ---------- | ----- | -| 11 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | -| 12 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | | | -| 13 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | -| 14 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | -| 15 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | -| 16 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | -| 17 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | -| 18 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :heavy_check_mark: | :heavy_check_mark: | | - -\* Please note that AMD GPU support is currently experimental. +| Version | Linux | macOS | FreeBSD | Windows | NVIDIA/CUDA | AMD/HIP \* | Intel/SPIRV \*\* | Notes | +| ------- | ------------- | ------------- | ------------- | ------------- | ------------- | -------------- | ---------------- | ----- | +| 11 | :green_heart: | :green_heart: | :green_heart: | :green_heart: | :green_heart: | | | | +| 12 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | | | | +| 13 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | +| 14 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | +| 15 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | +| 16 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | +| 17 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | :green_heart: | | +| 18 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :green_heart: | :green_heart: | | + +\* AMD GPU support is currently experimental. LLVM 18 is **strongly** recommended. + +\*\* Intel GPU (SPIR-V) support is currently experimental. The following versions were previously supported by Terra: From 1f2742d7c03c46175361de9b3e867187d87406c1 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Sat, 22 Jun 2024 09:21:02 -0700 Subject: [PATCH 09/12] Update README recommended LLVM versions. --- release/share/terra/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release/share/terra/README.md b/release/share/terra/README.md index b961b2d40..7849277ca 100644 --- a/release/share/terra/README.md +++ b/release/share/terra/README.md @@ -140,7 +140,7 @@ pkg install -y cmake llvm13 ### Supported LLVM Versions ### -The current recommended version of LLVM is **13**. The following versions are also supported: +The current recommended version of LLVM is **13** for most platforms, except Windows (x86) and Linux (ARM) where LLVM 11 is required. The following versions are also supported: | Version | Linux | macOS | FreeBSD | Windows | NVIDIA/CUDA | AMD/HIP \* | Intel/SPIRV \*\* | Notes | | ------- | ------------- | ------------- | ------------- | ------------- | ------------- | -------------- | ---------------- | ----- | From 3b57fe1a00bf6697119e2c21b1468350cefedadf Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Sat, 22 Jun 2024 09:30:53 -0700 Subject: [PATCH 10/12] Update README notes about GPU support. --- release/share/terra/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release/share/terra/README.md b/release/share/terra/README.md index 7849277ca..7526766f6 100644 --- a/release/share/terra/README.md +++ b/release/share/terra/README.md @@ -119,6 +119,7 @@ If the binary releases are not appropriate, then you can also build Terra from s * LLVM and Clang (see suppport table below) * LuaJIT (note this is downloaded and installed automatically by default) * *Optional:* CUDA + * *Note:* In addition to CUDA, Terra also supports AMD and Intel GPUs. However, Terra does not link their GPU toolkits directly so this is not a build requirement. On recent versions of Ubuntu, you can get these dependencies with: From 8c279c38e8a9202e80869ce93dc3769f01f22406 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Tue, 25 Jun 2024 07:48:59 -0700 Subject: [PATCH 11/12] Update release packages to use LLVM 18 (#669) --- .github/workflows/main.yml | 22 +++++++++++----------- release/share/terra/README.md | 14 +++++++------- travis.sh | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 85ad1bf8f..100f30269 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: name: Check Format runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - run: ./travis.sh env: CHECK_CLANG_FORMAT: 1 @@ -76,7 +76,7 @@ jobs: - llvm: '18' lua: 'moonjit' steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - run: ./travis.sh shell: bash env: @@ -87,7 +87,7 @@ jobs: SLIB_INCLUDE_LLVM: 1 SLIB_INCLUDE_LUAJIT: 1 TERRA_LUA: ${{ matrix.lua }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: terra-${{ matrix.os }}-x86_64-llvm-${{ matrix.llvm }} path: | @@ -192,7 +192,7 @@ jobs: # static: '0' # test: '1' steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - run: ./travis.sh env: DOCKER_DISTRO: ${{ matrix.distro }} @@ -220,7 +220,7 @@ jobs: - arch: 'ppc64le' llvm: '11.1.0' steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - run: ./travis.sh env: DOCKER_DISTRO: ${{ matrix.distro }} @@ -229,7 +229,7 @@ jobs: DOCKER_CUDA: ${{ matrix.cuda }} DOCKER_VARIANT: ${{ matrix.variant }} DOCKER_TEST: ${{ matrix.test }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: docker-${{ matrix.distro }}-${{ matrix.arch }}-llvm-${{ matrix.llvm }} path: | @@ -239,11 +239,11 @@ jobs: name: Compatibility Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - run: ./docker/compatibility_test.sh ubuntu 18.04 "18.04 20.04 22.04" "" 13.0.1 luajit prebuilt 2 - - uses: actions/upload-artifact@v2 + - uses: actions/checkout@v4 + - run: ./docker/compatibility_test.sh ubuntu 18.04 "18.04 20.04 22.04 24.04" "" 18.1.7 luajit prebuilt 2 + - uses: actions/upload-artifact@v4 with: - name: docker-ubuntu-18.04-x86_64-llvm-13 + name: docker-ubuntu-18.04-x86_64-llvm-18 path: | terra-*.tar.xz terra-*.7z @@ -255,7 +255,7 @@ jobs: nixpkgs: ['unstable', '24.05'] cuda: ['false', 'true'] steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v13 with: nix_path: nixpkgs=channel:nixos-${{ matrix.nixpkgs }} diff --git a/release/share/terra/README.md b/release/share/terra/README.md index 7526766f6..69269d1ca 100644 --- a/release/share/terra/README.md +++ b/release/share/terra/README.md @@ -124,24 +124,24 @@ If the binary releases are not appropriate, then you can also build Terra from s On recent versions of Ubuntu, you can get these dependencies with: ``` -sudo apt-get install build-essential cmake git llvm-13-dev libclang-13-dev clang-13 libmlir-13-dev libedit-dev libncurses5-dev zlib1g-dev libpfm4-dev +sudo apt-get install build-essential cmake git llvm-18-dev libclang-18-dev clang-18 libmlir-18-dev libedit-dev libncurses5-dev zlib1g-dev libpfm4-dev ``` On macOS with Homebrew, the following should be sufficient: ``` -brew install cmake llvm@13 +brew install cmake llvm@18 ``` On FreeBSD, use: ``` -pkg install -y cmake llvm13 +pkg install -y cmake gmake llvm18 ``` ### Supported LLVM Versions ### -The current recommended version of LLVM is **13** for most platforms, except Windows (x86) and Linux (ARM) where LLVM 11 is required. The following versions are also supported: +The current recommended version of LLVM is **18** for most platforms, except Windows (x86) and Linux (ARM) where LLVM 11 is required. The following versions are also supported: | Version | Linux | macOS | FreeBSD | Windows | NVIDIA/CUDA | AMD/HIP \* | Intel/SPIRV \*\* | Notes | | ------- | ------------- | ------------- | ------------- | ------------- | ------------- | -------------- | ---------------- | ----- | @@ -149,10 +149,10 @@ The current recommended version of LLVM is **13** for most platforms, except Win | 12 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | | | | | 13 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | | 14 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | -| 15 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | -| 16 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | | | +| 15 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | :yellow_heart: | | +| 16 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | :yellow_heart: | | | 17 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :yellow_heart: | :green_heart: | | -| 18 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :green_heart: | :green_heart: | | +| 18 | :green_heart: | :green_heart: | :green_heart: | | :green_heart: | :green_heart: | :green_heart: | | \* AMD GPU support is currently experimental. LLVM 18 is **strongly** recommended. diff --git a/travis.sh b/travis.sh index 5670ba3eb..c48b85125 100755 --- a/travis.sh +++ b/travis.sh @@ -178,7 +178,7 @@ if [[ $(uname) != Darwin ]]; then fi # Only deploy builds with LLVM 13 (macOS) and 11 (Windows). -if [[ (( $(uname) == Darwin && $LLVM_VERSION = 13 ) || ( $(uname) == MINGW* && $LLVM_VERSION = 11 && $USE_CUDA -eq 1 )) && $SLIB_INCLUDE_LLVM -eq 1 && $TERRA_LUA = luajit ]]; then +if [[ (( $(uname) == Darwin && $LLVM_VERSION = 18 ) || ( $(uname) == MINGW* && $LLVM_VERSION = 11 && $USE_CUDA -eq 1 )) && $SLIB_INCLUDE_LLVM -eq 1 && $TERRA_LUA = luajit ]]; then RELEASE_NAME=terra-`uname | sed -e s/Darwin/OSX/ | sed -e s/MINGW.*/Windows/`-`uname -m`-`git rev-parse --short HEAD` mv install $RELEASE_NAME if [[ $(uname) = MINGW* ]]; then From cc543dbcc85dbda84d5aec624d80f76642566940 Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Tue, 25 Jun 2024 10:23:11 -0700 Subject: [PATCH 12/12] Bump version to 1.2.0 (#670) --- CHANGES.md | 6 +++++- default.nix | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c63785ffd..85b58c70f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ -# Unreleased Changes (Intended to be Version 1.2.0) +# Release 1.2.0 (2024-06-25) + +This release adds new LLVM versions and introduces experimental support for SPIR-V code generation. Note that as of the tested LLVM versions, LLVM's native SPIR-V backend is unable to generate correct SPIR-V code in all cases; but the LLVM SPIR-V target can still be used in combination with the [LLVM/SPIR-V Translator](https://github.com/KhronosGroup/SPIRV-LLVM-Translator) to generate valid code. + +Users who generate code for AMD GPUs are strongly encouraged to upgrade to LLVM 18 and ROCm 6.0.0, as previous version combinations generate bad code to varying degrees. ## Added features diff --git a/default.nix b/default.nix index a3c140c37..1365b5871 100644 --- a/default.nix +++ b/default.nix @@ -44,7 +44,7 @@ let in stdenv.mkDerivation rec { pname = "terra"; - version = "1.1.1"; + version = "1.2.0"; src = ./.;