Skip to content

Commit 1fdf5ef

Browse files
author
Chen Zheng
committed
address comments
1 parent 6047403 commit 1fdf5ef

File tree

8 files changed

+61
-65
lines changed

8 files changed

+61
-65
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,9 +3841,12 @@ def note_cannot_use_trivial_abi_reason : Note<
38413841
"it is polymorphic|"
38423842
"it has a base of a non-trivial class type|it has a virtual base|"
38433843
"it has a __weak field|it has a field of a non-trivial class type}1">;
3844-
def warn_ppc_musttail_maybe_ignored: Warning<
3845-
"'musttail' attribute may be ignored on ppc targets">,
3846-
InGroup<IgnoredAttributes>;
3844+
def err_ppc_impossible_musttail: Error<
3845+
"'musttail' attribute for this call is impossible because %select{"
3846+
"long calls can not be tail called|"
3847+
"indirect calls can not be tail called|"
3848+
"external calls can not be tail called}0"
3849+
>;
38473850
def err_aix_musttail_unsupported: Error<
38483851
"'musttail' attribute is not supported on AIX">;
38493852

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
9393
HasQuadwordAtomics = true;
9494
} else if (Feature == "+aix-shared-lib-tls-model-opt") {
9595
HasAIXShLibTLSModelOpt = true;
96+
} else if (Feature == "+longcall") {
97+
UseLongCalls = true;
9698
}
9799
// TODO: Finish this list and add an assert that we've handled them
98100
// all.
@@ -728,6 +730,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
728730
.Case("isa-v31-instructions", IsISA3_1)
729731
.Case("quadword-atomics", HasQuadwordAtomics)
730732
.Case("aix-shared-lib-tls-model-opt", HasAIXShLibTLSModelOpt)
733+
.Case("longcall", UseLongCalls)
731734
.Default(false);
732735
}
733736

clang/lib/Basic/Targets/PPC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public TargetInfo {
8282
bool IsISA3_1 = false;
8383
bool HasQuadwordAtomics = false;
8484
bool HasAIXShLibTLSModelOpt = false;
85+
bool UseLongCalls = false;
8586

8687
protected:
8788
std::string ABI;

clang/lib/CodeGen/CGCall.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "clang/AST/DeclCXX.h"
2727
#include "clang/AST/DeclObjC.h"
2828
#include "clang/Basic/CodeGenOptions.h"
29-
#include "clang/Basic/DiagnosticSema.h"
3029
#include "clang/Basic/TargetInfo.h"
3130
#include "clang/CodeGen/CGFunctionInfo.h"
3231
#include "clang/CodeGen/SwiftCallingConv.h"
@@ -5752,15 +5751,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
57525751
if (llvm::CallInst *Call = dyn_cast<llvm::CallInst>(CI)) {
57535752
if (TargetDecl && TargetDecl->hasAttr<NotTailCalledAttr>())
57545753
Call->setTailCallKind(llvm::CallInst::TCK_NoTail);
5755-
else if (IsMustTail) {
5756-
if (getTarget().getTriple().isPPC()) {
5757-
if (getTarget().getTriple().isOSAIX())
5758-
CGM.getDiags().Report(Loc, diag::err_aix_musttail_unsupported);
5759-
else
5760-
CGM.getDiags().Report(Loc, diag::warn_ppc_musttail_maybe_ignored);
5761-
}
5754+
else if (IsMustTail)
57625755
Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
5763-
}
57645756
}
57655757

57665758
// Add metadata for calls to MSAllocator functions

clang/lib/Sema/SemaStmt.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,20 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr &MTA) {
743743
CallerType.Func = CallerDecl->getType()->getAs<FunctionProtoType>();
744744
}
745745

