[llvm-commits] [llvm] r93300 - in /llvm/trunk: include/llvm/Support/Mangler.h lib/VMCore/Mangler.cpp
Chris Lattner
sabre at nondot.org
Tue Jan 12 23:01:09 PST 2010
Author: lattner
Date: Wed Jan 13 01:01:09 2010
New Revision: 93300
URL: http://llvm.org/viewvc/llvm-project?rev=93300&view=rev
Log:
ugh, my last patch just sped up a method and changed all the clients
that I want to completely eliminate. Add fixme's so I remember this
in the future, and add the missing helper that they should be upgraded
to use instead.
Modified:
llvm/trunk/include/llvm/Support/Mangler.h
llvm/trunk/lib/VMCore/Mangler.cpp
Modified: llvm/trunk/include/llvm/Support/Mangler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Mangler.h?rev=93300&r1=93299&r2=93300&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Mangler.h (original)
+++ llvm/trunk/include/llvm/Support/Mangler.h Wed Jan 13 01:01:09 2010
@@ -102,6 +102,9 @@
/// specified suffix. If 'ForcePrivate' is specified, the label is specified
/// to have a private label prefix.
///
+ /// FIXME: This is deprecated, new code should use getNameWithPrefix and use
+ /// MCSymbol printing to handle quotes or not etc.
+ ///
std::string getMangledName(const GlobalValue *V, const char *Suffix = "",
bool ForcePrivate = false);
@@ -112,6 +115,9 @@
/// does this for you, so there's no point calling it on the result
/// from getValueName.
///
+ /// FIXME: This is deprecated, new code should use getNameWithPrefix and use
+ /// MCSymbol printing to handle quotes or not etc.
+ ///
void makeNameProper(SmallVectorImpl<char> &OutName,
const Twine &Name,
ManglerPrefixTy PrefixTy = Mangler::Default);
@@ -121,6 +127,12 @@
/// have a name, this fills in a unique name for the global.
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
bool isImplicitlyPrivate);
+
+ /// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
+ /// and the specified name as the global variable name. GVName must not be
+ /// empty.
+ void getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName,
+ ManglerPrefixTy PrefixTy = Mangler::Default);
};
} // End llvm namespace
Modified: llvm/trunk/lib/VMCore/Mangler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Mangler.cpp?rev=93300&r1=93299&r2=93300&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Mangler.cpp (original)
+++ llvm/trunk/lib/VMCore/Mangler.cpp Wed Jan 13 01:01:09 2010
@@ -34,6 +34,9 @@
/// makeNameProper - We don't want identifier names non-C-identifier characters
/// in them, so mangle them as appropriate.
///
+/// FIXME: This is deprecated, new code should use getNameWithPrefix and use
+/// MCSymbol printing to handle quotes or not etc.
+///
void Mangler::makeNameProper(SmallVectorImpl<char> &OutName,
const Twine &TheName,
ManglerPrefixTy PrefixTy) {
@@ -151,6 +154,9 @@
/// specified suffix. If 'ForcePrivate' is specified, the label is specified
/// to have a private label prefix.
///
+/// FIXME: This is deprecated, new code should use getNameWithPrefix and use
+/// MCSymbol printing to handle quotes or not etc.
+///
std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
bool ForcePrivate) {
assert((!isa<Function>(GV) || !cast<Function>(GV)->isIntrinsic()) &&
@@ -176,6 +182,37 @@
return Result.str().str();
}
+/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
+/// and the specified name as the global variable name. GVName must not be
+/// empty.
+void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
+ const Twine &GVName, ManglerPrefixTy PrefixTy) {
+ SmallString<256> TmpData;
+ GVName.toVector(TmpData);
+ StringRef Name = TmpData.str();
+ assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
+
+ // If the global name is not led with \1, add the appropriate prefixes.
+ if (Name[0] != '\1') {
+ if (PrefixTy == Mangler::Private)
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ else if (PrefixTy == Mangler::LinkerPrivate)
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));
+
+ if (Prefix[0] == 0)
+ ; // Common noop, no prefix.
+ else if (Prefix[1] == 0)
+ OutName.push_back(Prefix[0]); // Common, one character prefix.
+ else
+ OutName.append(Prefix, Prefix+strlen(Prefix)); // Arbitrary prefix.
+ } else {
+ Name = Name.substr(1);
+ }
+
+ OutName.append(Name.begin(), Name.end());
+}
+
/// getNameWithPrefix - Fill OutName with the name of the appropriate prefix
/// and the specified global variable's name. If the global variable doesn't
@@ -183,33 +220,28 @@
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
const GlobalValue *GV,
bool isImplicitlyPrivate) {
-
- // If the global is anonymous or not led with \1, then add the appropriate
- // prefix.
- if (!GV->hasName() || GV->getName()[0] != '\1') {
+ // If this global has a name, handle it simply.
+ if (GV->hasName()) {
+ ManglerPrefixTy PrefixTy = Mangler::Default;
if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
- OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ PrefixTy = Mangler::Private;
else if (GV->hasLinkerPrivateLinkage())
- OutName.append(LinkerPrivatePrefix,
- LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));;
- OutName.append(Prefix, Prefix+strlen(Prefix));
- }
-
- // If the global has a name, just append it now.
- if (GV->hasName()) {
- StringRef Name = GV->getName();
+ PrefixTy = Mangler::LinkerPrivate;
- // Strip off the prefix marker if present.
- if (Name[0] != '\1')
- OutName.append(Name.begin(), Name.end());
- else
- OutName.append(Name.begin()+1, Name.end());
- return;
+ return getNameWithPrefix(OutName, GV->getName(), PrefixTy);
}
// If the global variable doesn't have a name, return a unique name for the
// global based on a numbering.
+ // Anonymous names always get prefixes.
+ if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
+ OutName.append(PrivatePrefix, PrivatePrefix+strlen(PrivatePrefix));
+ else if (GV->hasLinkerPrivateLinkage())
+ OutName.append(LinkerPrivatePrefix,
+ LinkerPrivatePrefix+strlen(LinkerPrivatePrefix));;
+ OutName.append(Prefix, Prefix+strlen(Prefix));
+
// Get the ID for the global, assigning a new one if we haven't got one
// already.
unsigned &ID = AnonGlobalIDs[GV];
More information about the llvm-commits
mailing list