Skip to content

Commit a968d66

Browse files
committed
[CHERIoT] Wire up enough driver support to be able to successfully infer -mabi=cheriot from the cheriotrtos OS field in the triple.
1 parent 87d4c4d commit a968d66

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

clang/lib/Driver/ToolChains/Arch/RISCV.cpp

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static bool isCheriPurecapABIName(StringRef ABI) {
6363
.Case("l64pc128", true)
6464
.Case("l64pc128f", true)
6565
.Case("l64pc128d", true)
66+
.Case("cheriot", true)
67+
.Case("cheriot-baremetal", true)
6668
.Default(false);
6769
}
6870

@@ -205,8 +207,12 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
205207
options::OPT_m_riscv_Features_Group);
206208

207209
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
208-
bool IsPureCapability = isCheriPurecapABIName(A->getValue());
209-
if (IsPureCapability) {
210+
StringRef ABI = A->getValue();
211+
bool IsPureCapability = isCheriPurecapABIName(ABI);
212+
if (ABI == "cheriot" || ABI == "cheriot-baremetal") {
213+
// +xcheriot implies both +xcheri and +xcheripurecap
214+
Features.push_back("+xcheriot");
215+
} else if (IsPureCapability) {
210216
auto ISAInfo = llvm::RISCVISAInfo::parseFeatures(
211217
Triple.isArch32Bit() ? 32 : 64,
212218
std::vector<std::string>(Features.begin(), Features.end()));
@@ -224,42 +230,6 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
224230
}
225231
}
226232

227-
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
228-
bool IsPureCapability = isCheriPurecapABIName(A->getValue());
229-
if (IsPureCapability) {
230-
if (llvm::find(Features, "+xcheri") == Features.end()) {
231-
D.Diag(diag::err_riscv_invalid_abi) << A->getValue()
232-
<< "pure capability ABI requires xcheri extension to be specified";
233-
return;
234-
}
235-
Features.push_back("+xcheripurecap");
236-
}
237-
}
238-
239-
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
240-
bool IsPureCapability = isCheriPurecapABIName(A->getValue());
241-
if (IsPureCapability) {
242-
if (llvm::find(Features, "+xcheri") == Features.end()) {
243-
D.Diag(diag::err_riscv_invalid_abi) << A->getValue()
244-
<< "pure capability ABI requires xcheri extension to be specified";
245-
return;
246-
}
247-
Features.push_back("+xcheripurecap");
248-
}
249-
}
250-
251-
if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
252-
bool IsPureCapability = isCheriPurecapABIName(A->getValue());
253-
if (IsPureCapability) {
254-
if (llvm::find(Features, "+xcheri") == Features.end()) {
255-
D.Diag(diag::err_riscv_invalid_abi) << A->getValue()
256-
<< "pure capability ABI requires xcheri extension to be specified";
257-
return;
258-
}
259-
Features.push_back("+xcheripurecap");
260-
}
261-
}
262-
263233
// If -mstrict-align, -mno-strict-align, -mscalar-strict-align, or
264234
// -mno-scalar-strict-align is passed, use it. Otherwise, the
265235
// unaligned-scalar-mem is enabled if the CPU supports it or the target is
@@ -356,6 +326,8 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
356326
// - On `riscv{XLEN}-unknown-elf` we use the integer calling convention only.
357327
// - On all other OSs we use the double floating point calling convention.
358328
if (Triple.isRISCV32()) {
329+
if (Triple.getOS() == llvm::Triple::CheriotRTOS)
330+
return "cheriot";
359331
if (Triple.getOS() == llvm::Triple::UnknownOS)
360332
return "ilp32";
361333
else
@@ -457,8 +429,9 @@ std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,
457429
// We deviate from GCC's defaults here:
458430
// - On `riscv{XLEN}-unknown-elf` we default to `rv{XLEN}imac`
459431
// - On all other OSs we use `rv{XLEN}imafdc` (equivalent to `rv{XLEN}gc`)
460-
if (Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1)
461-
return "rv32emc_xcheri";
432+
if (Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1 ||
433+
Triple.getOS() == llvm::Triple::CheriotRTOS)
434+
return "rv32emc_xcheriot";
462435
if (Triple.isRISCV32()) {
463436
if (Triple.getOS() == llvm::Triple::UnknownOS)
464437
return "rv32imac";
@@ -488,7 +461,8 @@ std::string riscv::getRISCVTargetCPU(const llvm::opt::ArgList &Args,
488461
if (!CPU.empty())
489462
return CPU;
490463

491-
if (Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1)
464+
if (Triple.getOS() == llvm::Triple::CheriotRTOS ||
465+
Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1)
492466
return "cheriot";
493467

494468
return Triple.isRISCV64() ? "generic-rv64" : "generic-rv32";

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,8 @@ RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
957957

958958
StringRef RISCVISAInfo::computeDefaultABI() const {
959959
if (XLen == 32) {
960+
if (Exts.count("xcheriot"))
961+
return "cheriot";
960962
if (Exts.count("e"))
961963
return "ilp32e";
962964
if (Exts.count("d"))

0 commit comments

Comments
 (0)