Skip to content

[RISCV] Integrate RISCV target in baremetal toolchain object and deprecate RISCVToolchain object #121831

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

Merged
merged 1 commit into from
Jun 30, 2025
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
1 change: 0 additions & 1 deletion clang/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ add_clang_library(clangDriver
ToolChains/OHOS.cpp
ToolChains/OpenBSD.cpp
ToolChains/PS4CPU.cpp
ToolChains/RISCVToolchain.cpp
ToolChains/Solaris.cpp
ToolChains/SPIRV.cpp
ToolChains/SPIRVOpenMP.cpp
Expand Down
10 changes: 2 additions & 8 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include "ToolChains/PPCFreeBSD.h"
#include "ToolChains/PPCLinux.h"
#include "ToolChains/PS4CPU.h"
#include "ToolChains/RISCVToolchain.h"
#include "ToolChains/SPIRV.h"
#include "ToolChains/SPIRVOpenMP.h"
#include "ToolChains/SYCL.h"
Expand Down Expand Up @@ -6955,16 +6954,11 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
TC = std::make_unique<toolchains::AVRToolChain>(*this, Target, Args);
break;
case llvm::Triple::msp430:
TC =
std::make_unique<toolchains::MSP430ToolChain>(*this, Target, Args);
TC = std::make_unique<toolchains::MSP430ToolChain>(*this, Target, Args);
break;
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
if (toolchains::RISCVToolChain::hasGCCToolchain(*this, Args))
TC =
std::make_unique<toolchains::RISCVToolChain>(*this, Target, Args);
else
TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args);
TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args);
break;
case llvm::Triple::ve:
TC = std::make_unique<toolchains::VEToolChain>(*this, Target, Args);
Expand Down
22 changes: 22 additions & 0 deletions clang/lib/Driver/ToolChains/BareMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,28 @@ BareMetal::OrderedMultilibs BareMetal::getOrderedMultilibs() const {
return llvm::reverse(Default);
}

ToolChain::CXXStdlibType BareMetal::GetDefaultCXXStdlibType() const {
if (getTriple().isRISCV() && IsGCCInstallationValid)
return ToolChain::CST_Libstdcxx;
return ToolChain::CST_Libcxx;
}

ToolChain::RuntimeLibType BareMetal::GetDefaultRuntimeLibType() const {
if (getTriple().isRISCV() && IsGCCInstallationValid)
return ToolChain::RLT_Libgcc;
return ToolChain::RLT_CompilerRT;
}

// TODO: Add a validity check for GCCInstallation.
// If valid, use `UNW_Libgcc`; otherwise, use `UNW_None`.
ToolChain::UnwindLibType
BareMetal::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
if (getTriple().isRISCV())
Copy link
Member

Choose a reason for hiding this comment

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

Could we make it conditional only on valid GCC installation?

Suggested change
if (getTriple().isRISCV())
if (GCCInstallation.isValid())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done because in RISCVToolchain, it was UNW_NONE. It seems counter-intuitive however this is done to perserve the behavior of both RISCVToolchain and BareMetal toolchain

Copy link
Member

Choose a reason for hiding this comment

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

In that case would it be possible to leave TODO comment here to make sure we address this in a follow up change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return ToolChain::UNW_None;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this return UNW_Libgcc?

Suggested change
return ToolChain::UNW_None;
return ToolChain::UNW_Libgcc;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done because in RISCVToolchain, it was UNW_NONE. It seems counter-intuitive however this is done to perserve the behavior of both RISCVToolchain and BareMetal toolchain

Copy link
Member

Choose a reason for hiding this comment

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

In that case would it be possible to leave TODO comment here to make sure we address this in a follow up change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


return ToolChain::GetUnwindLibType(Args);
}

void BareMetal::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
ArgStringList &CC1Args) const {
if (DriverArgs.hasArg(options::OPT_nostdinc))
Expand Down
10 changes: 4 additions & 6 deletions clang/lib/Driver/ToolChains/BareMetal.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public Generic_ELF {
return UnwindTableLevel::None;
}

RuntimeLibType GetDefaultRuntimeLibType() const override {
return ToolChain::RLT_CompilerRT;
}
CXXStdlibType GetDefaultCXXStdlibType() const override;

CXXStdlibType GetDefaultCXXStdlibType() const override {
return ToolChain::CST_Libcxx;
}
RuntimeLibType GetDefaultRuntimeLibType() const override;

UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override;

void
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
Expand Down
231 changes: 0 additions & 231 deletions clang/lib/Driver/ToolChains/RISCVToolchain.cpp

This file was deleted.

67 changes: 0 additions & 67 deletions clang/lib/Driver/ToolChains/RISCVToolchain.h

This file was deleted.

Loading
Loading