[llvm] r183076 - Move getRealLinkageName to a common place and remove all the duplicates of it.
Benjamin Kramer
benny.kra at googlemail.com
Sat Jun 1 10:51:15 PDT 2013
Author: d0k
Date: Sat Jun 1 12:51:14 2013
New Revision: 183076
URL: http://llvm.org/viewvc/llvm-project?rev=183076&view=rev
Log:
Move getRealLinkageName to a common place and remove all the duplicates of it.
Also simplify code a bit while there. No functionality change.
Modified:
llvm/trunk/include/llvm/IR/GlobalValue.h
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/trunk/lib/IR/DebugInfo.cpp
llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
Modified: llvm/trunk/include/llvm/IR/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GlobalValue.h?rev=183076&r1=183075&r2=183076&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/IR/GlobalValue.h Sat Jun 1 12:51:14 2013
@@ -239,6 +239,15 @@ public:
/// create a GlobalValue) from the GlobalValue Src to this one.
virtual void copyAttributesFrom(const GlobalValue *Src);
+ /// getRealLinkageName - If special LLVM prefix that is used to inform the asm
+ /// printer to not emit usual symbol prefix before the symbol name is used
+ /// then return linkage name after skipping this special LLVM prefix.
+ static StringRef getRealLinkageName(StringRef Name) {
+ if (!Name.empty() && Name[0] == '\1')
+ return Name.substr(1);
+ return Name;
+ }
+
/// @name Materialization
/// Materialization is used to construct functions only as they're needed. This
/// is useful to reduce memory usage in LLVM or parsing work done by the
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=183076&r1=183075&r2=183076&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Sat Jun 1 12:51:14 2013
@@ -1133,16 +1133,6 @@ DIE *CompileUnit::getOrCreateNameSpace(D
return NDie;
}
-/// getRealLinkageName - If special LLVM prefix that is used to inform the asm
-/// printer to not emit usual symbol prefix before the symbol name is used then
-/// return linkage name after skipping this special LLVM prefix.
-static StringRef getRealLinkageName(StringRef LinkageName) {
- char One = '\1';
- if (LinkageName.startswith(StringRef(&One, 1)))
- return LinkageName.substr(1);
- return LinkageName;
-}
-
/// getOrCreateSubprogramDIE - Create new DIE using SP.
DIE *CompileUnit::getOrCreateSubprogramDIE(DISubprogram SP) {
DIE *SPDie = getDIE(SP);
@@ -1175,7 +1165,7 @@ DIE *CompileUnit::getOrCreateSubprogramD
StringRef LinkageName = SP.getLinkageName();
if (!LinkageName.empty() && DD->useDarwinGDBCompat())
addString(SPDie, dwarf::DW_AT_MIPS_linkage_name,
- getRealLinkageName(LinkageName));
+ GlobalValue::getRealLinkageName(LinkageName));
// If this DIE is going to refer declaration info using AT_specification
// then there is no need to add other attributes.
@@ -1190,7 +1180,7 @@ DIE *CompileUnit::getOrCreateSubprogramD
// Add the linkage name if we have one.
if (!LinkageName.empty() && !DD->useDarwinGDBCompat())
addString(SPDie, dwarf::DW_AT_MIPS_linkage_name,
- getRealLinkageName(LinkageName));
+ GlobalValue::getRealLinkageName(LinkageName));
// Constructors and operators for anonymous aggregates do not have names.
if (!SP.getName().empty())
@@ -1367,12 +1357,12 @@ void CompileUnit::createGlobalVariableDI
// TAG_variable.
addString(IsStaticMember && VariableSpecDIE ?
VariableSpecDIE : VariableDIE, dwarf::DW_AT_MIPS_linkage_name,
- getRealLinkageName(LinkageName));
+ GlobalValue::getRealLinkageName(LinkageName));
// In compatibility mode with older gdbs we put the linkage name on both
// the TAG_variable DIE and on the TAG_member DIE.
if (IsStaticMember && VariableSpecDIE && DD->useDarwinGDBCompat())
addString(VariableDIE, dwarf::DW_AT_MIPS_linkage_name,
- getRealLinkageName(LinkageName));
+ GlobalValue::getRealLinkageName(LinkageName));
}
} else if (const ConstantInt *CI =
dyn_cast_or_null<ConstantInt>(GV.getConstant())) {
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=183076&r1=183075&r2=183076&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Sat Jun 1 12:51:14 2013
@@ -279,16 +279,6 @@ void DwarfUnits::assignAbbrevNumber(DIEA
}
}
-// If special LLVM prefix that is used to inform the asm
-// printer to not emit usual symbol prefix before the symbol name is used then
-// return linkage name after skipping this special LLVM prefix.
-static StringRef getRealLinkageName(StringRef LinkageName) {
- char One = '\1';
- if (LinkageName.startswith(StringRef(&One, 1)))
- return LinkageName.substr(1);
- return LinkageName;
-}
-
static bool isObjCClass(StringRef Name) {
return Name.startswith("+") || Name.startswith("-");
}
@@ -2564,9 +2554,9 @@ void DwarfDebug::emitDebugInlineInfo() {
Asm->EmitSectionOffset(InfoHolder.getStringPoolEntry(Name),
DwarfStrSectionSym);
else
- Asm->EmitSectionOffset(InfoHolder
- .getStringPoolEntry(getRealLinkageName(LName)),
- DwarfStrSectionSym);
+ Asm->EmitSectionOffset(
+ InfoHolder.getStringPoolEntry(Function::getRealLinkageName(LName)),
+ DwarfStrSectionSym);
Asm->OutStreamer.AddComment("Function name");
Asm->EmitSectionOffset(InfoHolder.getStringPoolEntry(Name),
Modified: llvm/trunk/lib/IR/DebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=183076&r1=183075&r2=183076&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfo.cpp Sat Jun 1 12:51:14 2013
@@ -764,12 +764,20 @@ DIArray DICompileUnit::getImportedEntiti
return DIArray();
}
-/// fixupObjcLikeName - Replace contains special characters used
+/// fixupSubprogramName - Replace contains special characters used
/// in a typical Objective-C names with '.' in a given string.
-static void fixupObjcLikeName(StringRef Str, SmallVectorImpl<char> &Out) {
+static void fixupSubprogramName(DISubprogram Fn, SmallVectorImpl<char> &Out) {
+ StringRef FName =
+ Fn.getFunction() ? Fn.getFunction()->getName() : Fn.getName();
+ FName = Function::getRealLinkageName(FName);
+
+ StringRef Prefix("llvm.dbg.lv.");
+ Out.reserve(FName.size() + Prefix.size());
+ Out.append(Prefix.begin(), Prefix.end());
+
bool isObjCLike = false;
- for (size_t i = 0, e = Str.size(); i < e; ++i) {
- char C = Str[i];
+ for (size_t i = 0, e = FName.size(); i < e; ++i) {
+ char C = FName[i];
if (C == '[')
isObjCLike = true;
@@ -784,33 +792,16 @@ static void fixupObjcLikeName(StringRef
/// getFnSpecificMDNode - Return a NameMDNode, if available, that is
/// suitable to hold function specific information.
NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, DISubprogram Fn) {
- SmallString<32> Name = StringRef("llvm.dbg.lv.");
- StringRef FName = "fn";
- if (Fn.getFunction())
- FName = Fn.getFunction()->getName();
- else
- FName = Fn.getName();
- char One = '\1';
- if (FName.startswith(StringRef(&One, 1)))
- FName = FName.substr(1);
- fixupObjcLikeName(FName, Name);
+ SmallString<32> Name;
+ fixupSubprogramName(Fn, Name);
return M.getNamedMetadata(Name.str());
}
/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
/// to hold function specific information.
NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) {
- SmallString<32> Name = StringRef("llvm.dbg.lv.");
- StringRef FName = "fn";
- if (Fn.getFunction())
- FName = Fn.getFunction()->getName();
- else
- FName = Fn.getName();
- char One = '\1';
- if (FName.startswith(StringRef(&One, 1)))
- FName = FName.substr(1);
- fixupObjcLikeName(FName, Name);
-
+ SmallString<32> Name;
+ fixupSubprogramName(Fn, Name);
return M.getOrInsertNamedMetadata(Name.str());
}
Modified: llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp?rev=183076&r1=183075&r2=183076&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Sat Jun 1 12:51:14 2013
@@ -332,16 +332,6 @@ bool StripDebugDeclare::runOnModule(Modu
return true;
}
-/// getRealLinkageName - If special LLVM prefix that is used to inform the asm
-/// printer to not emit usual symbol prefix before the symbol name is used then
-/// return linkage name after skipping this special LLVM prefix.
-static StringRef getRealLinkageName(StringRef LinkageName) {
- char One = '\1';
- if (LinkageName.startswith(StringRef(&One, 1)))
- return LinkageName.substr(1);
- return LinkageName;
-}
-
bool StripDeadDebugInfo::runOnModule(Module &M) {
bool Changed = false;
@@ -401,9 +391,8 @@ bool StripDeadDebugInfo::runOnModule(Mod
StringRef FName = DISubprogram(*I).getLinkageName();
if (FName.empty())
FName = DISubprogram(*I).getName();
- if (NamedMDNode *LVNMD =
- M.getNamedMetadata(Twine("llvm.dbg.lv.",
- getRealLinkageName(FName))))
+ if (NamedMDNode *LVNMD = M.getNamedMetadata(
+ "llvm.dbg.lv." + Function::getRealLinkageName(FName)))
LVNMD->eraseFromParent();
}
}
More information about the llvm-commits
mailing list