git: e083afb30dbf - main - devel/ispc: Add support for LLVM 13

From: Yuri Victorovich <yuri_at_FreeBSD.org>
Date: Sat, 08 Jan 2022 21:23:55 UTC
The branch main has been updated by yuri:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e083afb30dbfe0b9c2be4ff751d0f775e40b4638

commit e083afb30dbfe0b9c2be4ff751d0f775e40b4638
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2022-01-08 21:20:49 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2022-01-08 21:23:52 +0000

    devel/ispc: Add support for LLVM 13
    
    PR:             260976
    Submitted by:   VVD <vvd@unislabs.com> (original version)
---
 devel/ispc/Makefile                   | 14 ++++++++------
 devel/ispc/files/patch-src_module.cpp | 14 ++++++++++++++
 devel/ispc/files/patch-src_opt.cpp    | 15 +++++++++++++++
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/devel/ispc/Makefile b/devel/ispc/Makefile
index 8bcfa95a296a..9008d20dd145 100644
--- a/devel/ispc/Makefile
+++ b/devel/ispc/Makefile
@@ -3,7 +3,7 @@
 PORTNAME=	ispc
 DISTVERSIONPREFIX=	v
 DISTVERSION=	1.16.1
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	devel
 
 MAINTAINER=	yuri@FreeBSD.org
@@ -23,11 +23,6 @@ USES=		bison cmake compiler:c++14-lang python:build,test shebangfix
 USE_GITHUB=	yes
 SHEBANG_FILES=	*.py
 
-#LLVM_VERSION=	-devel # fails with 12: call to non-static member function without an object argument: llvm::DebugLoc::get
-		# Release notes https://github.com/ispc/ispc/blob/master/docs/ReleaseNotes.txt list compatible LLVM versions, but they assume that extra patches are applied to LLVM
-		# LLVM build script: https://github.com/ispc/ispc/blob/master/scripts/build.sh
-LLVM_VERSION=	11 # it fails with -devel (13.0.d20210308), with 12.0.0.r2 it also fails, using 11 that it succeeds with
-
 CONFIGURE_ENV=	PATH=${LOCALBASE}/llvm${LLVM_VERSION}/bin:${PATH}
 CMAKE_OFF=	ISPC_NO_DUMPS ISPC_INCLUDE_EXAMPLES
 
@@ -59,6 +54,13 @@ GENX_PLIST_FILES=	include/ispcrt/ispcrt.h \
 			lib/libispcrt.so.${PORTVERSION} \
 			lib/libispcrt_static.a
 
+.include <bsd.port.options.mk>
+.if ${LLVM_DEFAULT:M[7891]0} || ${LLVM_DEFAULT:M1[12]} # max(LLVM_DEFAULT,13)
+LLVM_VERSION=	13
+.else
+LLVM_VERSION=	${LLVM_DEFAULT}
+.endif
+
 do-test: # some tests fail: https://github.com/ispc/ispc/issues/1868
 	@cd ${WRKSRC} && ISPC_HOME=${BUILD_WRKSRC}/bin ./run_tests.py
 
diff --git a/devel/ispc/files/patch-src_module.cpp b/devel/ispc/files/patch-src_module.cpp
index 987c2fcb2fd6..06bfac61b41f 100644
--- a/devel/ispc/files/patch-src_module.cpp
+++ b/devel/ispc/files/patch-src_module.cpp
@@ -18,3 +18,17 @@
      Opts.setSPIRVAllowUnknownIntrinsics({"llvm.genx"});
  #else
      llvm::cl::opt<bool> SPIRVAllowUnknownIntrinsics(
+@@ -1314,7 +1314,12 @@ bool Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine, llvm::Module *module, OutputType outputType,
+     llvm::CodeGenFileType fileType = (outputType == Object) ? llvm::CGFT_ObjectFile : llvm::CGFT_AssemblyFile;
+     bool binary = (fileType == llvm::CGFT_ObjectFile);
+
+-    llvm::sys::fs::OpenFlags flags = binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text;
++    llvm::sys::fs::OpenFlags flags = binary ?
++#if ISPC_LLVM_VERSION >= ISPC_LLVM_13_0
++                                              llvm::sys::fs::OF_None : llvm::sys::fs::OF_Text;
++#else
++                                              llvm::sys::fs::F_None  : llvm::sys::fs::F_Text;
++#endif
+
+     std::error_code error;
+
diff --git a/devel/ispc/files/patch-src_opt.cpp b/devel/ispc/files/patch-src_opt.cpp
index de3ecdcbd15f..3bf08c14a7d0 100644
--- a/devel/ispc/files/patch-src_opt.cpp
+++ b/devel/ispc/files/patch-src_opt.cpp
@@ -62,3 +62,18 @@ ISPC devs insist on using dump() functions which LLVM devs consider a debug func
      return true;
  }
  
+@@ -4687,7 +4687,13 @@ void DebugPassFile::run(llvm::Module &module, bool init)
+     std::error_code EC;
+     char fname[100];
+     snprintf(fname, sizeof(fname), "%s_%d_%s.ll", init ? "init" : "ir", pnum, sanitize(std::string(pname)).c_str());
+-    llvm::raw_fd_ostream OS(fname, EC, llvm::sys::fs::F_None);
++    llvm::raw_fd_ostream OS(fname, EC,
++#if ISPC_LLVM_VERSION >= ISPC_LLVM_13_0
++                                       llvm::sys::fs::OF_None
++#else
++                                       llvm::sys::fs::F_None
++#endif
++    );
+     Assert(!EC && "IR dump file creation failed!");
+     module.print(OS, 0);
+ }