1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

rename Memo/Count to AnonGlobalIDs/NextAnonGlobalID to be more

descriptive.  Thange them to keep track of the ID of a global that is
assigned, not the first mangled name returned for it.  Without doing this,
we are required to always use the same suffix for a global that gets 
mangled.  This means that we can mangle the same global once with $stub
and another time with $non_lazy_ptr or whatever.

llvm-svn: 75561
This commit is contained in:
Chris Lattner 2009-07-14 00:01:06 +00:00
parent 1404d6e7d1
commit 6460e403a7
2 changed files with 23 additions and 24 deletions

View File

@ -42,13 +42,15 @@ class Mangler {
/// from names with 'asm' specifiers. /// from names with 'asm' specifiers.
bool PreserveAsmNames; bool PreserveAsmNames;
/// Memo - This is used to remember the name that we assign a value. /// AnonGlobalIDs - We need to give global values the same name every time
/// they are mangled. This keeps track of the number we give to anonymous
/// ones.
/// ///
DenseMap<const Value*, std::string> Memo; DenseMap<const GlobalValue*, unsigned> AnonGlobalIDs;
/// Count - This simple counter is used to unique value names. /// NextAnonGlobalID - This simple counter is used to unique value names.
/// ///
unsigned Count; unsigned NextAnonGlobalID;
/// AcceptableChars - This bitfield contains a one for each character that is /// AcceptableChars - This bitfield contains a one for each character that is
/// allowed to be part of an unmangled name. /// allowed to be part of an unmangled name.

View File

@ -129,32 +129,29 @@ std::string Mangler::makeNameProper(const std::string &X, const char *Prefix,
} }
std::string Mangler::getValueName(const GlobalValue *GV, const char *Suffix) { std::string Mangler::getValueName(const GlobalValue *GV, const char *Suffix) {
// Check to see whether we've already named V. // Never mangle intrinsic functions.
std::string &Name = Memo[GV]; // FIXME: These should never come into the mangler.
if (!Name.empty()) if (isa<Function>(GV) && cast<Function>(GV)->isIntrinsic())
return Name; // Return the already-computed name for V. return GV->getNameStart();
// Name mangling occurs as follows: if (GV->hasName()) {
// - If V is an intrinsic function, do not change name at all
// - Otherwise, mangling occurs if global collides with existing name.
if (isa<Function>(GV) && cast<Function>(GV)->isIntrinsic()) {
Name = GV->getNameStart(); // Is an intrinsic function
} else if (!GV->hasName()) {
// Must mangle the global into a unique ID.
Name = "__unnamed_" + utostr(Count++) + Suffix;
} else {
if (GV->hasPrivateLinkage()) if (GV->hasPrivateLinkage())
Name = makeNameProper(GV->getName() + Suffix, Prefix, PrivatePrefix); return makeNameProper(GV->getName() + Suffix, Prefix, PrivatePrefix);
else return makeNameProper(GV->getName() + Suffix, Prefix);
Name = makeNameProper(GV->getName() + Suffix, Prefix);
} }
return Name; // Get the ID for the global, assigning a new one if we haven't got one
// already.
unsigned &ID = AnonGlobalIDs[GV];
if (ID == 0) ID = NextAnonGlobalID++;
// Must mangle the global into a unique ID.
return "__unnamed_" + utostr(ID) + Suffix;
} }
Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix) Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
: Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false), : Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false),
PreserveAsmNames(false), Count(0) { PreserveAsmNames(false), NextAnonGlobalID(1) {
std::fill(AcceptableChars, array_endof(AcceptableChars), 0); std::fill(AcceptableChars, array_endof(AcceptableChars), 0);
// Letters and numbers are acceptable. // Letters and numbers are acceptable.