diff options
author | Chris Lattner <sabre@nondot.org> | 2009-07-14 00:01:06 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-07-14 00:01:06 +0000 |
commit | f00a42d245ab1e6854c8cf74ef53f0cbb599c54c (patch) | |
tree | c0c1a0d03fd20221236b5882b43f9fd3e03e20cf /lib/VMCore/Mangler.cpp | |
parent | 8be68a3a8cd70654c707b6a477a763daad123a6e (diff) | |
download | external_llvm-f00a42d245ab1e6854c8cf74ef53f0cbb599c54c.zip external_llvm-f00a42d245ab1e6854c8cf74ef53f0cbb599c54c.tar.gz external_llvm-f00a42d245ab1e6854c8cf74ef53f0cbb599c54c.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75561 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Mangler.cpp')
-rw-r--r-- | lib/VMCore/Mangler.cpp | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp index 625c9c3..6e838e3 100644 --- a/lib/VMCore/Mangler.cpp +++ b/lib/VMCore/Mangler.cpp @@ -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) { - // Check to see whether we've already named V. - std::string &Name = Memo[GV]; - if (!Name.empty()) - return Name; // Return the already-computed name for V. - - // Name mangling occurs as follows: - // - 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 { + // Never mangle intrinsic functions. + // FIXME: These should never come into the mangler. + if (isa<Function>(GV) && cast<Function>(GV)->isIntrinsic()) + return GV->getNameStart(); + + if (GV->hasName()) { if (GV->hasPrivateLinkage()) - Name = makeNameProper(GV->getName() + Suffix, Prefix, PrivatePrefix); - else - Name = makeNameProper(GV->getName() + Suffix, Prefix); + return makeNameProper(GV->getName() + Suffix, Prefix, PrivatePrefix); + return 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) : Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false), - PreserveAsmNames(false), Count(0) { + PreserveAsmNames(false), NextAnonGlobalID(1) { std::fill(AcceptableChars, array_endof(AcceptableChars), 0); // Letters and numbers are acceptable. |