From 144a31f53b0a97a2c46bfcb1e2a40fa8327b8e89 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 5 Jun 2013 17:49:37 +0000 Subject: [PATCH] [ms-cxxabi] Thread GlobalDecls through to CodeGenModule::getFunctionLinkage. This is so that we can give destructor variants different linkage later. Differential Revision: http://llvm-reviews.chandlerc.com/D819 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183324 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCXX.cpp | 9 ++++----- lib/CodeGen/CGVTables.cpp | 4 ++-- lib/CodeGen/CodeGenModule.cpp | 14 ++++++++------ lib/CodeGen/CodeGenModule.h | 9 ++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index 983cb9224a..afeb090d5b 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -106,8 +106,7 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl, // The alias will use the linkage of the referrent. If we can't // support aliases with that linkage, fail. - llvm::GlobalValue::LinkageTypes Linkage - = getFunctionLinkage(cast(AliasDecl.getDecl())); + llvm::GlobalValue::LinkageTypes Linkage = getFunctionLinkage(AliasDecl); switch (Linkage) { // We can definitely emit aliases to definitions with external linkage. @@ -132,7 +131,7 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl, } llvm::GlobalValue::LinkageTypes TargetLinkage - = getFunctionLinkage(cast(TargetDecl.getDecl())); + = getFunctionLinkage(TargetDecl); if (llvm::GlobalValue::isWeakForLinker(TargetLinkage)) return true; @@ -203,7 +202,7 @@ void CodeGenModule::EmitCXXConstructor(const CXXConstructorDecl *ctor, llvm::Function *fn = cast(GetAddrOfCXXConstructor(ctor, ctorType, &fnInfo)); - setFunctionLinkage(ctor, fn); + setFunctionLinkage(GlobalDecl(ctor, ctorType), fn); CodeGenFunction(*this).GenerateCode(GlobalDecl(ctor, ctorType), fn, fnInfo); @@ -267,7 +266,7 @@ void CodeGenModule::EmitCXXDestructor(const CXXDestructorDecl *dtor, llvm::Function *fn = cast(GetAddrOfCXXDestructor(dtor, dtorType, &fnInfo)); - setFunctionLinkage(dtor, fn); + setFunctionLinkage(GlobalDecl(dtor, dtorType), fn); CodeGenFunction(*this).GenerateCode(GlobalDecl(dtor, dtorType), fn, fnInfo); diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 9a345cf472..b1072b4721 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -379,7 +379,7 @@ void CodeGenFunction::GenerateThunk(llvm::Function *Fn, FinishFunction(); // Set the right linkage. - CGM.setFunctionLinkage(MD, Fn); + CGM.setFunctionLinkage(GD, Fn); // Set the right visibility. setThunkVisibility(CGM, MD, Thunk, Fn); @@ -437,7 +437,7 @@ void CodeGenVTables::EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk, "Function should have available_externally linkage!"); // Change the linkage. - CGM.setFunctionLinkage(cast(GD.getDecl()), ThunkFn); + CGM.setFunctionLinkage(GD, ThunkFn); return; } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 4d64624dbc..d49fc0b031 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -509,7 +509,8 @@ void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) { } llvm::GlobalValue::LinkageTypes -CodeGenModule::getFunctionLinkage(const FunctionDecl *D) { +CodeGenModule::getFunctionLinkage(GlobalDecl GD) { + const FunctionDecl *D = cast(GD.getDecl()); GVALinkage Linkage = getContext().GetGVALinkageForFunction(D); if (Linkage == GVA_Internal) @@ -1230,9 +1231,10 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) { } bool -CodeGenModule::shouldEmitFunction(const FunctionDecl *F) { - if (getFunctionLinkage(F) != llvm::Function::AvailableExternallyLinkage) +CodeGenModule::shouldEmitFunction(GlobalDecl GD) { + if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage) return true; + const FunctionDecl *F = cast(GD.getDecl()); if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr() && !F->hasAttr()) return false; @@ -1268,10 +1270,10 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD) { Context.getSourceManager(), "Generating code for declaration"); - if (const FunctionDecl *Function = dyn_cast(D)) { + if (isa(D)) { // At -O0, don't generate IR for functions with available_externally // linkage. - if (!shouldEmitFunction(Function)) + if (!shouldEmitFunction(GD)) return; if (const CXXMethodDecl *Method = dyn_cast(D)) { @@ -2177,7 +2179,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD) { // want to propagate this information down (e.g. to local static // declarations). llvm::Function *Fn = cast(Entry); - setFunctionLinkage(D, Fn); + setFunctionLinkage(GD, Fn); // FIXME: this is redundant with part of SetFunctionDefinitionAttributes setGlobalVisibility(Fn, D); diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index aa48cce08b..b2ff60deff 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -386,7 +386,7 @@ class CodeGenModule : public CodeGenTypeCache { void createCUDARuntime(); bool isTriviallyRecursive(const FunctionDecl *F); - bool shouldEmitFunction(const FunctionDecl *F); + bool shouldEmitFunction(GlobalDecl GD); /// @name Cache for Blocks Runtime Globals /// @{ @@ -924,11 +924,10 @@ public: /// \brief Appends a dependent lib to the "Linker Options" metadata value. void AddDependentLib(StringRef Lib); - llvm::GlobalVariable::LinkageTypes - getFunctionLinkage(const FunctionDecl *FD); + llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); - void setFunctionLinkage(const FunctionDecl *FD, llvm::GlobalValue *V) { - V->setLinkage(getFunctionLinkage(FD)); + void setFunctionLinkage(GlobalDecl GD, llvm::GlobalValue *V) { + V->setLinkage(getFunctionLinkage(GD)); } /// getVTableLinkage - Return the appropriate linkage for the vtable, VTT, -- 2.40.0