Skip to content
Open
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 clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def TargetMips32 : TargetArch<["mips", "mipsel"]>;
def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
def TargetMSP430 : TargetArch<["msp430"]>;
def TargetM68k : TargetArch<["m68k"]>;
def TargetRISCV : TargetArch<["riscv32", "riscv64"]>;
def TargetRISCV : TargetArch<["riscv32", "riscv64", "riscv32be", "riscv64be"]>;
def TargetX86 : TargetArch<["x86"]>;
def TargetX86_64 : TargetArch<["x86_64"]>;
def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ def warn_ignored_clang_option : Warning<"the flag '%0' has been deprecated and w
def warn_drv_unsupported_opt_for_target : Warning<
"optimization flag '%0' is not supported for target '%1'">,
InGroup<IgnoredOptimizationArgument>;
def warn_drv_riscv_be_experimental : Warning<
"big-endian RISC-V target support is experimental">,
InGroup<RISCVBEExperimental>;
def warn_drv_unsupported_debug_info_opt_for_target : Warning<
"debug information option '%0' is not supported for target '%1'">,
InGroup<UnsupportedTargetOpt>;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def UnsupportedFPOpt : DiagGroup<"unsupported-floating-point-opt">;
def UnsupportedCB : DiagGroup<"unsupported-cb">;
def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
def UnsupportedTargetOpt : DiagGroup<"unsupported-target-opt">;
def RISCVBEExperimental : DiagGroup<"riscv-be-experimental">;
def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">;
def NullConversion : DiagGroup<"null-conversion">;
def ImplicitConversionFloatingPointToBool :
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/ObjCRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class ObjCRuntime {
case llvm::Triple::mips64:
return !(getVersion() >= VersionTuple(1, 9));
case llvm::Triple::riscv64:
case llvm::Triple::riscv64be:
return !(getVersion() >= VersionTuple(2, 2));
default:
return true;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<AMDGPUTargetInfo>(Triple, Opts);

case llvm::Triple::riscv32:
case llvm::Triple::riscv32be:
switch (os) {
case llvm::Triple::NetBSD:
return std::make_unique<NetBSDTargetInfo<RISCV32TargetInfo>>(Triple,
Expand All @@ -439,6 +440,7 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
}

case llvm::Triple::riscv64:
case llvm::Triple::riscv64be:
switch (os) {
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<RISCV64TargetInfo>>(Triple,
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
break;
case llvm::Triple::loongarch64:
case llvm::Triple::riscv64:
case llvm::Triple::riscv64be:
break;
}
}
Expand Down Expand Up @@ -513,6 +514,7 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
break;
case llvm::Triple::loongarch64:
case llvm::Triple::riscv64:
case llvm::Triple::riscv64be:
break;
}
}
Expand Down
16 changes: 12 additions & 4 deletions clang/lib/Basic/Targets/RISCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,17 @@ class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
IntPtrType = SignedInt;
PtrDiffType = SignedInt;
SizeType = UnsignedInt;
resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
resetDataLayout((Twine(Triple.isLittleEndian() ? "e" : "E") +
"-m:e-p:32:32-i64:64-n32-S128")
.str());
}

