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.

llvm-svn: 93300
This commit is contained in:
Chris Lattner 2010-01-13 07:01:09 +00:00
parent 3c2fad1fc6
commit 951cfb6b8b
2 changed files with 64 additions and 20 deletions

View File

@ -102,6 +102,9 @@ public:
/// 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 @@ public:
/// 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 @@ public:
/// 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

View File

@ -34,6 +34,9 @@ static void MangleLetter(SmallVectorImpl<char> &OutName, unsigned char C) {
/// 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 @@ void Mangler::makeNameProper(SmallVectorImpl<char> &OutName,
/// 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 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
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 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
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 (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));
}
// If the global has a name, just append it now.
// If this global has a name, handle it simply.
if (GV->hasName()) {
StringRef Name = GV->getName();
ManglerPrefixTy PrefixTy = Mangler::Default;
if (GV->hasPrivateLinkage() || isImplicitlyPrivate)
PrefixTy = Mangler::Private;
else if (GV->hasLinkerPrivateLinkage())
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];