forked from OSchip/llvm-project
[hip] Revise `GlobalDecl` constructors. NFC.
Summary: - https://reviews.llvm.org/D68578 revises the `GlobalDecl` constructors to ensure all GPU kernels have `ReferenceKenelKind` initialized properly with an explicit constructor and static one. But, there are lots of places using the implicit constructor triggering the assertion on non-GPU kernels. That's found in compilation of many tests and workloads. - Fixing all of them may change more code and, more importantly, all of them assumes the default kernel reference kind. This patch changes that constructor to tell `CUDAGlobalAttr` and construct `GlobalDecl` properly. Reviewers: yaxunl Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76344
This commit is contained in:
parent
6739805e24
commit
4cf01ed75e
|
@ -68,7 +68,15 @@ public:
|
|||
GlobalDecl(const VarDecl *D) { Init(D);}
|
||||
GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
|
||||
: MultiVersionIndex(MVIndex) {
|
||||
Init(D);
|
||||
if (!D->hasAttr<CUDAGlobalAttr>()) {
|
||||
Init(D);
|
||||
return;
|
||||
}
|
||||
Value.setPointerAndInt(D, unsigned(getDefaultKernelReference(D)));
|
||||
}
|
||||
GlobalDecl(const FunctionDecl *D, KernelReferenceKind Kind)
|
||||
: Value(D, unsigned(Kind)) {
|
||||
assert(D->hasAttr<CUDAGlobalAttr>() && "Decl is not a GPU kernel!");
|
||||
}
|
||||
GlobalDecl(const NamedDecl *D) { Init(D); }
|
||||
GlobalDecl(const BlockDecl *D) { Init(D); }
|
||||
|
@ -80,10 +88,6 @@ public:
|
|||
GlobalDecl(const CXXDestructorDecl *D, CXXDtorType Type) : Value(D, Type) {}
|
||||
GlobalDecl(const VarDecl *D, DynamicInitKind StubKind)
|
||||
: Value(D, unsigned(StubKind)) {}
|
||||
GlobalDecl(const FunctionDecl *D, KernelReferenceKind Kind)
|
||||
: Value(D, unsigned(Kind)) {
|
||||
assert(D->hasAttr<CUDAGlobalAttr>() && "Decl is not a GPU kernel!");
|
||||
}
|
||||
|
||||
GlobalDecl getCanonicalDecl() const {
|
||||
GlobalDecl CanonGD;
|
||||
|
@ -145,10 +149,10 @@ public:
|
|||
return GD;
|
||||
}
|
||||
|
||||
static GlobalDecl getDefaultKernelReference(const FunctionDecl *D) {
|
||||
return GlobalDecl(D, D->getASTContext().getLangOpts().CUDAIsDevice
|
||||
? KernelReferenceKind::Kernel
|
||||
: KernelReferenceKind::Stub);
|
||||
static KernelReferenceKind getDefaultKernelReference(const FunctionDecl *D) {
|
||||
return D->getASTContext().getLangOpts().CUDAIsDevice
|
||||
? KernelReferenceKind::Kernel
|
||||
: KernelReferenceKind::Stub;
|
||||
}
|
||||
|
||||
GlobalDecl getWithDecl(const Decl *D) {
|
||||
|
|
|
@ -567,7 +567,7 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const Decl *CurrentDecl) {
|
|||
else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(ND))
|
||||
GD = GlobalDecl(DD, Dtor_Base);
|
||||
else if (ND->hasAttr<CUDAGlobalAttr>())
|
||||
GD = GlobalDecl::getDefaultKernelReference(cast<FunctionDecl>(ND));
|
||||
GD = GlobalDecl(cast<FunctionDecl>(ND));
|
||||
else
|
||||
GD = GlobalDecl(ND);
|
||||
MC->mangleName(GD, Out);
|
||||
|
|
|
@ -1575,14 +1575,8 @@ static GlobalDecl getParentOfLocalEntity(const DeclContext *DC) {
|
|||
GD = GlobalDecl(CD, Ctor_Complete);
|
||||
else if (auto *DD = dyn_cast<CXXDestructorDecl>(DC))
|
||||
GD = GlobalDecl(DD, Dtor_Complete);
|
||||
else {
|
||||
auto *FD = cast<FunctionDecl>(DC);
|
||||
// Local variables can only exist in real kernels.
|
||||
if (FD->hasAttr<CUDAGlobalAttr>())
|
||||
GD = GlobalDecl(FD, KernelReferenceKind::Kernel);
|
||||
else
|
||||
GD = GlobalDecl(FD);
|
||||
}
|
||||
else
|
||||
GD = GlobalDecl(cast<FunctionDecl>(DC));
|
||||
return GD;
|
||||
}
|
||||
|
||||
|
|
|
@ -444,7 +444,7 @@ private:
|
|||
else if (const auto *DtorD = dyn_cast<CXXDestructorDecl>(D))
|
||||
GD = GlobalDecl(DtorD, Dtor_Complete);
|
||||
else if (D->hasAttr<CUDAGlobalAttr>())
|
||||
GD = GlobalDecl::getDefaultKernelReference(cast<FunctionDecl>(D));
|
||||
GD = GlobalDecl(cast<FunctionDecl>(D));
|
||||
else
|
||||
GD = GlobalDecl(D);
|
||||
MC->mangleName(GD, OS);
|
||||
|
|
|
@ -3833,8 +3833,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
|
|||
// create the one describing the function in order to have complete
|
||||
// call site debug info.
|
||||
if (!CalleeDecl->isStatic() && !CalleeDecl->isInlined())
|
||||
EmitFunctionDecl(CGM.getGlobalDecl(CalleeDecl), CalleeDecl->getLocation(),
|
||||
CalleeType, Func);
|
||||
EmitFunctionDecl(CalleeDecl, CalleeDecl->getLocation(), CalleeType, Func);
|
||||
}
|
||||
|
||||
void CGDebugInfo::EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD) {
|
||||
|
|
|
@ -297,7 +297,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl(
|
|||
else if (const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
|
||||
GD = GlobalDecl(DD, Dtor_Base);
|
||||
else if (const auto *FD = dyn_cast<FunctionDecl>(DC))
|
||||
GD = getGlobalDecl(FD);
|
||||
GD = GlobalDecl(FD);
|
||||
else {
|
||||
// Don't do anything for Obj-C method decls or global closures. We should
|
||||
// never defer them.
|
||||
|
|
|
@ -4678,12 +4678,12 @@ CGCallee CodeGenFunction::EmitCallee(const Expr *E) {
|
|||
// Resolve direct calls.
|
||||
} else if (auto DRE = dyn_cast<DeclRefExpr>(E)) {
|
||||
if (auto FD = dyn_cast<FunctionDecl>(DRE->getDecl())) {
|
||||
return EmitDirectCallee(*this, CGM.getGlobalDecl(FD));
|
||||
return EmitDirectCallee(*this, FD);
|
||||
}
|
||||
} else if (auto ME = dyn_cast<MemberExpr>(E)) {
|
||||
if (auto FD = dyn_cast<FunctionDecl>(ME->getMemberDecl())) {
|
||||
EmitIgnoredExpr(ME->getBase());
|
||||
return EmitDirectCallee(*this, CGM.getGlobalDecl(FD));
|
||||
return EmitDirectCallee(*this, FD);
|
||||
}
|
||||
|
||||
// Look through template substitutions.
|
||||
|
|
|
@ -5302,7 +5302,7 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
|
|||
case Decl::CXXConversion:
|
||||
case Decl::CXXMethod:
|
||||
case Decl::Function:
|
||||
EmitGlobal(getGlobalDecl(cast<FunctionDecl>(D)));
|
||||
EmitGlobal(cast<FunctionDecl>(D));
|
||||
// Always provide some coverage mapping
|
||||
// even for the functions that aren't emitted.
|
||||
AddDeferredUnusedCoverageMapping(D);
|
||||
|
@ -5964,10 +5964,3 @@ CodeGenModule::createOpenCLIntToSamplerConversion(const Expr *E,
|
|||
"__translate_sampler_initializer"),
|
||||
{C});
|
||||
}
|
||||
|
||||
GlobalDecl CodeGenModule::getGlobalDecl(const FunctionDecl *FD) {
|
||||
if (FD->hasAttr<CUDAGlobalAttr>())
|
||||
return GlobalDecl::getDefaultKernelReference(FD);
|
||||
else
|
||||
return GlobalDecl(FD);
|
||||
}
|
||||
|
|
|
@ -711,9 +711,6 @@ public:
|
|||
CtorList &getGlobalCtors() { return GlobalCtors; }
|
||||
CtorList &getGlobalDtors() { return GlobalDtors; }
|
||||
|
||||
/// get GlobalDecl for non-ctor/dtor functions.
|
||||
GlobalDecl getGlobalDecl(const FunctionDecl *FD);
|
||||
|
||||
/// getTBAATypeInfo - Get metadata used to describe accesses to objects of
|
||||
/// the given type.
|
||||
llvm::MDNode *getTBAATypeInfo(QualType QTy);
|
||||
|
|
Loading…
Reference in New Issue