Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-slang-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ on:
jobs:
build:
runs-on: ${{ fromJSON(inputs.runs-on) }}
timeout-minutes: 60
timeout-minutes: 120

defaults:
run:
Expand Down
58 changes: 24 additions & 34 deletions cmake/LLVM.cmake
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
# A convenience on top of the llvm package's cmake files, this creates a target
# to pass to target_link_libraries which correctly pulls in the llvm include
# dir and other compile dependencies
function(llvm_target_from_components target_name)
set(components ${ARGN})
llvm_map_components_to_libnames(llvm_libs
${components}
)
add_library(${target_name} INTERFACE)
target_link_libraries(${target_name} INTERFACE ${llvm_libs})
target_include_directories(
${target_name}
SYSTEM
INTERFACE ${LLVM_INCLUDE_DIRS}
)
target_compile_definitions(${target_name} INTERFACE ${LLVM_DEFINITIONS})
if(NOT LLVM_ENABLE_RTTI)
# Make sure that we don't disable rtti if this library wasn't compiled with
# support
add_supported_cxx_flags(${target_name} INTERFACE -fno-rtti /GR-)
endif()
endfunction()

# The same for clang
function(clang_target_from_libs target_name)
set(clang_libs ${ARGN})
add_library(${target_name} INTERFACE)
target_link_libraries(${target_name} INTERFACE ${clang_libs})
# Check if we have the individual modules or not.
if(TARGET clangBasic)
target_link_libraries(${target_name} INTERFACE ${clang_libs})
else()
# If not, we can still link to the catch-all clang-cpp.
target_link_libraries(${target_name} INTERFACE clang-cpp)
endif()
target_include_directories(
${target_name}
SYSTEM
INTERFACE ${CLANG_INCLUDE_DIRS}
)
target_compile_definitions(${target_name} INTERFACE ${CLANG_DEFINITIONS})
if(NOT LLVM_ENABLE_RTTI)
# Make sure that we don't disable rtti if this library wasn't compiled with
# support
add_supported_cxx_flags(${target_name} INTERFACE -fno-rtti /GR-)
endif()
endfunction()

function(fetch_or_build_slang_llvm)
Expand All @@ -60,10 +38,13 @@ function(fetch_or_build_slang_llvm)
endif()
endif()
elseif(SLANG_SLANG_LLVM_FLAVOR STREQUAL "USE_SYSTEM_LLVM")
find_package(LLVM 14.0 REQUIRED CONFIG)
find_package(LLVM 21.1 REQUIRED CONFIG)
find_package(Clang REQUIRED CONFIG)

llvm_target_from_components(llvm-dep filecheck native orcjit)
if(LLVM_LINK_LLVM_DYLIB)
set(LLVM_LINK_TYPE USE_SHARED)
endif()

