forked from OSchip/llvm-project
Reduce heap trashing due to std::string construction / concatenation via caching of section flags string representations
llvm-svn: 54842
This commit is contained in:
parent
f1ac2dc883
commit
44b4a9a05d
|
@ -27,7 +27,7 @@ namespace llvm {
|
||||||
explicit ELFTargetAsmInfo(const TargetMachine &TM);
|
explicit ELFTargetAsmInfo(const TargetMachine &TM);
|
||||||
|
|
||||||
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
|
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
|
||||||
virtual std::string PrintSectionFlags(unsigned flags) const;
|
virtual std::string printSectionFlags(unsigned flags) const;
|
||||||
const Section* MergeableConstSection(const GlobalVariable *GV) const;
|
const Section* MergeableConstSection(const GlobalVariable *GV) const;
|
||||||
inline const Section* MergeableConstSection(const Type *Ty) const;
|
inline const Section* MergeableConstSection(const Type *Ty) const;
|
||||||
const Section* MergeableStringSection(const GlobalVariable *GV) const;
|
const Section* MergeableStringSection(const GlobalVariable *GV) const;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#ifndef LLVM_TARGET_ASM_INFO_H
|
#ifndef LLVM_TARGET_ASM_INFO_H
|
||||||
#define LLVM_TARGET_ASM_INFO_H
|
#define LLVM_TARGET_ASM_INFO_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -83,6 +84,16 @@ namespace llvm {
|
||||||
static inline unsigned setEntitySize(unsigned Flags, unsigned Size) {
|
static inline unsigned setEntitySize(unsigned Flags, unsigned Size) {
|
||||||
return ((Flags & ~EntitySize) | ((Size & 0xFF) << 24));
|
return ((Flags & ~EntitySize) | ((Size & 0xFF) << 24));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct KeyInfo {
|
||||||
|
static inline unsigned getEmptyKey() { return Invalid; }
|
||||||
|
static inline unsigned getTombstoneKey() { return Invalid - 1; }
|
||||||
|
static unsigned getHashValue(const unsigned &Key) { return Key; }
|
||||||
|
static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
|
||||||
|
static bool isPod() { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef DenseMap<unsigned, std::string, KeyInfo> FlagsStringsMapType;
|
||||||
}
|
}
|
||||||
|
|
||||||
class TargetMachine;
|
class TargetMachine;
|
||||||
|
@ -109,6 +120,7 @@ namespace llvm {
|
||||||
class TargetAsmInfo {
|
class TargetAsmInfo {
|
||||||
private:
|
private:
|
||||||
mutable StringMap<Section> Sections;
|
mutable StringMap<Section> Sections;
|
||||||
|
mutable SectionFlags::FlagsStringsMapType FlagsStrings;
|
||||||
protected:
|
protected:
|
||||||
//===------------------------------------------------------------------===//
|
//===------------------------------------------------------------------===//
|
||||||
// Properties to be set by the target writer, used to configure asm printer.
|
// Properties to be set by the target writer, used to configure asm printer.
|
||||||
|
@ -551,7 +563,8 @@ namespace llvm {
|
||||||
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
|
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
|
||||||
SectionKind::Kind kind) const;
|
SectionKind::Kind kind) const;
|
||||||
|
|
||||||
virtual std::string PrintSectionFlags(unsigned flags) const { return ""; }
|
const std::string& getSectionFlags(unsigned Flags) const;
|
||||||
|
virtual std::string printSectionFlags(unsigned flags) const { return ""; }
|
||||||
|
|
||||||
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
|
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV) const;
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
|
||||||
return getReadOnlySection_();
|
return getReadOnlySection_();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
|
std::string ELFTargetAsmInfo::printSectionFlags(unsigned flags) const {
|
||||||
std::string Flags = ",\"";
|
std::string Flags = ",\"";
|
||||||
|
|
||||||
if (!(flags & SectionFlags::Debug))
|
if (!(flags & SectionFlags::Debug))
|
||||||
|
|
|
@ -27,9 +27,9 @@ SparcELFTargetAsmInfo::SparcELFTargetAsmInfo(const TargetMachine &TM):
|
||||||
CStringSection=".rodata.str";
|
CStringSection=".rodata.str";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string SparcELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
|
std::string SparcELFTargetAsmInfo::printSectionFlags(unsigned flags) const {
|
||||||
if (flags & SectionFlags::Mergeable)
|
if (flags & SectionFlags::Mergeable)
|
||||||
return ELFTargetAsmInfo::PrintSectionFlags(flags);
|
return ELFTargetAsmInfo::printSectionFlags(flags);
|
||||||
|
|
||||||
std::string Flags;
|
std::string Flags;
|
||||||
if (!(flags & SectionFlags::Debug))
|
if (!(flags & SectionFlags::Debug))
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace llvm {
|
||||||
struct SparcELFTargetAsmInfo : public ELFTargetAsmInfo {
|
struct SparcELFTargetAsmInfo : public ELFTargetAsmInfo {
|
||||||
explicit SparcELFTargetAsmInfo(const TargetMachine &TM);
|
explicit SparcELFTargetAsmInfo(const TargetMachine &TM);
|
||||||
|
|
||||||
std::string PrintSectionFlags(unsigned flags) const;
|
std::string printSectionFlags(unsigned flags) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace llvm
|
} // namespace llvm
|
||||||
|
|
|
@ -291,7 +291,7 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
|
||||||
// If section is named we need to switch into it via special '.section'
|
// If section is named we need to switch into it via special '.section'
|
||||||
// directive and also append funky flags. Otherwise - section name is just
|
// directive and also append funky flags. Otherwise - section name is just
|
||||||
// some magic assembler directive.
|
// some magic assembler directive.
|
||||||
return getSwitchToSectionDirective() + S->Name + PrintSectionFlags(S->Flags);
|
return getSwitchToSectionDirective() + S->Name + getSectionFlags(S->Flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lame default implementation. Calculate the section name for global.
|
// Lame default implementation. Calculate the section name for global.
|
||||||
|
@ -376,3 +376,16 @@ TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags) const {
|
||||||
|
|
||||||
return &S;
|
return &S;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string&
|
||||||
|
TargetAsmInfo::getSectionFlags(unsigned Flags) const {
|
||||||
|
SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
|
||||||
|
|
||||||
|
// We didn't print these flags yet, print and save them to map. This reduces
|
||||||
|
// amount of heap trashing due to std::string construction / concatenation.
|
||||||
|
if (I == FlagsStrings.end())
|
||||||
|
I = FlagsStrings.insert(std::make_pair(Flags,
|
||||||
|
printSectionFlags(Flags))).first;
|
||||||
|
|
||||||
|
return I->second;
|
||||||
|
}
|
||||||
|
|
|
@ -404,7 +404,7 @@ X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
|
std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
|
||||||
std::string Flags = ",\"";
|
std::string Flags = ",\"";
|
||||||
|
|
||||||
if (flags & SectionFlags::Code)
|
if (flags & SectionFlags::Code)
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace llvm {
|
||||||
bool Global) const;
|
bool Global) const;
|
||||||
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
|
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
|
||||||
SectionKind::Kind kind) const;
|
SectionKind::Kind kind) const;
|
||||||
virtual std::string PrintSectionFlags(unsigned flags) const;
|
virtual std::string printSectionFlags(unsigned flags) const;
|
||||||
protected:
|
protected:
|
||||||
const X86TargetMachine *X86TM;
|
const X86TargetMachine *X86TM;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue