@@ -94,6 +94,12 @@ static cl::opt<bool>
9494 "be combined with a shift"),
9595 cl::init(true));
9696
97+ static cl::opt<bool>
98+ CheriotUseCapTable("cheriot-use-cap-table", cl::Hidden,
99+ cl::desc("Use cap tables to access globals with many "
100+ "static references (CHERIoT)"),
101+ cl::init(false));
102+
97103RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
98104 const RISCVSubtarget &STI)
99105 : TargetLowering(TM), Subtarget(STI) {
@@ -8977,14 +8983,17 @@ static SDValue getLargeExternalSymbol(ExternalSymbolSDNode *N, const SDLoc &DL,
89778983template <class NodeTy>
89788984SDValue RISCVTargetLowering::getAddr(NodeTy *N, EVT Ty, SelectionDAG &DAG,
89798985 bool IsLocal, bool CanDeriveFromPcc,
8980- bool IsExternWeak) const {
8986+ bool IsExternWeak,
8987+ const GlobalValue *GV) const {
89818988 SDLoc DL(N);
89828989
89838990 if (RISCVABI::isCheriPureCapABI(Subtarget.getTargetABI())) {
89848991 bool IsCheriot = Subtarget.getTargetABI() == RISCVABI::ABI_CHERIOT ||
89858992 Subtarget.getTargetABI() == RISCVABI::ABI_CHERIOT_BAREMETAL;
89868993 SDValue Addr = getTargetNode(N, DL, Ty, DAG, 0);
8987- if ((IsLocal && CanDeriveFromPcc) || IsCheriot) {
8994+ bool NotHighUseGV = !GV || GV->getNumUses() < 4;
8995+ if ((IsLocal && CanDeriveFromPcc) ||
8996+ (IsCheriot && CheriotUseCapTable && NotHighUseGV)) {
89888997 // Use PC-relative addressing to access the symbol. This generates the
89898998 // pattern (PseudoCLLC sym), which expands to
89908999 // (cincoffsetimm (auipcc %pcrel_hi(sym)) %pcrel_lo(auipc)).
@@ -9121,7 +9130,7 @@ SDValue RISCVTargetLowering::lowerGlobalAddress(SDValue Op,
91219130 }
91229131
91239132 return getAddr(N, Ty, DAG, GV->isDSOLocal(), /*CanDeriveFromPcc=*/false,
9124- GV->hasExternalWeakLinkage());
9133+ GV->hasExternalWeakLinkage(), GV );
91259134}
91269135
91279136SDValue RISCVTargetLowering::lowerBlockAddress(SDValue Op,
0 commit comments