clang_target_from_libs(
clang-dep
clangBasic
Expand All @@ -76,7 +57,7 @@ function(fetch_or_build_slang_llvm)
slang_add_target(
source/slang-llvm
MODULE
LINK_WITH_PRIVATE core compiler-core llvm-dep clang-dep
LINK_WITH_PRIVATE core compiler-core clang-dep
# We include slang.h, but don't need to link with it
INCLUDE_FROM_PRIVATE slang
# We include tools/slang-test/filecheck.h, but don't need to link
Expand All @@ -90,6 +71,9 @@ function(fetch_or_build_slang_llvm)
INSTALL_COMPONENT slang-llvm
EXPORT_SET_NAME SlangTargets
)

llvm_config(slang-llvm ${LLVM_LINK_TYPE} filecheck native orcjit)

# If we don't include this, then the symbols in the LLVM linked here may
# conflict with those of other LLVMs linked at runtime, for instance in mesa.
set_target_properties(
Expand All @@ -104,11 +88,17 @@ function(fetch_or_build_slang_llvm)

# The LLVM headers need a warning disabling, which somehow slips through \external
if(MSVC)
target_compile_options(slang-llvm PRIVATE -wd4244)
target_compile_options(slang-llvm PRIVATE -wd4244 /Zc:preprocessor)
endif()

if(NOT LLVM_ENABLE_RTTI)
# Make sure that we don't disable rtti if this library wasn't compiled with
# support
add_supported_cxx_flags(slang-llvm PRIVATE -fno-rtti /GR-)
endif()

# TODO: Put a check here that libslang-llvm.so doesn't have a 'NEEDED'
# directive for libLLVM-14.so, it's almost certainly going to break at
# directive for libLLVM-21.so, it's almost certainly going to break at
# runtime in surprising ways when linked alongside Mesa (or anything else
# pulling in libLLVM.so)
endif()
Expand Down
4 changes: 2 additions & 2 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ There are several options for getting llvm-support:
containing such a file
- If this isn't set then the build system tries to download it from the
release on github matching the current tag. If such a tag doesn't exist
or doesn't have the correct os*arch combination then the latest release
or doesn't have the correct os\*arch combination then the latest release
will be tried.
- If `SLANG_SLANG_LLVM_BINARY_URL` is `FETCH_BINARY_IF_POSSIBLE` then in
the case that a prebuilt binary can't be found then the build will proceed
as though `DISABLE` was chosen
- Use a system supplied LLVM: `-DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM`, you
must have llvm-14.0 and a matching libclang installed. It's important that
must have llvm-21.1 and a matching libclang installed. It's important that
either:
- You don't end up linking to a dynamic libllvm.so, this will almost
certainly cause multiple versions of LLVM to be loaded at runtime,
Expand Down
3 changes: 2 additions & 1 deletion external/build-llvm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $null = Register-EngineEvent PowerShell.Exiting -Action $cleanup

# Default values
$repo = "https://github.com/llvm/llvm-project"
$branch = "llvmorg-14.0.6"
$branch = "llvmorg-21.1.2"
$sourceDir = $tempDir.FullName
$installPrefix = ""
$config = "Release"
Expand Down Expand Up @@ -123,6 +123,7 @@ $cmakeArgumentsForSlang = @(
"-DLLVM_INCLUDE_EXAMPLES=0"
"-DLLVM_INCLUDE_TESTS=0"
"-DLLVM_ENABLE_TERMINFO=0"
"-DLLVM_ENABLE_DIA_SDK=0"
"-DCLANG_BUILD_TOOLS=0"
"-DCLANG_ENABLE_STATIC_ANALYZER=0"
"-DCLANG_ENABLE_ARCMT=0"
Expand Down
5 changes: 4 additions & 1 deletion external/build-llvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ trap cleanup EXIT SIGHUP SIGINT SIGTERM
# Options and parsing
#
repo=https://github.com/llvm/llvm-project
branch=llvmorg-14.0.6
branch=llvmorg-21.1.2
source_dir=$temp_dir
install_prefix=
config=Release
Expand Down Expand Up @@ -122,6 +122,9 @@ cmake_arguments_for_slang=(
-DLLVM_INCLUDE_EXAMPLES=0
-DLLVM_INCLUDE_TESTS=0
-DLLVM_ENABLE_TERMINFO=0
-DLLVM_FORCE_VC_REVISION=0
-DLLVM_FORCE_VC_REPOSITORY="https://github.com/llvm/llvm-project"
-DLLVM_ENABLE_DIA_SDK=0
-DCLANG_BUILD_TOOLS=0
-DCLANG_ENABLE_STATIC_ANALYZER=0
-DCLANG_ENABLE_ARCMT=0
Expand Down
4 changes: 2 additions & 2 deletions source/slang-llvm/slang-llvm-filecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <core/slang-com-object.h>
#include <llvm/ADT/SmallString.h>
#include <llvm/FileCheck/FileCheck.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/Support/raw_ostream.h>
#include <slang-test/filecheck.h>

Expand Down Expand Up @@ -126,8 +127,7 @@ TestResult LLVMFileCheck::performTest(
TestMessageType::RunError};
sourceManager.setDiagHandler(fileCheckDiagHandler, static_cast<void*>(&reporterData));

auto checkPrefix = fc.buildCheckPrefixRegex();
if (fc.readCheckFile(sourceManager, rulesStringRef, checkPrefix))
if (fc.readCheckFile(sourceManager, rulesStringRef))
{
// FileCheck failed to find or understand any FileCheck rules in
// the input file, automatic fail, and reported to the diag handler .
Expand Down
68 changes: 28 additions & 40 deletions source/slang-llvm/slang-llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/Version.h"
#include "clang/CodeGen/CodeGenAction.h"
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
#include "clang/Config/config.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/Options.h"
Expand All @@ -15,6 +15,7 @@
#include "clang/Frontend/Utils.h"
#include "clang/FrontendTool/Utils.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/LinkAllPasses.h"
Expand Down Expand Up @@ -226,13 +227,8 @@ void* LLVMJITSharedLibrary::castAs(const Guid& guid)

void* LLVMJITSharedLibrary::findSymbolAddressByName(char const* name)
{
auto fnExpected = m_jit->lookup(name);
if (fnExpected)
{
auto fn = std::move(*fnExpected);
return (void*)fn.getAddress();
}
return nullptr;
auto fn = m_jit->lookup(name);
return fn ? (void*)fn.get().getValue() : nullptr;
}


Expand Down Expand Up @@ -653,7 +649,7 @@ SlangResult LLVMDownstreamCompiler::compile(
pchOps->registerWriter(std::make_unique<ObjectFilePCHContainerWriter>());
pchOps->registerReader(std::make_unique<ObjectFilePCHContainerReader>());

IntrusiveRefCntPtr<DiagnosticOptions> diagOpts = new DiagnosticOptions();
DiagnosticOptions diagOpts;

ComPtr<IArtifactDiagnostics> diagnostics(new ArtifactDiagnostics);

Expand Down Expand Up @@ -721,8 +717,6 @@ SlangResult LLVMDownstreamCompiler::compile(
}
}

const InputKind inputKind(language, InputKind::Format::Source);

{
auto& opts = invocation.getFrontendOpts();

Expand All @@ -732,7 +726,7 @@ SlangResult LLVMDownstreamCompiler::compile(
// input is a memory buffer. For Slang usage, this probably isn't an issue, because it's
// *output* typically holds #line directives.
{

const InputKind inputKind(language, InputKind::Format::Source);
FrontendInputFile inputFile(*sourceBuffer, inputKind);
opts.Inputs.push_back(inputFile);
}
Expand Down Expand Up @@ -776,24 +770,19 @@ SlangResult LLVMDownstreamCompiler::compile(
}

{
auto opts = invocation.getLangOpts();
auto& opts = invocation.getLangOpts();

std::vector<std::string> includes;
for (const auto& includePath : options.includePaths)
{
includes.push_back(includePath.begin());
}

clang::CompilerInvocation::setLangDefaults(
*opts,
inputKind,
targetTriple,
includes,
langStd);
clang::LangOptions::setLangDefaults(opts, language, targetTriple, includes, langStd);

if (options.floatingPointMode == DownstreamCompileOptions::FloatingPointMode::Fast)
{
opts->FastMath = true;
opts.FastMath = true;
}
}

Expand Down Expand Up @@ -853,7 +842,7 @@ SlangResult LLVMDownstreamCompiler::compile(
#endif

// Create the actual diagnostics engine.
clang->createDiagnostics();
clang->createDiagnostics(*llvm::vfs::getRealFileSystem());
clang->setDiagnostics(diags.get());

if (!clang->hasDiagnostics())
Expand Down Expand Up @@ -1037,36 +1026,33 @@ SlangResult LLVMDownstreamCompiler::compile(
// Add all the symbolmap
SymbolMap symbolMap;

// symbolMap.insert(std::make_pair(mangler("sin"),
// JITEvaluatedSymbol::fromPointer(static_cast<double (*)(double)>(&sin))));

{
static const NameAndFunc funcs[] = {SLANG_LLVM_FUNCS(
SLANG_LLVM_FUNC) SLANG_PLATFORM_FUNCS(SLANG_LLVM_FUNC)};

for (auto& func : funcs)
{
symbolMap.insert(std::make_pair(
mangler(func.name),
JITEvaluatedSymbol::fromPointer(func.func)));
symbolMap[mangler(func.name)] = {
ExecutorAddr::fromPtr(func.func),
JITSymbolFlags::Callable};
}
}

#if SLANG_PTR_IS_32 && SLANG_VC
{
// https://docs.microsoft.com/en-us/windows/win32/devnotes/-win32-alldiv
symbolMap.insert(std::make_pair(
mangler("_alldiv"),
JITEvaluatedSymbol::fromPointer(WinSpecific::_alldiv)));
symbolMap.insert(std::make_pair(
mangler("_allrem"),
JITEvaluatedSymbol::fromPointer(WinSpecific::_allrem)));
symbolMap.insert(std::make_pair(
mangler("_aullrem"),
JITEvaluatedSymbol::fromPointer(WinSpecific::_aullrem)));
symbolMap.insert(std::make_pair(
mangler("_aulldiv"),
JITEvaluatedSymbol::fromPointer(WinSpecific::_aulldiv)));
symbolMap[mangler("_alldiv")] = {
ExecutorAddr::fromPtr(WinSpecific::_alldiv),
JITSymbolFlags::Callable};
symbolMap[mangler("_allrem")] = {
ExecutorAddr::fromPtr(WinSpecific::_allrem),
JITSymbolFlags::Callable};
symbolMap[mangler("_aulldiv")] = {
ExecutorAddr::fromPtr(WinSpecific::_aulldiv),
JITSymbolFlags::Callable};
symbolMap[mangler("_aullrem")] = {
ExecutorAddr::fromPtr(WinSpecific::_aullrem),
JITSymbolFlags::Callable};
}
#endif

Expand All @@ -1076,7 +1062,9 @@ SlangResult LLVMDownstreamCompiler::compile(
}

// Required or the symbols won't be found
jit->getMainJITDylib().addToLinkOrder(stdcLib);
jit->getMainJITDylib().addToLinkOrder(
stdcLib,
JITDylibLookupFlags::MatchAllSymbols);
}
}

Expand Down
Loading