Skip to content

Commit babea01

Browse files
committed
[CHERIoT] Remove all explicit checks for the riscv32cheriot subarchitecture.
It still parses, but we now handle everything related to Cheriot configuration through the clang driver.
1 parent 7bee8e4 commit babea01

File tree

9 files changed

+23
-45
lines changed

9 files changed

+23
-45
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,6 @@ bool RISCVTargetInfo::initFeatureMap(
377377
Features["32bit"] = true;
378378
}
379379

380-
if (getTriple().getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1) {
381-
Features["xcheri"] = true;
382-
Features["xcheriot"] = true;
383-
Features["xcheripurecap"] = true;
384-
Features["c"] = true;
385-
Features["e"] = true;
386-
Features["m"] = true;
387-
}
388-
389380
std::vector<std::string> AllFeatures = FeaturesVec;
390381
auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesVec);
391382
if (!ParseResult) {
@@ -464,7 +455,7 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
464455
CapSize = XLen * 2;
465456
}
466457
if (ABI.empty())
467-
ABI = ISAInfo->computeDefaultABI().str();
458+
ABI = ISAInfo->computeDefaultABI(getTriple()).str();
468459

469460
if (ISAInfo->hasExtension("zfh") || ISAInfo->hasExtension("zhinx"))
470461
HasLegalHalfType = true;