746+
if (Context.getTargetInfo().getTriple().isPPC()) {
747+
if (Context.getTargetInfo().getTriple().isOSAIX())
748+
return Diag(St->getBeginLoc(), diag::err_aix_musttail_unsupported);
749+
else if (!Context.getTargetInfo().hasFeature("pcrelative-memops")) {
750+
if (Context.getTargetInfo().hasFeature("longcall"))
751+
return Diag(St->getBeginLoc(), diag::err_ppc_impossible_musttail) << 0;
752+
else if (!CE->getDirectCallee())
753+
return Diag(St->getBeginLoc(), diag::err_ppc_impossible_musttail) << 1;
754+
else if (isa_and_nonnull<FunctionDecl>(CE->getCalleeDecl()) &&
755+
!cast<FunctionDecl>(CE->getCalleeDecl())->isDefined())
756+
return Diag(St->getBeginLoc(), diag::err_ppc_impossible_musttail) << 2;
757+
}
758+
}
759+
746760
const Expr *CalleeExpr = CE->getCallee()->IgnoreParens();
747761
const auto *CalleeBinOp = dyn_cast<BinaryOperator>(CalleeExpr);
748762
SourceLocation CalleeLoc = CE->getCalleeDecl()
Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
1-
// RUN: %clang_cc1 %s -triple powerpc64-ibm-aix-xcoff -o /dev/null -emit-llvm -verify=aix
2-
// RUN: %clang_cc1 %s -triple powerpc-ibm-aix-xcoff -o /dev/null -emit-llvm -verify=aix
3-
// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -o /dev/null -emit-llvm -verify=linux
4-
// RUN: %clang_cc1 %s -triple powerpc-unknown-linux-gnu -o /dev/null -emit-llvm -verify=linux
5-
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -o /dev/null -emit-llvm -verify=linux
1+
// RUN: %clang_cc1 %s -triple powerpc64-ibm-aix-xcoff -fsyntax-only -verify=aix
2+
// RUN: %clang_cc1 %s -triple powerpc-ibm-aix-xcoff -fsyntax-only -verify=aix
3+
// RUN: %clang_cc1 %s -triple powerpc64-unknown-linux-gnu -fsyntax-only -verify=linux
4+
// RUN: %clang_cc1 %s -triple powerpc-unknown-linux-gnu -fsyntax-only -verify=linux
5+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -fsyntax-only -verify=linux
6+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -target-feature +pcrelative-memops -fsyntax-only -verify=good
7+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -target-feature +longcall -fsyntax-only -verify=longcall
8+
// RUN: %clang_cc1 %s -triple powerpc64le-unknown-linux-gnu -target-feature +pcrelative-memops -target-feature +longcall -fsyntax-only -verify=good
69

7-
int Func();
8-
int Func1() {
9-
// linux-warning@+2 {{'musttail' attribute may be ignored on ppc targets}}
10+
int good_callee() {
11+
return 0;
12+
}
13+
int good_caller() {
14+
// good-no-diagnostics
15+
// longcall-error@+2 {{'musttail' attribute for this call is impossible because long calls can not be tail called}}
16+
// aix-error@+1 {{'musttail' attribute is not supported on AIX}}
17+
[[clang::musttail]] return good_callee();
18+
}
19+
20+
int func();
21+
int external_call() {
22+
// good-no-diagnostics
23+
// longcall-error@+3 {{'musttail' attribute for this call is impossible because long calls can not be tail called}}
24+
// linux-error@+2 {{'musttail' attribute for this call is impossible because external calls can not be tail called}}
25+
// aix-error@+1 {{'musttail' attribute is not supported on AIX}}
26+
[[clang::musttail]] return func();
27+
}
28+
29+
void indirect_call(int r) {
30+
auto Fn = (void (*)(int))1;
31+
// good-no-diagnostics
32+
// longcall-error@+3 {{'musttail' attribute for this call is impossible because long calls can not be tail called}}
33+
// linux-error@+2 {{'musttail' attribute for this call is impossible because indirect calls can not be tail called}}
1034
// aix-error@+1 {{'musttail' attribute is not supported on AIX}}
11-
[[clang::musttail]] return Func();
35+
[[clang::musttail]] return Fn(r);
1236
}

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ static cl::opt<unsigned> PPCAIXTLSModelOptUseIEForLDLimit(
146146
cl::desc("Set inclusive limit count of TLS local-dynamic access(es) in a "
147147
"function to use initial-exec"));
148148

149-
static cl::opt<bool> AbortOnImpossibleMusttailCall(
150-
"ppc-abort-on-impossible-musttailcall", cl::init(false), cl::Hidden,
151-
cl::desc("Abort if any call marked as musttail is impossible."));
152-
153149
STATISTIC(NumTailCalls, "Number of tail calls");
154150
STATISTIC(NumSiblingCalls, "Number of sibling calls");
155151
STATISTIC(ShufflesHandledWithVPERM,
@@ -5949,14 +5945,9 @@ PPCTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
59495945
}
59505946
}
59515947

5952-
if (!isTailCall && CB && CB->isMustTailCall()) {
5953-
if (AbortOnImpossibleMusttailCall)
5954-
report_fatal_error("failed to perform tail call elimination on a call "
5955-
"site marked musttail");
5956-
else
5957-
cast<CallInst>(const_cast<CallBase *>(CB))
5958-
->setTailCallKind(llvm::CallInst::TCK_Tail);
5959-
}
5948+
if (!isTailCall && CB && CB->isMustTailCall())
5949+
report_fatal_error("failed to perform tail call elimination on a call "
5950+
"site marked musttail");
59605951

59615952
// When long calls (i.e. indirect calls) are always used, calls are always
59625953
// made via function pointer. If we have a function name, first translate it

llvm/test/CodeGen/PowerPC/musttail-call.ll

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)