Simplify setting dso_local. NFC.

The value of dso_local can be computed from just IR properties and
global information (object file type, command line options, etc).

With this patch we no longer pass in the Decl. It was almost unused
and making it fully unused guarantees that dso_local is consistent
with the rest of the IR.

llvm-svn: 325846
This commit is contained in:
Rafael Espindola 2018-02-23 00:22:15 +00:00
parent 0dcc88a500
commit 3dd4981298
3 changed files with 12 additions and 12 deletions

View File

@ -712,7 +712,7 @@ void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
} }
static bool shouldAssumeDSOLocal(const CodeGenModule &CGM, static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
llvm::GlobalValue *GV, const NamedDecl *D) { llvm::GlobalValue *GV) {
const llvm::Triple &TT = CGM.getTriple(); const llvm::Triple &TT = CGM.getTriple();
// Only handle ELF for now. // Only handle ELF for now.
if (!TT.isOSBinFormatELF()) if (!TT.isOSBinFormatELF())
@ -742,31 +742,30 @@ static bool shouldAssumeDSOLocal(const CodeGenModule &CGM,
return false; return false;
// If we can use copy relocations we can assume it is local. // If we can use copy relocations we can assume it is local.
if (auto *VD = dyn_cast<VarDecl>(D)) if (auto *Var = dyn_cast<llvm::GlobalVariable>(GV))
if (VD->getTLSKind() == VarDecl::TLS_None && if (!Var->isThreadLocal() &&
(RM == llvm::Reloc::Static || CGOpts.PIECopyRelocations)) (RM == llvm::Reloc::Static || CGOpts.PIECopyRelocations))
return true; return true;
// If we can use a plt entry as the symbol address we can assume it // If we can use a plt entry as the symbol address we can assume it
// is local. // is local.
// FIXME: This should work for PIE, but the gold linker doesn't support it. // FIXME: This should work for PIE, but the gold linker doesn't support it.
if (isa<FunctionDecl>(D) && !CGOpts.NoPLT && RM == llvm::Reloc::Static) if (isa<llvm::Function>(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static)
return true; return true;
// Otherwise don't assue it is local. // Otherwise don't assue it is local.
return false; return false;
} }
void CodeGenModule::setDSOLocal(llvm::GlobalValue *GV, void CodeGenModule::setDSOLocal(llvm::GlobalValue *GV) const {
const NamedDecl *D) const { if (shouldAssumeDSOLocal(*this, GV))
if (shouldAssumeDSOLocal(*this, GV, D))
GV->setDSOLocal(true); GV->setDSOLocal(true);
} }
void CodeGenModule::setGVProperties(llvm::GlobalValue *GV, void CodeGenModule::setGVProperties(llvm::GlobalValue *GV,
const NamedDecl *D) const { const NamedDecl *D) const {
setGlobalVisibility(GV, D); setGlobalVisibility(GV, D);
setDSOLocal(GV, D); setDSOLocal(GV);
} }
static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S) { static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S) {
@ -2749,7 +2748,6 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
GV->setAlignment(getContext().getDeclAlign(D).getQuantity()); GV->setAlignment(getContext().getDeclAlign(D).getQuantity());
setLinkageForGV(GV, D); setLinkageForGV(GV, D);
setGVProperties(GV, D);
if (D->getTLSKind()) { if (D->getTLSKind()) {
if (D->getTLSKind() == VarDecl::TLS_Dynamic) if (D->getTLSKind() == VarDecl::TLS_Dynamic)
@ -2757,6 +2755,8 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName,
setTLSMode(GV, *D); setTLSMode(GV, *D);
} }
setGVProperties(GV, D);
// If required by the ABI, treat declarations of static data members with // If required by the ABI, treat declarations of static data members with
// inline initializers as definitions. // inline initializers as definitions.
if (getContext().isMSStaticDataMemberInlineDefinition(D)) { if (getContext().isMSStaticDataMemberInlineDefinition(D)) {

View File

@ -721,7 +721,7 @@ public:
/// Set the visibility for the given LLVM GlobalValue. /// Set the visibility for the given LLVM GlobalValue.
void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const; void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
void setDSOLocal(llvm::GlobalValue *GV, const NamedDecl *D) const; void setDSOLocal(llvm::GlobalValue *GV) const;
void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const; void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;

View File

@ -3214,10 +3214,10 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force,
llvmVisibility = CodeGenModule::GetLLVMVisibility(Ty->getVisibility()); llvmVisibility = CodeGenModule::GetLLVMVisibility(Ty->getVisibility());
TypeName->setVisibility(llvmVisibility); TypeName->setVisibility(llvmVisibility);
CGM.setDSOLocal(TypeName, Ty->getAsCXXRecordDecl()); CGM.setDSOLocal(TypeName);
GV->setVisibility(llvmVisibility); GV->setVisibility(llvmVisibility);
CGM.setDSOLocal(GV, Ty->getAsCXXRecordDecl()); CGM.setDSOLocal(GV);
if (CGM.getTriple().isWindowsItaniumEnvironment()) { if (CGM.getTriple().isWindowsItaniumEnvironment()) {
auto RD = Ty->getAsCXXRecordDecl(); auto RD = Ty->getAsCXXRecordDecl();