Skip to content

Commit 8a10a97

Browse files
authored
Improve LLVM runner (#1105)
This allows for more debug symbols in the LLVM runner and makes it more robust on systems with different clang/opt installations. I also removed the requirement for llc, as we do not use it currently.
1 parent 319039c commit 8a10a97

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

effekt/jvm/src/main/scala/effekt/Runner.scala

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,10 @@ object LLVMRunner extends Runner[String] {
279279

280280
override def includes(path: File): List[File] = List(path / ".." / "llvm")
281281

282-
lazy val clangCmd = discoverExecutable(List("clang-18", "clang"), List("--version"))
283-
lazy val llcCmd = discoverExecutable(List("llc-18", "llc"), List("--version"))
284-
lazy val optCmd = discoverExecutable(List("opt-18", "opt"), List("--version"))
282+
lazy val clangCmd = discoverExecutable(List("clang-20", "clang-19", "clang-18", "clang"), List("--version"))
285283

286284
def checkSetup(): Either[String, Unit] =
287285
clangCmd.getOrElseAborting { return Left("Cannot find clang. This is required to use the LLVM backend.") }
288-
llcCmd.getOrElseAborting { return Left("Cannot find llc. This is required to use the LLVM backend.") }
289-
optCmd.getOrElseAborting { return Left("Cannot find opt. This is required to use the LLVM backend.") }
290286
Right(())
291287

292288
def libuvArgs(using C: Context): Seq[String] =
@@ -335,40 +331,33 @@ object LLVMRunner extends Runner[String] {
335331

336332
def missing(cmd: String) = C.abort(s"Cannot find ${cmd}. This is required to use the LLVM backend.")
337333
val clang = clangCmd.getOrElse(missing("clang"))
338-
val llc = llcCmd.getOrElse(missing("llc"))
339-
val opt = optCmd.getOrElse(missing("opt"))
340334

341335
val clangMainFile = (C.config.libPath / ".." / "llvm" / "main.c").unixPath
342336
val executableFile = basePath
343337

344-
if (useLTO) {
345-
// Convert to bitcode with aggressive optimizations
346-
exec(opt, llPath, "-O3", "-o", bcPath)
347-
348-
var clangArgs = Seq(clang, clangMainFile, bcPath, "-o", executableFile) ++ linkedLibraries
349-
350-
clangArgs ++= Seq(
351-
"-O3",
352-
"-flto=full",
353-
"-Wno-override-module"
354-
)
355-
356-
if (C.config.native()) {
357-
clangArgs :+= "-march=native"
358-
}
338+
var clangArgs = Seq(clang, llPath, clangMainFile, "-Wno-override-module", "-o", executableFile)
339+
++ linkedLibraries
359340

360-
exec(clangArgs: _*)
361-
} else {
362-
exec(opt, llPath, "-O2", "-o", bcPath)
341+
if (C.config.native()) {
342+
clangArgs ++= Seq("-march=native")
343+
}
363344

364-
var clangArgs = Seq(clang, clangMainFile, "-o", executableFile, bcPath, "-Wno-override-module") ++ linkedLibraries
345+
if (C.config.debug()) {
346+
clangArgs ++= Seq("-g", "-Wall", "-Wextra", "-Werror")
347+
}
365348

366-
if (C.config.debug()) clangArgs ++= Seq("-g", "-Wall", "-Wextra", "-Werror")
367-
if (C.config.valgrind()) clangArgs ++= Seq("-O0", "-g")
368-
else if (C.config.debug()) clangArgs ++= Seq("-fsanitize=address,undefined", "-fstack-protector-all")
349+
if (C.config.valgrind()) {
350+
clangArgs ++= Seq("-Og", "-g")
351+
} else if (C.config.debug()) {
352+
// these can only be used without valgrind
353+
clangArgs ++= Seq("-fsanitize=address,undefined", "-fstack-protector-all")
354+
}
369355

370-
exec(clangArgs: _*)
356+
if (useLTO) {
357+
clangArgs ++= Seq("-O3", "-flto=full")
371358
}
372359

360+
exec(clangArgs: _*)
361+
373362
Some(executableFile)
374363
}

0 commit comments

Comments
 (0)