Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIE2] Enable libc++ support #142

Merged
merged 4 commits into from
Aug 29, 2024
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
46 changes: 36 additions & 10 deletions clang/cmake/caches/Peano-AIE-runtime-libraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
set(LLVM_ENABLE_RUNTIMES
compiler-rt
libc
libcxx
libcxxabi
CACHE STRING "")
set(LLVM_LIBC_FULL_BUILD ON CACHE BOOL "")
set(LLVM_FORCE_BUILD_RUNTIME "libc" CACHE STRING "")
Expand All @@ -25,6 +27,7 @@ foreach(target ${LLVM_BUILTIN_TARGETS})
set(BUILTINS_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE Release CACHE STRING "")
set(BUILTINS_${target}_LLVM_USE_LINKER lld CACHE STRING "")
set(RUNTIMES_${target}_LLVM_INCLUDE_TESTS OFF CACHE STRING "")
set(BUILTINS_${target}_CMAKE_C_FLAGS "--target=${target}" CACHE STRING "")
set(BUILTINS_${target}_CMAKE_CXX_FLAGS "--target=${target}" CACHE STRING "")
set(BUILTINS_${target}_CMAKE_ASM_FLAGS "--target=${target}" CACHE STRING "")
Expand All @@ -35,14 +38,37 @@ foreach(target ${LLVM_BUILTIN_TARGETS})
# shouldn't expect the stdlibs to be available anyway
set(BUILTINS_${target}_CMAKE_EXE_LINKER_FLAGS "-nostdlib" CACHE STRING "")
set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "-nostdlib" CACHE STRING "")
endforeach()

set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXX_ENABLE_THREADS OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
set(LIBCXXABI_ENABLE_THREADS OFF CACHE BOOL "")
set(LIBCXX_ENABLE_ABI_LINKER_SCRIPT OFF CACHE BOOL "")
set(LIBCXX_LINK_TESTS_WITH_SHARED_LIBCXX OFF CACHE BOOL "")
set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX OFF CACHE BOOL "")
set(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI OFF CACHE BOOL "")
set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_UNICODE OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_WIDE_CHARACTERS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_TIME_ZONE_DATABASE OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_USE_COMPILER_RT ON CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_EXCEPTIONS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_RTTI OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_THREADS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_ENABLE_MONOTONIC_CLOCK OFF CACHE STRING "")
# disable new/delete in both libcxx and libcxxabi to work around missing alloc/free in libc
set(RUNTIMES_${target}_LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_HEADER_ONLY ON CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_INCLUDE_BENCHMARKS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_INCLUDE_TESTS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXX_EXTRA_SITE_DEFINES "_LIBCPP_REMOVE_TRANSITIVE_INCLUDES" CACHE STRING "")

set(RUNTIMES_${target}_LIBC_ENABLE_USE_BY_CLANG ON CACHE STRING "")
# configure libcxxabi build
set(RUNTIMES_${target}_LIBCXXABI_ENABLE_SHARED OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_ENABLE_EXCEPTIONS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_USE_COMPILER_RT OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_ENABLE_THREADS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_BAREMETAL ON CACHE STRING "")
# disable new/delete in both libcxx and libcxxabi to work around missing alloc/free in libc
set(RUNTIMES_${target}_LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_USE_LLVM_UNWINDER OFF CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_HEADER_ONLY ON CACHE STRING "")
set(RUNTIMES_${target}_LIBCXXABI_INCLUDE_TESTS OFF CACHE STRING "")
endforeach()
44 changes: 44 additions & 0 deletions clang/lib/Driver/ToolChains/AIE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,50 @@ void AIEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
// Don't pull in system headers from /usr/include or /usr/local/include.
// All of the basic headers that we need come from the compiler.
CC1Args.push_back("-nostdsysteminc");

if (DriverArgs.hasArg(options::OPT_nostdlibinc))
return;

const Driver &D = getDriver();
std::string Target = getTripleString();
konstantinschwarz marked this conversation as resolved.
Show resolved Hide resolved
SmallString<128> Path(D.Dir);
llvm::sys::path::append(Path, "..", "include", Target);
if (getVFS().exists(Path))
addExternCSystemInclude(DriverArgs, CC1Args, Path.str());
}

void AIEToolChain::addLibCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {

if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
options::OPT_nostdincxx))
return;

// We don't ship libc/libcxx for AIE1
if (getTriple().isAIE1())
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually fail, or have you just not tried it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried it


const Driver &D = getDriver();
const std::string Target = getTripleString();

SmallString<128> Path(D.Dir);
llvm::sys::path::append(Path, "..", "include");

const std::string Version = detectLibcxxVersion(Path);
if (Version.empty())
return;

// First add the per-target include path.
SmallString<128> TargetDir(Path);
llvm::sys::path::append(TargetDir, Target, "c++", Version);
if (getVFS().exists(TargetDir))
addSystemInclude(DriverArgs, CC1Args, TargetDir);

// Second add the generic one.
SmallString<128> Dir(Path);
llvm::sys::path::append(Dir, "c++", Version);
addSystemInclude(DriverArgs, CC1Args, Dir);
}

void AIEToolChain::addClangTargetOptions(
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/Driver/ToolChains/AIE.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class LLVM_LIBRARY_VISIBILITY AIEToolChain : public Generic_ELF {
AIEToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);

// No support for finding a C++ standard library yet.
void addLibCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override {}
CXXStdlibType GetDefaultCXXStdlibType() const override {
return ToolChain::CST_Libcxx;
}

void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void addLibStdCxxIncludePaths(
const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override {}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set(aie_files
aiev2_addlog.h
aiev2_ldst.h
aiev2intrin.h
aiev2_aie_api_compat.h
)

set(arm_common_files
Expand Down
Loading
Loading