forked from OSchip/llvm-project
CodeGen, Target: Move Mach-O-specific symbol name logic to Mach-O lowering.
A profile of an LTO link of Chrome revealed that we were spending some ~30-50% of execution time in the function Constant::getRelocationInfo(), which is called from TargetLoweringObjectFile::getKindForGlobal() and in turn from TargetMachine::getNameWithPrefix(). It turns out that we only need the result of getKindForGlobal() when targeting Mach-O, so this change moves the relevant part of the logic to TargetLoweringObjectFileMachO. NFCI. Differential Revision: http://reviews.llvm.org/D14168 llvm-svn: 252014
This commit is contained in:
parent
26014690aa
commit
94d778697a
|
@ -123,6 +123,9 @@ public:
|
||||||
const MCValue &MV, int64_t Offset,
|
const MCValue &MV, int64_t Offset,
|
||||||
MachineModuleInfo *MMI,
|
MachineModuleInfo *MMI,
|
||||||
MCStreamer &Streamer) const override;
|
MCStreamer &Streamer) const override;
|
||||||
|
|
||||||
|
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
||||||
|
Mangler &Mang, const TargetMachine &TM) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,8 +143,7 @@ public:
|
||||||
const TargetMachine &TM) const override;
|
const TargetMachine &TM) const override;
|
||||||
|
|
||||||
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
||||||
bool CannotUsePrivateLabel, Mangler &Mang,
|
Mangler &Mang, const TargetMachine &TM) const override;
|
||||||
const TargetMachine &TM) const override;
|
|
||||||
|
|
||||||
MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
|
MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
|
||||||
const TargetMachine &TM) const override;
|
const TargetMachine &TM) const override;
|
||||||
|
|
|
@ -93,8 +93,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
||||||
const GlobalValue *GV,
|
const GlobalValue *GV, Mangler &Mang,
|
||||||
bool CannotUsePrivateLabel, Mangler &Mang,
|
|
||||||
const TargetMachine &TM) const;
|
const TargetMachine &TM) const;
|
||||||
|
|
||||||
virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
|
virtual MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "llvm/IR/GlobalVariable.h"
|
#include "llvm/IR/GlobalVariable.h"
|
||||||
#include "llvm/IR/Mangler.h"
|
#include "llvm/IR/Mangler.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCSectionCOFF.h"
|
#include "llvm/MC/MCSectionCOFF.h"
|
||||||
|
@ -763,6 +764,29 @@ const MCExpr *TargetLoweringObjectFileMachO::getIndirectSymViaGOTPCRel(
|
||||||
return MCBinaryExpr::createSub(LHS, RHS, Ctx);
|
return MCBinaryExpr::createSub(LHS, RHS, Ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
|
||||||
|
const MCSection &Section) {
|
||||||
|
if (!AsmInfo.isSectionAtomizableBySymbols(Section))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// If it is not dead stripped, it is safe to use private labels.
|
||||||
|
const MCSectionMachO &SMO = cast<MCSectionMachO>(Section);
|
||||||
|
if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TargetLoweringObjectFileMachO::getNameWithPrefix(
|
||||||
|
SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const {
|
||||||
|
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
|
||||||
|
const MCSection *TheSection = SectionForGlobal(GV, GVKind, Mang, TM);
|
||||||
|
bool CannotUsePrivateLabel =
|
||||||
|
!canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
|
||||||
|
Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
|
||||||
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// COFF
|
// COFF
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -918,7 +942,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
|
||||||
COMDATSymName, Selection);
|
COMDATSymName, Selection);
|
||||||
} else {
|
} else {
|
||||||
SmallString<256> TmpData;
|
SmallString<256> TmpData;
|
||||||
getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true, Mang, TM);
|
Mang.getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true);
|
||||||
return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
|
return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
|
||||||
Selection);
|
Selection);
|
||||||
}
|
}
|
||||||
|
@ -943,8 +967,9 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetLoweringObjectFileCOFF::getNameWithPrefix(
|
void TargetLoweringObjectFileCOFF::getNameWithPrefix(
|
||||||
SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang,
|
||||||
bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const {
|
const TargetMachine &TM) const {
|
||||||
|
bool CannotUsePrivateLabel = false;
|
||||||
if (GV->hasPrivateLinkage() &&
|
if (GV->hasPrivateLinkage() &&
|
||||||
((isa<Function>(GV) && TM.getFunctionSections()) ||
|
((isa<Function>(GV) && TM.getFunctionSections()) ||
|
||||||
(isa<GlobalVariable>(GV) && TM.getDataSections())))
|
(isa<GlobalVariable>(GV) && TM.getDataSections())))
|
||||||
|
|
|
@ -344,7 +344,7 @@ const MCExpr *TargetLoweringObjectFile::getDebugThreadLocalSymbol(const MCSymbol
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetLoweringObjectFile::getNameWithPrefix(
|
void TargetLoweringObjectFile::getNameWithPrefix(
|
||||||
SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang,
|
||||||
bool CannotUsePrivateLabel, Mangler &Mang, const TargetMachine &TM) const {
|
const TargetMachine &TM) const {
|
||||||
Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
|
Mang.getNameWithPrefix(OutName, GV, /*CannotUsePrivateLabel=*/false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,19 +155,6 @@ TargetIRAnalysis TargetMachine::getTargetIRAnalysis() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
|
|
||||||
const MCSection &Section) {
|
|
||||||
if (!AsmInfo.isSectionAtomizableBySymbols(Section))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If it is not dead stripped, it is safe to use private labels.
|
|
||||||
const MCSectionMachO &SMO = cast<MCSectionMachO>(Section);
|
|
||||||
if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
|
void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
|
||||||
const GlobalValue *GV, Mangler &Mang,
|
const GlobalValue *GV, Mangler &Mang,
|
||||||
bool MayAlwaysUsePrivate) const {
|
bool MayAlwaysUsePrivate) const {
|
||||||
|
@ -177,11 +164,8 @@ void TargetMachine::getNameWithPrefix(SmallVectorImpl<char> &Name,
|
||||||
Mang.getNameWithPrefix(Name, GV, false);
|
Mang.getNameWithPrefix(Name, GV, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, *this);
|
|
||||||
const TargetLoweringObjectFile *TLOF = getObjFileLowering();
|
const TargetLoweringObjectFile *TLOF = getObjFileLowering();
|
||||||
const MCSection *TheSection = TLOF->SectionForGlobal(GV, GVKind, Mang, *this);
|
TLOF->getNameWithPrefix(Name, GV, Mang, *this);
|
||||||
bool CannotUsePrivateLabel = !canUsePrivateLabel(*AsmInfo, *TheSection);
|
|
||||||
TLOF->getNameWithPrefix(Name, GV, CannotUsePrivateLabel, Mang, *this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV, Mangler &Mang) const {
|
MCSymbol *TargetMachine::getSymbol(const GlobalValue *GV, Mangler &Mang) const {
|
||||||
|
|
Loading…
Reference in New Issue