[llvm] a60ca4b - [PowerPC][Future] Initial support for PCRel addressing to get block address
Kamau Bridgeman via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 22 13:01:47 PDT 2020
Author: Victor Huang
Date: 2020-04-22T15:01:29-05:00
New Revision: a60ca4b4e9b16347ff6c2842b555badffa6c09e3
URL: https://github.com/llvm/llvm-project/commit/a60ca4b4e9b16347ff6c2842b555badffa6c09e3
DIFF: https://github.com/llvm/llvm-project/commit/a60ca4b4e9b16347ff6c2842b555badffa6c09e3.diff
LOG: [PowerPC][Future] Initial support for PCRel addressing to get block address
Add initial support for PCRelative addressing to get block address
instead of using TOC.
Differential Revision: https://reviews.llvm.org/D76294
Added:
llvm/test/CodeGen/PowerPC/pcrel-block-address.ll
Modified:
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index effb1651d045..2922d90472ec 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -2588,6 +2588,11 @@ bool PPCTargetLowering::SelectAddressRegRegOnly(SDValue N, SDValue &Base,
return true;
}
+template <typename Ty> static bool isValidPCRelNode(SDValue N) {
+ Ty *PCRelCand = dyn_cast<Ty>(N);
+ return PCRelCand && (PCRelCand->getTargetFlags() & PPCII::MO_PCREL_FLAG);
+}
+
/// Returns true if this address is a PC Relative address.
/// PC Relative addresses are marked with the flag PPCII::MO_PCREL_FLAG
/// or if the node opcode is PPCISD::MAT_PCREL_ADDR.
@@ -2596,15 +2601,11 @@ bool PPCTargetLowering::SelectAddressPCRel(SDValue N, SDValue &Base) const {
Base = N;
if (N.getOpcode() == PPCISD::MAT_PCREL_ADDR)
return true;
- if (ConstantPoolSDNode *CPN = dyn_cast<ConstantPoolSDNode>(N))
- if (CPN->getTargetFlags() & PPCII::MO_PCREL_FLAG)
- return true;
- if (GlobalAddressSDNode *GAN = dyn_cast<GlobalAddressSDNode>(N))
- if (GAN->getTargetFlags() & PPCII::MO_PCREL_FLAG)
- return true;
- if (JumpTableSDNode *JT = dyn_cast<JumpTableSDNode>(N))
- if (JT->getTargetFlags() & PPCII::MO_PCREL_FLAG)
- return true;
+ if (isValidPCRelNode<ConstantPoolSDNode>(N) ||
+ isValidPCRelNode<GlobalAddressSDNode>(N) ||
+ isValidPCRelNode<JumpTableSDNode>(N) ||
+ isValidPCRelNode<BlockAddressSDNode>(N))
+ return true;
return false;
}
@@ -2936,6 +2937,16 @@ SDValue PPCTargetLowering::LowerBlockAddress(SDValue Op,
BlockAddressSDNode *BASDN = cast<BlockAddressSDNode>(Op);
const BlockAddress *BA = BASDN->getBlockAddress();
+ // isUsingPCRelativeCalls() returns true when PCRelative is enabled
+ if (Subtarget.isUsingPCRelativeCalls()) {
+ SDLoc DL(BASDN);
+ EVT Ty = getPointerTy(DAG.getDataLayout());
+ SDValue GA = DAG.getTargetBlockAddress(BA, Ty, BASDN->getOffset(),
+ PPCII::MO_PCREL_FLAG);
+ SDValue MatAddr = DAG.getNode(PPCISD::MAT_PCREL_ADDR, DL, Ty, GA);
+ return MatAddr;
+ }
+
// 64-bit SVR4 ABI and AIX ABI code are always position-independent.
// The actual BlockAddress is stored in the TOC.
if (Subtarget.is64BitELFABI() || Subtarget.isAIXABI()) {
diff --git a/llvm/test/CodeGen/PowerPC/pcrel-block-address.ll b/llvm/test/CodeGen/PowerPC/pcrel-block-address.ll
new file mode 100644
index 000000000000..b7219da94027
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/pcrel-block-address.ll
@@ -0,0 +1,16 @@
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
+; RUN: -mcpu=future -ppc-asm-full-reg-names < %s | FileCheck %s
+define dso_local void @blockaddress() {
+; CHECK-LABEL: blockaddress:
+; CHECK: # %bb.0: # %entry
+; CHECK: paddi r3, 0, .Ltmp0 at PCREL, 1
+; CHECK: bl helper at notoc
+entry:
+ tail call void @helper(i8* blockaddress(@blockaddress, %label))
+ br label %label
+
+label: ; preds = %entry
+ ret void
+}
+
+declare void @helper(i8*)
More information about the llvm-commits
mailing list