diff --git a/clang/include/clang/AST/GlobalDecl.h b/clang/include/clang/AST/GlobalDecl.h --- a/clang/include/clang/AST/GlobalDecl.h +++ b/clang/include/clang/AST/GlobalDecl.h @@ -68,7 +68,15 @@ GlobalDecl(const VarDecl *D) { Init(D);} GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0) : MultiVersionIndex(MVIndex) { - Init(D); + if (!D->hasAttr()) { + Init(D); + return; + } + Value.setPointerAndInt(D, unsigned(getDefaultKernelReference(D))); + } + GlobalDecl(const FunctionDecl *D, KernelReferenceKind Kind) + : Value(D, unsigned(Kind)) { + assert(D->hasAttr() && "Decl is not a GPU kernel!"); } GlobalDecl(const NamedDecl *D) { Init(D); } GlobalDecl(const BlockDecl *D) { Init(D); } @@ -80,10 +88,6 @@ 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() && "Decl is not a GPU kernel!"); - } GlobalDecl getCanonicalDecl() const { GlobalDecl CanonGD; @@ -145,10 +149,10 @@ 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 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -567,7 +567,7 @@ else if (const CXXDestructorDecl *DD = dyn_cast(ND)) GD = GlobalDecl(DD, Dtor_Base); else if (ND->hasAttr()) - GD = GlobalDecl::getDefaultKernelReference(cast(ND)); + GD = GlobalDecl(cast(ND)); else GD = GlobalDecl(ND); MC->mangleName(GD, Out); diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -1575,14 +1575,8 @@ GD = GlobalDecl(CD, Ctor_Complete); else if (auto *DD = dyn_cast(DC)) GD = GlobalDecl(DD, Dtor_Complete); - else { - auto *FD = cast(DC); - // Local variables can only exist in real kernels. - if (FD->hasAttr()) - GD = GlobalDecl(FD, KernelReferenceKind::Kernel); - else - GD = GlobalDecl(FD); - } + else + GD = GlobalDecl(cast(DC)); return GD; } diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -444,7 +444,7 @@ else if (const auto *DtorD = dyn_cast(D)) GD = GlobalDecl(DtorD, Dtor_Complete); else if (D->hasAttr()) - GD = GlobalDecl::getDefaultKernelReference(cast(D)); + GD = GlobalDecl(cast(D)); else GD = GlobalDecl(D); MC->mangleName(GD, OS); diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3833,8 +3833,7 @@ // 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 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -297,7 +297,7 @@ else if (const auto *DD = dyn_cast(DC)) GD = GlobalDecl(DD, Dtor_Base); else if (const auto *FD = dyn_cast(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 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -4678,12 +4678,12 @@ // Resolve direct calls. } else if (auto DRE = dyn_cast(E)) { if (auto FD = dyn_cast(DRE->getDecl())) { - return EmitDirectCallee(*this, CGM.getGlobalDecl(FD)); + return EmitDirectCallee(*this, FD); } } else if (auto ME = dyn_cast(E)) { if (auto FD = dyn_cast(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.h b/clang/lib/CodeGen/CodeGenModule.h --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -711,9 +711,6 @@ 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); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5302,7 +5302,7 @@ case Decl::CXXConversion: case Decl::CXXMethod: case Decl::Function: - EmitGlobal(getGlobalDecl(cast(D))); + EmitGlobal(cast(D)); // Always provide some coverage mapping // even for the functions that aren't emitted. AddDeferredUnusedCoverageMapping(D); @@ -5964,10 +5964,3 @@ "__translate_sampler_initializer"), {C}); } - -GlobalDecl CodeGenModule::getGlobalDecl(const FunctionDecl *FD) { - if (FD->hasAttr()) - return GlobalDecl::getDefaultKernelReference(FD); - else - return GlobalDecl(FD); -}