[llvm] r280040 - [PowerPC] Add support for -mlongcall
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 29 17:59:23 PDT 2016
Author: hfinkel
Date: Mon Aug 29 19:59:23 2016
New Revision: 280040
URL: http://llvm.org/viewvc/llvm-project?rev=280040&view=rev
Log:
[PowerPC] Add support for -mlongcall
The "long call" option forces the use of the indirect calling sequence for all
calls (even those that don't really need it). GCC provides this option; This is
helpful, under certain circumstances, for building very-large binaries, and
some other specialized use cases.
Fixes PR19098.
Added:
llvm/trunk/test/CodeGen/PowerPC/longcall.ll
Modified:
llvm/trunk/lib/Target/PowerPC/PPC.td
llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp
llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h
Modified: llvm/trunk/lib/Target/PowerPC/PPC.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPC.td?rev=280040&r1=280039&r2=280040&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPC.td (original)
+++ llvm/trunk/lib/Target/PowerPC/PPC.td Mon Aug 29 19:59:23 2016
@@ -136,6 +136,8 @@ def FeatureInvariantFunctionDescriptors
SubtargetFeature<"invariant-function-descriptors",
"HasInvariantFunctionDescriptors", "true",
"Assume function descriptors are invariant">;
+def FeatureLongCall : SubtargetFeature<"longcall", "UseLongCalls", "true",
+ "Always use indirect calls">;
def FeatureHTM : SubtargetFeature<"htm", "HasHTM", "true",
"Enable Hardware Transactional Memory instructions">;
def FeatureMFTB : SubtargetFeature<"", "FeatureMFTB", "true",
Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=280040&r1=280039&r2=280040&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Mon Aug 29 19:59:23 2016
@@ -4695,7 +4695,9 @@ PPCTargetLowering::LowerCall(TargetLower
ImmutableCallSite *CS = CLI.CS;
if (isTailCall) {
- if (Subtarget.isSVR4ABI() && Subtarget.isPPC64())
+ if (Subtarget.useLongCalls() && !(CS && CS->isMustTailCall()))
+ isTailCall = false;
+ else if (Subtarget.isSVR4ABI() && Subtarget.isPPC64())
isTailCall =
IsEligibleForTailCallOptimization_64SVR4(Callee, CallConv, CS,
isVarArg, Outs, Ins, DAG);
@@ -4725,6 +4727,13 @@ PPCTargetLowering::LowerCall(TargetLower
report_fatal_error("failed to perform tail call elimination on a call "
"site marked musttail");
+ // When long calls (i.e. indirect calls) are always used, calls are always
+ // made via function pointer. If we have a function name, first translate it
+ // into a pointer.
+ if (Subtarget.useLongCalls() && isa<GlobalAddressSDNode>(Callee) &&
+ !isTailCall)
+ Callee = LowerGlobalAddress(Callee, DAG);
+
if (Subtarget.isSVR4ABI()) {
if (Subtarget.isPPC64())
return LowerCall_64SVR4(Chain, Callee, CallConv, isVarArg,
Modified: llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp?rev=280040&r1=280039&r2=280040&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCSubtarget.cpp Mon Aug 29 19:59:23 2016
@@ -105,6 +105,7 @@ void PPCSubtarget::initializeEnvironment
HasFusion = false;
HasFloat128 = false;
IsISA3_0 = false;
+ UseLongCalls = false;
HasPOPCNTD = POPCNTD_Unavailable;
}
Modified: llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h?rev=280040&r1=280039&r2=280040&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCSubtarget.h Mon Aug 29 19:59:23 2016
@@ -132,6 +132,7 @@ protected:
bool HasFusion;
bool HasFloat128;
bool IsISA3_0;
+ bool UseLongCalls;
POPCNTDKind HasPOPCNTD;
@@ -275,6 +276,7 @@ public:
bool hasFusion() const { return HasFusion; }
bool hasFloat128() const { return HasFloat128; }
bool isISA3_0() const { return IsISA3_0; }
+ bool useLongCalls() const { return UseLongCalls; }
POPCNTDKind hasPOPCNTD() const { return HasPOPCNTD; }
Added: llvm/trunk/test/CodeGen/PowerPC/longcall.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/longcall.ll?rev=280040&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/longcall.ll (added)
+++ llvm/trunk/test/CodeGen/PowerPC/longcall.ll Mon Aug 29 19:59:23 2016
@@ -0,0 +1,26 @@
+; RUN: llc < %s | FileCheck %s
+target datalayout = "E-m:e-i64:64-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"
+
+; Function Attrs: nounwind
+define void @bar() local_unnamed_addr #0 {
+entry:
+ tail call void @foo() #1
+ ret void
+
+; CHECK-LABEL: @bar
+; CHECK: ld [[FD:[0-9]+]], .LC0 at toc@l({{[0-9]+}})
+; CHECK: ld [[ADDR:[0-9]+]], 0([[FD]])
+; CHECK: mtctr [[ADDR]]
+; CHECK: bctrl
+; CHECK-NOT: bl foo
+; CHECK: blr
+}
+
+; CHECK: .tc foo
+
+declare void @foo() local_unnamed_addr
+
+attributes #0 = { nounwind "target-cpu"="ppc64" "target-features"="+longcall" }
+attributes #1 = { nounwind }
+
More information about the llvm-commits
mailing list