+void Mangler::InsertName(GlobalValue *GV,
+ std::map<std::string, GlobalValue*> &Names) {
+ if (!GV->hasName()) { // We must mangle unnamed globals.
+ MangledGlobals.insert(GV);
+ return;
+ }
+
+ // Figure out if this is already used.
+ GlobalValue *&ExistingValue = Names[GV->getName()];
+ if (!ExistingValue) {
+ ExistingValue = GV;
+ } else {
+ // If GV is external but the existing one is static, mangle the existing one
+ if (GV->hasExternalLinkage() && !ExistingValue->hasExternalLinkage()) {
+ MangledGlobals.insert(ExistingValue);
+ ExistingValue = GV;
+ } else {
+ // Otherwise, mangle GV
+ MangledGlobals.insert(GV);
+ }
+ }
+}
+
+
+Mangler::Mangler(Module &m, const char *prefix)
+ : M(m), Prefix(prefix), TypeCounter(0), Count(0) {