Author: Michael Liao Date: 2020-03-18T09:33:39-04:00 New Revision: 4cf01ed75e35e7bd3ef8ef1a2192c7f4656ab545
URL: https://github.com/llvm/llvm-project/commit/4cf01ed75e35e7bd3ef8ef1a2192c7f4656ab545 DIFF: https://github.com/llvm/llvm-project/commit/4cf01ed75e35e7bd3ef8ef1a2192c7f4656ab545.diff LOG: [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 Added: Modified: clang/include/clang/AST/GlobalDecl.h clang/lib/AST/Expr.cpp clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/Mangle.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenModule.h Removed: ################################################################################ diff --git a/clang/include/clang/AST/GlobalDecl.h b/clang/include/clang/AST/GlobalDecl.h index d2b5566a4cfa..bf30d9b94235 100644 --- a/clang/include/clang/AST/GlobalDecl.h +++ b/clang/include/clang/AST/GlobalDecl.h @@ -68,7 +68,15 @@ class GlobalDecl { 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 @@ class GlobalDecl { 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 @@ class GlobalDecl { 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) { diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 1eb56c30283c..6591b0481d4b 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -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); diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 6deab2a95494..12e1fc589fdc 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -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; } diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp index cc46994c1003..30078fcb243d 100644 --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -444,7 +444,7 @@ class ASTNameGenerator::Implementation { 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); diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index a1ecddd3da7f..94dab4c85614 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -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) { diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 034e725c0eeb..c5de1e077b0c 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -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. diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index a3399af183b5..6457852f1b6d 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -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. diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 4ece40bd9fe0..cd77a727231b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -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); -} diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 77b90024635c..fc4486659426 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -711,9 +711,6 @@ class CodeGenModule : public CodeGenTypeCache { 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); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits