Skip to content

Commit 707cc92

Browse files
veselypetaresistor
authored andcommitted
[CHERI] Use ABI to deduce purecap instead of default addrspace
1 parent 600e33e commit 707cc92

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,7 @@ void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
851851
bool BadDebugInfo = false;
852852
FullSourceLoc Loc =
853853
getBestLocationFromDebugLoc(DICI, BadDebugInfo, Filename, Line, Column);
854-
const auto &DL = DICI.getFunction().getParent()->getDataLayout();
855-
bool IsPurecap = DL.isFatPointer(DL.getDefaultGlobalsAddressSpace());
854+
bool IsPurecap = Context->getTargetInfo().areAllPointersCapabilities();
856855

857856
Diags.Report(Loc, diag::warn_fe_backend_cheri_inefficient)
858857
<< DICI.getMessage();

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,7 @@ class LLVM_ABI TargetLoweringBase {
35623562
Register getNullCapabilityRegister() const {
35633563
return NullCapabilityRegister;
35643564
}
3565+
bool isCheriPureCap() const { return IsCheriPureCap; }
35653566

35663567
/// Does this target require the clearing of high-order bits in a register
35673568
/// passed to the fp16 to fp conversion library function.
@@ -3982,6 +3983,9 @@ class LLVM_ABI TargetLoweringBase {
39823983
/// Should be one of c64/c128/c256
39833984
MVT CapType = MVT();
39843985

3986+
/// All pointers are capabilities.
3987+
bool IsCheriPureCap = false;
3988+
39853989
/// Whether CHERI Capability loads/stores can be used with unaligned addresses
39863990
/// This makes it possible to do a tag-preserving copy even if the alignment
39873991
/// is not statically known to be at least capability aligned.

llvm/lib/CodeGen/AtomicExpandPass.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,13 +2117,10 @@ bool AtomicExpandImpl::expandAtomicOpToLibcall(
21172117
// adding the 20+ new entries to RuntimeLibcalls.def. We also suffix with
21182118
// _c for capability pointer arguments in hybrid mode.
21192119
std::string LibcallName = TLI->getLibcallName(RTLibType);
2120-
// We are compiling for CHERI purecap mode if the default globals address
2121-
// space is a capability type.
2122-
bool IsCheriPurecap = DL.isFatPointer(DL.getDefaultGlobalsAddressSpace());
21232120
if (ValueOperandIsCap) {
21242121
LibcallName += "_cap";
21252122
}
2126-
if (PointerOperandIsCap && !IsCheriPurecap) {
2123+
if (PointerOperandIsCap && !TLI->isCheriPureCap()) {
21272124
// Add a _c suffix if the function uses capability pointer operands in
21282125
// hybrid mode.
21292126
assert(StringRef(LibcallName).starts_with("__atomic"));

llvm/lib/Target/Mips/MipsISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ MipsTargetLowering::MipsTargetLowering(const MipsTargetMachine &TM,
344344
: TargetLowering(TM), Subtarget(STI), ABI(TM.getABI()) {
345345
CapType = STI.typeForCapabilities();
346346
assert(cheriCapabilityType().isFatPointer());
347+
IsCheriPureCap = ABI.IsCheriPureCap();
347348

348349
// Mips does not have i1 type, so use i32 for
349350
// setcc operations results (slt, sgt, ...).

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
170170
CapType = Subtarget.typeForCapabilities();
171171
NullCapabilityRegister = RISCV::X0_Y;
172172
addRegisterClass(CapType, &RISCV::YGPRRegClass);
173-
}
174-
175-
if (Subtarget.hasVendorXCheri()) {
176-
CapType = Subtarget.typeForCapabilities();
177-
NullCapabilityRegister = RISCV::X0_Y;
178-
addRegisterClass(CapType, &RISCV::YGPRRegClass);
173+
IsCheriPureCap = RISCVABI::isCheriPureCapABI(ABI);
179174
}
180175

181176
if (Subtarget.hasVendorXCheriot()) {

0 commit comments

Comments
 (0)