- // Check to see whether we've already named V.
- ValueMap::iterator VI = Memo.find(V);
- if (VI != Memo.end()) {
- return VI->second; // Return the old name for V.
- }
-
- std::string name;
- if (V->hasName()) { // Print out the label if it exists...
- // Name mangling occurs as follows:
- // - If V is an intrinsic function, do not change name at all
- // - If V is not a global, mangling always occurs.
- // - Otherwise, mangling occurs when any of the following are true:
- // 1) V has internal linkage
- // 2) V's name would collide if it is not mangled.
- //
- const GlobalValue* gv = dyn_cast<GlobalValue>(V);
- if (gv && isa<Function>(gv) && cast<Function>(gv)->getIntrinsicID()) {
- name = gv->getName(); // Is an intrinsic function
- } else if (gv && !gv->hasInternalLinkage() && !MangledGlobals.count(gv)) {
- name = makeNameProper(gv->getName(), Prefix);
- } else {
- // Non-global, or global with internal linkage / colliding name
- // -> mangle.
- unsigned TypeUniqueID = getTypeID(V->getType());
- name = "l" + utostr(TypeUniqueID) + "_" + makeNameProper(V->getName());
- }
- } else {
- name = "ltmp_" + utostr(Count++) + "_" + utostr(getTypeID(V->getType()));
- }
-
- Memo[V] = name;
- return name;
+ if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
+ return getValueName(GV);
+
+ std::string &Name = Memo[V];
+ if (!Name.empty())
+ return Name; // Return the already-computed name for V.
+
+ // Always mangle local names.
+ Name = "ltmp_" + utostr(Count++) + "_" + utostr(getTypeID(V->getType()));
+ return Name;