clang/lib/Basic/Targets/RISCV.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class RISCVTargetInfo : public TargetInfo {
8484
bool HasExperimental = false;
8585

8686
public:
87-
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
87+
RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
8888
: TargetInfo(Triple) {
8989
BFloat16Width = 16;
9090
BFloat16Align = 16;
@@ -99,12 +99,6 @@ class RISCVTargetInfo : public TargetInfo {
9999
MCountName = "_mcount";
100100
HasFloat16 = true;
101101
HasStrictFP = true;
102-
103-
if (Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1) {
104-
CPU = "cheriot";
105-
ABI = (Triple.getOS() == llvm::Triple::CheriotRTOS) ? "cheriot"
106-
: "cheriot-baremetal";
107-
}
108102
}
109103

110104
bool setCPU(const std::string &Name) override {

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,11 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
306306
// rv64e -> lp64e
307307
// rv64* -> lp64
308308
std::string Arch = getRISCVArch(Args, Triple);
309-
if (Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1) {
310-
llvm::Triple::OSType OS = Triple.getOS();
311-
if (OS == llvm::Triple::CheriotRTOS)
312-
return "cheriot";
313-
else if (OS == llvm::Triple::UnknownOS)
314-
return "cheriot-baremetal";
315-
}
316-
317309
auto ParseResult = llvm::RISCVISAInfo::parseArchString(
318310
Arch, /* EnableExperimentalExtension */ true);
319311
// Ignore parsing error, just go 3rd step.
320312
if (!llvm::errorToBool(ParseResult.takeError()))
321-
return (*ParseResult)->computeDefaultABI();
313+
return (*ParseResult)->computeDefaultABI(Triple);
322314

323315
// 3. Choose a default based on the triple
324316
//
@@ -429,8 +421,7 @@ std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,
429421
// We deviate from GCC's defaults here:
430422
// - On `riscv{XLEN}-unknown-elf` we default to `rv{XLEN}imac`
431423
// - On all other OSs we use `rv{XLEN}imafdc` (equivalent to `rv{XLEN}gc`)
432-
if (Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1 ||
433-
Triple.getOS() == llvm::Triple::CheriotRTOS)
424+
if (Triple.getOS() == llvm::Triple::CheriotRTOS)
434425
return "rv32emc_xcheriot";
435426
if (Triple.isRISCV32()) {
436427
if (Triple.getOS() == llvm::Triple::UnknownOS)
@@ -461,9 +452,13 @@ std::string riscv::getRISCVTargetCPU(const llvm::opt::ArgList &Args,
461452
if (!CPU.empty())
462453
return CPU;
463454

464-
if (Triple.getOS() == llvm::Triple::CheriotRTOS ||
465-
Triple.getSubArch() == llvm::Triple::RISCV32SubArch_cheriot_v1)
455+
if (Triple.getOS() == llvm::Triple::CheriotRTOS)
466456
return "cheriot";
457+
if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
458+
StringRef ABI = A->getValue();
459+
if (ABI == "cheriot" || ABI == "cheriot-baremetal")
460+
return "cheriot";
461+
}
467462

468463
return Triple.isRISCV64() ? "generic-rv64" : "generic-rv32";
469464
}

clang/test/Driver/cheri/cheriot.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
// RUN: %clang -target riscv32cheriot -### -c %s 2>&1 | FileCheck %s -check-prefixes BAREMETAL,ALL
2-
// RUN: %clang -target riscv32cheriot-unknown-unknown -### -c %s 2>&1 | FileCheck %s -check-prefixes BAREMETAL,ALL
1+
// RUN: %clang -target riscv32cheriot-unknown-unknown -mcpu=cheriot -### -c %s 2>&1 | FileCheck %s -check-prefixes BAREMETAL,ALL
2+
// RUN: %clang -target riscv32cheriot-unknown-unknown -mabi=cheriot-baremetal -### -c %s 2>&1 | FileCheck %s -check-prefixes BAREMETAL,ALL
33
// RUN: %clang -target riscv32cheriot-unknown-cheriotrtos -### -c %s 2>&1 | FileCheck %s -check-prefixes RTOS,ALL
44

55

66
// ALL: "-target-cpu" "cheriot"
7-
// ALL: "-target-feature" "+e"
8-
// ALL: "-target-feature" "+m"
9-
// ALL: "-target-feature" "+c"
10-
// ALL: "-target-feature" "+xcheri"
7+
// ALL: "-target-feature" "+xcheriot"
118

129
// BAREMETAL: "-target-abi" "cheriot-baremetal"
1310
// RTOS: "-target-abi" "cheriot"

clang/test/SemaCXX/cheri/attr-cheriot-sealed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -std=c++11 -triple riscv32cheriot -verify %s
1+
// RUN: %clang_cc1 -std=c++11 -triple riscv32cheriot-unknown-cheriotrtos -verify %s
22

33
struct test_struct {
44
int b;

lld/test/ELF/cheri/riscv/cheriot_compartment_lo_i.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# RUN: llvm-objdump -d %t.exe | FileCheck %s
55

66
.attribute 4, 16
7-
.attribute 5, "rv32e2p0_m2p0_c2p0_zmmul1p0_xcheri0p0_xcheriot1p0_xcheripurecap1p0"
7+
.attribute 5, "rv32e2p0_m2p0_c2p0_zmmul1p0_xcheri0p0_xcheriot1p0_xcheripurecap0p0"
88
.section .text,"ax",@progbits
99
.globl _start
1010
.p2align 1

llvm/include/llvm/TargetParser/RISCVISAInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
namespace llvm {
2323

24+
class Triple;
25+
2426
class RISCVISAInfo {
2527
public:
2628
RISCVISAInfo(const RISCVISAInfo &) = delete;
@@ -66,7 +68,7 @@ class RISCVISAInfo {
6668

6769
bool hasExtension(StringRef Ext) const;
6870
std::string toString() const;
69-
StringRef computeDefaultABI() const;
71+
StringRef computeDefaultABI(const llvm::Triple &Triple) const;
7072

7173
static bool isSupportedExtensionFeature(StringRef Ext);
7274
static bool isSupportedExtension(StringRef Ext);

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,11 @@ ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits,
9292
auto ISAInfo = RISCVFeatures::parseFeatureBits(IsRV64, FeatureBits);
9393
if (!ISAInfo)
9494
report_fatal_error(ISAInfo.takeError());
95-
return getTargetABI((*ISAInfo)->computeDefaultABI(), TT);
95+
return getTargetABI((*ISAInfo)->computeDefaultABI(TT), TT);
9696
}
9797

9898
ABI getTargetABI(StringRef ABIName, const Triple &TT) {
9999
ABI Default = ABI_Unknown;
100-
if (TT.getSubArch() == Triple::RISCV32SubArch_cheriot_v1) {
101-
Default = (TT.getOS() == Triple::CheriotRTOS) ? ABI_CHERIOT : ABI_CHERIOT_BAREMETAL;
102-
}
103100

104101
auto TargetABI = StringSwitch<ABI>(ABIName)
105102
.Case("ilp32", ABI_ILP32)

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/Support/Errc.h"
1414
#include "llvm/Support/Error.h"
1515
#include "llvm/Support/raw_ostream.h"
16+
#include "llvm/TargetParser/Triple.h"
1617

1718
#include <array>
1819
#include <atomic>
@@ -955,10 +956,11 @@ RISCVISAInfo::postProcessAndChecking(std::unique_ptr<RISCVISAInfo> &&ISAInfo) {
955956
return std::move(ISAInfo);
956957
}
957958

958-
StringRef RISCVISAInfo::computeDefaultABI() const {
959+
StringRef RISCVISAInfo::computeDefaultABI(const llvm::Triple &Triple) const {
959960
if (XLen == 32) {
960961
if (Exts.count("xcheriot"))
961-
return "cheriot";
962+
return Triple.getOS() == llvm::Triple::CheriotRTOS ? "cheriot"
963+
: "cheriot-baremetal";
962964
if (Exts.count("e"))
963965
return "ilp32e";
964966
if (Exts.count("d"))

0 commit comments

Comments
 (0)