@@ -94,6 +94,11 @@ static cl::opt<bool>
9494 "be combined with a shift"),
9595 cl::init(true));
9696
97+ static cl::opt<bool> CheriotDisableCapTable(
98+ "cheriot-disable-cap-table", cl::Hidden,
99+ cl::desc("Disable cap tables for references to globals on CHERIoT"),
100+ cl::init(false));
101+
97102RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
98103 const RISCVSubtarget &STI)
99104 : TargetLowering(TM), Subtarget(STI) {
@@ -8977,14 +8982,17 @@ static SDValue getLargeExternalSymbol(ExternalSymbolSDNode *N, const SDLoc &DL,
89778982template <class NodeTy>
89788983SDValue RISCVTargetLowering::getAddr(NodeTy *N, EVT Ty, SelectionDAG &DAG,
89798984 bool IsLocal, bool CanDeriveFromPcc,
8980- bool IsExternWeak) const {
8985+ bool IsExternWeak,
8986+ const GlobalValue *GV) const {
89818987 SDLoc DL(N);
89828988
89838989 if (RISCVABI::isCheriPureCapABI(Subtarget.getTargetABI())) {
89848990 bool IsCheriot = Subtarget.getTargetABI() == RISCVABI::ABI_CHERIOT ||
89858991 Subtarget.getTargetABI() == RISCVABI::ABI_CHERIOT_BAREMETAL;
89868992 SDValue Addr = getTargetNode(N, DL, Ty, DAG, 0);
8987- if ((IsLocal && CanDeriveFromPcc) || IsCheriot) {
8993+ bool NotHighUseGV = !GV || GV->getNumUses() < 4;
8994+ if ((IsLocal && CanDeriveFromPcc) ||
8995+ (IsCheriot && (CheriotDisableCapTable || NotHighUseGV))) {
89888996 // Use PC-relative addressing to access the symbol. This generates the
89898997 // pattern (PseudoCLLC sym), which expands to
89908998 // (cincoffsetimm (auipcc %pcrel_hi(sym)) %pcrel_lo(auipc)).
@@ -9121,7 +9129,7 @@ SDValue RISCVTargetLowering::lowerGlobalAddress(SDValue Op,
91219129 }
91229130
91239131 return getAddr(N, Ty, DAG, GV->isDSOLocal(), /*CanDeriveFromPcc=*/false,
9124- GV->hasExternalWeakLinkage());
9132+ GV->hasExternalWeakLinkage(), GV );
91259133}
91269134
91279135SDValue RISCVTargetLowering::lowerBlockAddress(SDValue Op,
0 commit comments