bool setABI(const std::string &Name) override {
if (Name == "ilp32e") {
ABI = Name;
resetDataLayout("e-m:e-p:32:32-i64:64-n32-S32");
resetDataLayout((Twine(getTriple().isLittleEndian() ? "e" : "E") +
"-m:e-p:32:32-i64:64-n32-S32")
.str());
return true;
}

Expand All @@ -205,13 +209,17 @@ class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
: RISCVTargetInfo(Triple, Opts) {
LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
IntMaxType = Int64Type = SignedLong;
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
resetDataLayout((Twine(Triple.isLittleEndian() ? "e" : "E") +
"-m:e-p:64:64-i64:64-i128:128-n32:64-S128")
.str());
}

bool setABI(const std::string &Name) override {
if (Name == "lp64e") {
ABI = Name;
resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S64");
resetDataLayout((Twine(getTriple().isLittleEndian() ? "e" : "E") +
"-m:e-p:64:64-i64:64-i128:128-n32:64-S64")
.str());
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF,
return CGF->EmitHexagonBuiltinExpr(BuiltinID, E);
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
return CGF->EmitRISCVBuiltinExpr(BuiltinID, E, ReturnValue);
case llvm::Triple::spirv32:
case llvm::Triple::spirv64:
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,8 @@ void CodeGenFunction::EmitMultiVersionResolver(
return;
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
EmitRISCVMultiVersionResolver(Resolver, Options);
return;

Expand Down
4 changes: 3 additions & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
return createMSP430TargetCodeGenInfo(CGM);

case llvm::Triple::riscv32:
case llvm::Triple::riscv64: {
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be: {
StringRef ABIStr = Target.getABI();
unsigned XLen = Target.getPointerWidth(LangAS::Default);
unsigned ABIFLen = 0;
Expand Down
26 changes: 22 additions & 4 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,30 @@ static llvm::Triple computeTargetTriple(const Driver &D,
ArchName, /*EnableExperimentalExtensions=*/true);
if (!llvm::errorToBool(ISAInfo.takeError())) {
unsigned XLen = (*ISAInfo)->getXLen();
if (XLen == 32)
Target.setArch(llvm::Triple::riscv32);
else if (XLen == 64)
Target.setArch(llvm::Triple::riscv64);
if (XLen == 32) {
if (Target.isLittleEndian())
Target.setArch(llvm::Triple::riscv32);
else
Target.setArch(llvm::Triple::riscv32be);
} else if (XLen == 64) {
if (Target.isLittleEndian())
Target.setArch(llvm::Triple::riscv64);
else
Target.setArch(llvm::Triple::riscv64be);
}
}
}
}

if (Target.getArch() == llvm::Triple::riscv32be ||
Target.getArch() == llvm::Triple::riscv64be) {
static bool WarnedRISCVBE = false;
if (!WarnedRISCVBE) {
D.Diag(diag::warn_drv_riscv_be_experimental);
WarnedRISCVBE = true;
}
}

return Target;
}

Expand Down Expand Up @@ -6957,6 +6973,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
break;
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args);
break;
case llvm::Triple::ve:
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
break;
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
getRISCVMultilibFlags(D, Triple, Args, Result);
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Driver/ToolChains/BareMetal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ SanitizerMask BareMetal::getSupportedSanitizers() const {
const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
getTriple().getArch() == llvm::Triple::aarch64_be;
const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64;
const bool IsRISCV64 = getTriple().getArch() == llvm::Triple::riscv64 ||
getTriple().getArch() == llvm::Triple::riscv64be;
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::KernelAddress;
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,8 @@ static bool isSignedCharDefault(const llvm::Triple &Triple) {
case llvm::Triple::ppc64le:
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
case llvm::Triple::systemz:
case llvm::Triple::xcore:
case llvm::Triple::xtensa:
Expand Down Expand Up @@ -1593,6 +1595,8 @@ void Clang::RenderTargetOptions(const llvm::Triple &EffectiveTriple,

case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
AddRISCVTargetArgs(Args, CmdArgs);
break;

Expand Down Expand Up @@ -5644,7 +5648,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
} else if (Name == "SLEEF" || Name == "ArmPL") {
if (Triple.getArch() != llvm::Triple::aarch64 &&
Triple.getArch() != llvm::Triple::aarch64_be &&
Triple.getArch() != llvm::Triple::riscv64)
Triple.getArch() != llvm::Triple::riscv64 &&
Triple.getArch() != llvm::Triple::riscv64be)
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Name << Triple.getArchName();
}
Expand Down Expand Up @@ -8718,6 +8723,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,

case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
AddRISCVTargetArgs(Args, CmdArgs);
break;

Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args,
case llvm::Triple::ppc64le:
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
case llvm::Triple::sparc:
case llvm::Triple::sparcel:
case llvm::Triple::sparcv9:
Expand Down Expand Up @@ -590,6 +592,10 @@ const char *tools::getLDMOption(const llvm::Triple &T, const ArgList &Args) {
return "elf32lriscv";
case llvm::Triple::riscv64:
return "elf64lriscv";
case llvm::Triple::riscv32be:
return "elf32briscv";
case llvm::Triple::riscv64be:
return "elf64briscv";
case llvm::Triple::sparc:
case llvm::Triple::sparcel:
return "elf32_sparc";
Expand Down Expand Up @@ -767,6 +773,8 @@ std::string tools::getCPUName(const Driver &D, const ArgList &Args,
return "ck810";
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
return riscv::getRISCVTargetCPU(Args, T);

case llvm::Triple::bpfel:
Expand Down Expand Up @@ -848,6 +856,8 @@ void tools::getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
break;
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
riscv::getRISCVTargetFeatures(D, Triple, Args, Features);
break;
case llvm::Triple::systemz:
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/FreeBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-m");
CmdArgs.push_back("elf64lriscv");
break;
case llvm::Triple::riscv32be:
CmdArgs.push_back("-m");
CmdArgs.push_back("elf32briscv");
break;
case llvm::Triple::riscv64be:
CmdArgs.push_back("-m");
CmdArgs.push_back("elf64briscv");
break;
case llvm::Triple::loongarch64:
CmdArgs.push_back("-m");
CmdArgs.push_back("elf64loongarch");
Expand Down
39 changes: 34 additions & 5 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,9 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
break;
}
case llvm::Triple::riscv32:
case llvm::Triple::riscv64: {
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be: {
StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
CmdArgs.push_back("-mabi");
CmdArgs.push_back(ABIName.data());
Expand Down Expand Up @@ -1732,16 +1734,20 @@ static void findRISCVBareMetalMultilibs(const Driver &D,
.flag(Twine("-march=", Element.march).str())
.flag(Twine("-mabi=", Element.mabi).str()));
}

StringRef EndiannessSuffix = TargetTriple.isLittleEndian() ? "" : "be";
MultilibSet RISCVMultilibs =
MultilibSetBuilder()
.Either(Ms)
.makeMultilibSet()
.FilterOut(NonExistent)
.setFilePathsCallback([](const Multilib &M) {
.setFilePathsCallback([EndiannessSuffix](const Multilib &M) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.setFilePathsCallback([EndiannessSuffix](const Multilib &M) {
.setFilePathsCallback([&EndiannessSuffix](const Multilib &M) {

return std::vector<std::string>(
{M.gccSuffix(),
"/../../../../riscv64-unknown-elf/lib" + M.gccSuffix(),
"/../../../../riscv32-unknown-elf/lib" + M.gccSuffix()});
"/../../../../riscv64" + EndiannessSuffix.str() +
"-unknown-elf/lib" + M.gccSuffix(),
"/../../../../riscv32" + EndiannessSuffix.str() +
"-unknown-elf/lib" + M.gccSuffix()});
});

Multilib::flags_list Flags;
Expand Down Expand Up @@ -1789,7 +1795,7 @@ static void findRISCVMultilibs(const Driver &D,
.FilterOut(NonExistent);

Multilib::flags_list Flags;
bool IsRV64 = TargetTriple.getArch() == llvm::Triple::riscv64;
bool IsRV64 = TargetTriple.isRISCV64();
StringRef ABIName = tools::riscv::getRISCVABI(Args, TargetTriple);

addMultilibFlag(!IsRV64, "-m32", Flags);
Expand Down Expand Up @@ -2431,6 +2437,15 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
"riscv64-unknown-elf"};

static const char *const RISCV32beLibDirs[] = {"/lib32", "/lib"};
static const char *const RISCV32beTriples[] = {"riscv32be-unknown-linux-gnu",
"riscv32be-linux-gnu",
"riscv32be-unknown-elf"};
static const char *const RISCV64beLibDirs[] = {"/lib64", "/lib"};
static const char *const RISCV64beTriples[] = {"riscv64be-unknown-linux-gnu",
"riscv64be-linux-gnu",
"riscv64be-unknown-elf"};

static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
"sparcv8-linux-gnu"};
Expand Down Expand Up @@ -2723,6 +2738,18 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
BiarchLibDirs.append(begin(RISCV32LibDirs), end(RISCV32LibDirs));
BiarchTripleAliases.append(begin(RISCV32Triples), end(RISCV32Triples));
break;
case llvm::Triple::riscv32be:
LibDirs.append(begin(RISCV32beLibDirs), end(RISCV32beLibDirs));
TripleAliases.append(begin(RISCV32beTriples), end(RISCV32beTriples));
BiarchLibDirs.append(begin(RISCV64beLibDirs), end(RISCV64beLibDirs));
BiarchTripleAliases.append(begin(RISCV64beTriples), end(RISCV64beTriples));
break;
case llvm::Triple::riscv64be:
LibDirs.append(begin(RISCV64beLibDirs), end(RISCV64beLibDirs));
TripleAliases.append(begin(RISCV64beTriples), end(RISCV64beTriples));
BiarchLibDirs.append(begin(RISCV32beLibDirs), end(RISCV32beLibDirs));
BiarchTripleAliases.append(begin(RISCV32beTriples), end(RISCV32beTriples));
break;
case llvm::Triple::sparc:
case llvm::Triple::sparcel:
LibDirs.append(begin(SPARCv8LibDirs), end(SPARCv8LibDirs));
Expand Down Expand Up @@ -3038,6 +3065,8 @@ Generic_GCC::getDefaultUnwindTableLevel(const ArgList &Args) const {
case llvm::Triple::ppc64le:
case llvm::Triple::riscv32:
case llvm::Triple::riscv64:
case llvm::Triple::riscv32be:
case llvm::Triple::riscv64be:
case llvm::Triple::x86:
case llvm::Triple::x86_64:
return UnwindTableLevel::Asynchronous;
Expand Down
Loading