@@ -6432,37 +6432,45 @@ static SDValue getTargetNode(JumpTableSDNode *N, const SDLoc &DL, EVT Ty,
64326432 return DAG.getTargetJumpTable(N->getIndex(), Ty, Flags);
64336433}
64346434
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()));
64386466}
64396467
64406468template <class NodeTy>
64416469static SDValue getLargeAddr(NodeTy *N, SDLoc DL, EVT Ty, SelectionDAG &DAG) {
64426470 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);
64506472 } 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);
64666474 } else {
64676475 // Using pc-relative mode for other node type.
64686476 SDValue Addr = getTargetNode(N, DL, Ty, DAG, 0);
@@ -17533,10 +17541,12 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
1753317541 // split it and then direct call can be matched by PseudoCALL.
1753417542 if (getTargetMachine().getCodeModel() == CodeModel::Large) {
1753517543 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);
1753717546 } else if (ExternalSymbolSDNode *S =
1753817547 dyn_cast<ExternalSymbolSDNode>(Callee)) {
17539- Callee = getLargeAddr(S, DL, getPointerTy(DAG.getDataLayout()), DAG);
17548+ Callee =
17549+ getLargeExternalSymbol(S, DL, getPointerTy(DAG.getDataLayout()), DAG);
1754017550 }
1754117551 } else {
1754217552 if (GlobalAddressSDNode *S = dyn_cast<GlobalAddressSDNode>(Callee)) {
0 commit comments