@@ -6432,37 +6432,45 @@ static SDValue getTargetNode(JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
6432
6432
return DAG.getTargetJumpTable(N->getIndex(), Ty, Flags);
6433
6433
}
6434
6434
6435
- static SDValue getTargetNode(ExternalSymbolSDNode *N, SDLoc DL, EVT Ty,
6436
- SelectionDAG &DAG, unsigned Flags) {
6437
- llvm_unreachable("Unexpected node type.");
6435
+ static SDValue getLargeGlobalAddress(GlobalAddressSDNode *N, SDLoc DL, EVT Ty,
6436
+ SelectionDAG &DAG) {
6437
+ RISCVConstantPoolConstant *CPV =
6438
+ RISCVConstantPoolConstant::Create(N->getGlobal(), RISCVCP::GlobalValue);
6439
+ SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
6440
+ SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
6441
+ return DAG.getLoad(
6442
+ Ty, DL, DAG.getEntryNode(), LC,
6443
+ MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
6444
+ }
6445
+
6446
+ static SDValue getLargeBlockAddress(BlockAddressSDNode *N, SDLoc DL, EVT Ty,
6447
+ SelectionDAG &DAG) {
6448
+ RISCVConstantPoolConstant *CPV = RISCVConstantPoolConstant::Create(
6449
+ N->getBlockAddress(), RISCVCP::BlockAddress);
6450
+ SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
6451
+ SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
6452
+ return DAG.getLoad(
6453
+ Ty, DL, DAG.getEntryNode(), LC,
6454
+ MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
6455
+ }
6456
+
6457
+ static SDValue getLargeExternalSymbol(ExternalSymbolSDNode *N, SDLoc DL, EVT Ty,
6458
+ SelectionDAG &DAG) {
6459
+ RISCVConstantPoolSymbol *CPV =
6460
+ RISCVConstantPoolSymbol::Create(*DAG.getContext(), N->getSymbol());
6461
+ SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
6462
+ SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
6463
+ return DAG.getLoad(
6464
+ Ty, DL, DAG.getEntryNode(), LC,
6465
+ MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
6438
6466
}
6439
6467
6440
6468
template <class NodeTy>
6441
6469
static SDValue getLargeAddr(NodeTy *N, SDLoc DL, EVT Ty, SelectionDAG &DAG) {
6442
6470
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N)) {
6443
- RISCVConstantPoolConstant *CPV =
6444
- RISCVConstantPoolConstant::Create(G->getGlobal(), RISCVCP::GlobalValue);
6445
- SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
6446
- SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
6447
- return DAG.getLoad(
6448
- Ty, DL, DAG.getEntryNode(), LC,
6449
- MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
6471
+ return getLargeGlobalAddress(G, DL, Ty, DAG);
6450
6472
} else if (BlockAddressSDNode *B = dyn_cast<BlockAddressSDNode>(N)) {
6451
- RISCVConstantPoolConstant *CPV = RISCVConstantPoolConstant::Create(
6452
- B->getBlockAddress(), RISCVCP::BlockAddress);
6453
- SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
6454
- SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
6455
- return DAG.getLoad(
6456
- Ty, DL, DAG.getEntryNode(), LC,
6457
- MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
6458
- } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N)) {
6459
- RISCVConstantPoolSymbol *CPV =
6460
- RISCVConstantPoolSymbol::Create(*DAG.getContext(), S->getSymbol());
6461
- SDValue CPAddr = DAG.getTargetConstantPool(CPV, Ty, Align(8));
6462
- SDValue LC = DAG.getNode(RISCVISD::LLA, DL, Ty, CPAddr);
6463
- return DAG.getLoad(
6464
- Ty, DL, DAG.getEntryNode(), LC,
6465
- MachinePointerInfo::getConstantPool(DAG.getMachineFunction()));
6473
+ return getLargeBlockAddress(B, DL, Ty, DAG);
6466
6474
} else {
6467
6475
// Using pc-relative mode for other node type.
6468
6476
SDValue Addr = getTargetNode(N, DL, Ty, DAG, 0);
@@ -17533,10 +17541,12 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
17533
17541
// split it and then direct call can be matched by PseudoCALL.
17534
17542
if (getTargetMachine().getCodeModel() == CodeModel::Large) {
17535
17543
if (GlobalAddressSDNode *S = dyn_cast<GlobalAddressSDNode>(Callee)) {
17536
- Callee = getLargeAddr(S, DL, getPointerTy(DAG.getDataLayout()), DAG);
17544
+ Callee =
17545
+ getLargeGlobalAddress(S, DL, getPointerTy(DAG.getDataLayout()), DAG);
17537
17546
} else if (ExternalSymbolSDNode *S =
17538
17547
dyn_cast<ExternalSymbolSDNode>(Callee)) {
17539
- Callee = getLargeAddr(S, DL, getPointerTy(DAG.getDataLayout()), DAG);
17548
+ Callee =
17549
+ getLargeExternalSymbol(S, DL, getPointerTy(DAG.getDataLayout()), DAG);
17540
17550
}
17541
17551
} else {
17542
17552
if (GlobalAddressSDNode *S = dyn_cast<GlobalAddressSDNode>(Callee)) {
0 commit comments