[llvm-commits] [llvm] r94189 - in /llvm/trunk: include/llvm/MC/MCSectionELF.h lib/MC/MCSectionELF.cpp lib/Target/TargetLoweringObjectFile.cpp
Benjamin Kramer
benny.kra at googlemail.com
Fri Jan 22 10:21:23 PST 2010
Author: d0k
Date: Fri Jan 22 12:21:23 2010
New Revision: 94189
URL: http://llvm.org/viewvc/llvm-project?rev=94189&view=rev
Log:
Simplify some uses of str(n)cmp with StringRef.
Modified:
llvm/trunk/include/llvm/MC/MCSectionELF.h
llvm/trunk/lib/MC/MCSectionELF.cpp
llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
Modified: llvm/trunk/include/llvm/MC/MCSectionELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSectionELF.h?rev=94189&r1=94188&r2=94189&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSectionELF.h (original)
+++ llvm/trunk/include/llvm/MC/MCSectionELF.h Fri Jan 22 12:21:23 2010
@@ -47,8 +47,7 @@
/// ShouldOmitSectionDirective - Decides whether a '.section' directive
/// should be printed before the section name
- bool ShouldOmitSectionDirective(const char *Name,
- const MCAsmInfo &MAI) const;
+ bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const;
/// ShouldPrintSectionType - Only prints the section type if supported
bool ShouldPrintSectionType(unsigned Ty) const;
Modified: llvm/trunk/lib/MC/MCSectionELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSectionELF.cpp?rev=94189&r1=94188&r2=94189&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSectionELF.cpp (original)
+++ llvm/trunk/lib/MC/MCSectionELF.cpp Fri Jan 22 12:21:23 2010
@@ -22,14 +22,12 @@
// ShouldOmitSectionDirective - Decides whether a '.section' directive
// should be printed before the section name
-bool MCSectionELF::ShouldOmitSectionDirective(const char *Name,
+bool MCSectionELF::ShouldOmitSectionDirective(StringRef Name,
const MCAsmInfo &MAI) const {
// FIXME: Does .section .bss/.data/.text work everywhere??
- if (strcmp(Name, ".text") == 0 ||
- strcmp(Name, ".data") == 0 ||
- (strcmp(Name, ".bss") == 0 &&
- !MAI.usesELFSectionDirectiveForBSS()))
+ if (Name == ".text" || Name == ".data" ||
+ (Name == ".bss" && !MAI.usesELFSectionDirectiveForBSS()))
return true;
return false;
@@ -46,7 +44,7 @@
void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
raw_ostream &OS) const {
- if (ShouldOmitSectionDirective(SectionName.c_str(), MAI)) {
+ if (ShouldOmitSectionDirective(SectionName, MAI)) {
OS << '\t' << getSectionName() << '\n';
return;
}
@@ -128,7 +126,7 @@
// header index.
bool MCSectionELF::HasCommonSymbols() const {
- if (strncmp(SectionName.c_str(), ".gnu.linkonce.", 14) == 0)
+ if (StringRef(SectionName).startswith(".gnu.linkonce."))
return true;
return false;
Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=94189&r1=94188&r2=94189&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Fri Jan 22 12:21:23 2010
@@ -474,30 +474,30 @@
static SectionKind
-getELFKindForNamedSection(const char *Name, SectionKind K) {
- if (Name[0] != '.') return K;
+getELFKindForNamedSection(StringRef Name, SectionKind K) {
+ if (Name.empty() || Name[0] != '.') return K;
// Some lame default implementation based on some magic section names.
- if (strcmp(Name, ".bss") == 0 ||
- strncmp(Name, ".bss.", 5) == 0 ||
- strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
- strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
- strcmp(Name, ".sbss") == 0 ||
- strncmp(Name, ".sbss.", 6) == 0 ||
- strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
- strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
+ if (Name == ".bss" ||
+ Name.startswith(".bss.") ||
+ Name.startswith(".gnu.linkonce.b.") ||
+ Name.startswith(".llvm.linkonce.b.") ||
+ Name == ".sbss" ||
+ Name.startswith(".sbss.") ||
+ Name.startswith(".gnu.linkonce.sb.") ||
+ Name.startswith(".llvm.linkonce.sb."))
return SectionKind::getBSS();
- if (strcmp(Name, ".tdata") == 0 ||
- strncmp(Name, ".tdata.", 7) == 0 ||
- strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
- strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
+ if (Name == ".tdata" ||
+ Name.startswith(".tdata.") ||
+ Name.startswith(".gnu.linkonce.td.") ||
+ Name.startswith(".llvm.linkonce.td."))
return SectionKind::getThreadData();
- if (strcmp(Name, ".tbss") == 0 ||
- strncmp(Name, ".tbss.", 6) == 0 ||
- strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
- strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
+ if (Name == ".tbss" ||
+ Name.startswith(".tbss.") ||
+ Name.startswith(".gnu.linkonce.tb.") ||
+ Name.startswith(".llvm.linkonce.tb."))
return SectionKind::getThreadBSS();
return K;
@@ -553,7 +553,7 @@
const MCSection *TargetLoweringObjectFileELF::
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
- const char *SectionName = GV->getSection().c_str();
+ StringRef SectionName = GV->getSection();
// Infer section flags from the section name if we can.
Kind = getELFKindForNamedSection(SectionName, Kind);
@@ -616,7 +616,7 @@
std::string Name = SizeSpec + utostr(Align);
- return getELFSection(Name.c_str(), MCSectionELF::SHT_PROGBITS,
+ return getELFSection(Name, MCSectionELF::SHT_PROGBITS,
MCSectionELF::SHF_ALLOC |
MCSectionELF::SHF_MERGE |
MCSectionELF::SHF_STRINGS,
@@ -1086,7 +1086,7 @@
const MCSection *TargetLoweringObjectFileCOFF::
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
- return getCOFFSection(GV->getSection().c_str(), false, Kind);
+ return getCOFFSection(GV->getSection(), false, Kind);
}
static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
More information about the llvm-commits
mailing list