Fix some memory leaks and avoid looking in the hash tables twice.

libxul links in 7m0.403s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126085 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2011-02-20 16:27:25 +00:00
parent 89d31ec7d2
commit cd6c93ec48
2 changed files with 53 additions and 35 deletions

View File

@@ -357,7 +357,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
mangler.getNameWithPrefix(Buffer, f, false); mangler.getNameWithPrefix(Buffer, f, false);
if (!f->isDeclaration() && if (!f->isDeclaration() &&
_mustPreserveSymbols.count(Buffer)) _mustPreserveSymbols.count(Buffer))
mustPreserveList.push_back(::strdup(f->getNameStr().c_str())); mustPreserveList.push_back(f->getName().data());
} }
for (Module::global_iterator v = mergedModule->global_begin(), for (Module::global_iterator v = mergedModule->global_begin(),
e = mergedModule->global_end(); v != e; ++v) { e = mergedModule->global_end(); v != e; ++v) {
@@ -365,7 +365,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
mangler.getNameWithPrefix(Buffer, v, false); mangler.getNameWithPrefix(Buffer, v, false);
if (!v->isDeclaration() && if (!v->isDeclaration() &&
_mustPreserveSymbols.count(Buffer)) _mustPreserveSymbols.count(Buffer))
mustPreserveList.push_back(::strdup(v->getNameStr().c_str())); mustPreserveList.push_back(v->getName().data());
} }
for (Module::alias_iterator a = mergedModule->alias_begin(), for (Module::alias_iterator a = mergedModule->alias_begin(),
e = mergedModule->alias_end(); a != e; ++a) { e = mergedModule->alias_end(); a != e; ++a) {
@@ -373,7 +373,7 @@ void LTOCodeGenerator::applyScopeRestrictions() {
mangler.getNameWithPrefix(Buffer, a, false); mangler.getNameWithPrefix(Buffer, a, false);
if (!a->isDeclaration() && if (!a->isDeclaration() &&
_mustPreserveSymbols.count(Buffer)) _mustPreserveSymbols.count(Buffer))
mustPreserveList.push_back(::strdup(a->getNameStr().c_str())); mustPreserveList.push_back(a->getName().data());
} }
passes.add(createInternalizePass(mustPreserveList)); passes.add(createInternalizePass(mustPreserveList));
} }
@@ -441,6 +441,7 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out,
codeGenPasses->run(*it); codeGenPasses->run(*it);
codeGenPasses->doFinalization(); codeGenPasses->doFinalization();
delete codeGenPasses;
return false; // success return false; // success
} }

View File

@@ -195,26 +195,28 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) {
std::string superclassName; std::string superclassName;
if (objcClassNameFromExpression(c->getOperand(1), superclassName)) { if (objcClassNameFromExpression(c->getOperand(1), superclassName)) {
NameAndAttributes info; NameAndAttributes info;
if (_undefines.find(superclassName.c_str()) == _undefines.end()) { StringMap<NameAndAttributes>::value_type &entry =
const char *symbolName = ::strdup(superclassName.c_str()); _undefines.GetOrCreateValue(superclassName.c_str());
if (!entry.getValue().name) {
const char *symbolName = entry.getKey().data();
info.name = symbolName; info.name = symbolName;
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
// string is owned by _undefines entry.setValue(info);
_undefines[info.name] = info;
} }
} }
// third slot in __OBJC,__class is pointer to class name // third slot in __OBJC,__class is pointer to class name
std::string className; std::string className;
if (objcClassNameFromExpression(c->getOperand(2), className)) { if (objcClassNameFromExpression(c->getOperand(2), className)) {
const char *symbolName = ::strdup(className.c_str()); StringSet::value_type &entry =
_defines.GetOrCreateValue(className.c_str());
entry.setValue(1);
NameAndAttributes info; NameAndAttributes info;
info.name = symbolName; info.name = entry.getKey().data();
info.attributes = (lto_symbol_attributes) info.attributes = (lto_symbol_attributes)
(LTO_SYMBOL_PERMISSIONS_DATA | (LTO_SYMBOL_PERMISSIONS_DATA |
LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_DEFINITION_REGULAR |
LTO_SYMBOL_SCOPE_DEFAULT); LTO_SYMBOL_SCOPE_DEFAULT);
_symbols.push_back(info); _symbols.push_back(info);
_defines[info.name] = 1;
} }
} }
} }
@@ -227,13 +229,17 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) {
std::string targetclassName; std::string targetclassName;
if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) { if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) {
NameAndAttributes info; NameAndAttributes info;
if (_undefines.find(targetclassName.c_str()) == _undefines.end()) {
const char *symbolName = ::strdup(targetclassName.c_str()); StringMap<NameAndAttributes>::value_type &entry =
info.name = symbolName; _undefines.GetOrCreateValue(targetclassName.c_str());
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
// string is owned by _undefines if (entry.getValue().name)
_undefines[info.name] = info; return;
}
const char *symbolName = entry.getKey().data();
info.name = symbolName;
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
entry.setValue(info);
} }
} }
} }
@@ -244,13 +250,16 @@ void LTOModule::addObjCClassRef(GlobalVariable *clgv) {
std::string targetclassName; std::string targetclassName;
if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) { if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) {
NameAndAttributes info; NameAndAttributes info;
if (_undefines.find(targetclassName.c_str()) == _undefines.end()) {
const char *symbolName = ::strdup(targetclassName.c_str()); StringMap<NameAndAttributes>::value_type &entry =
info.name = symbolName; _undefines.GetOrCreateValue(targetclassName.c_str());
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; if (entry.getValue().name)
// string is owned by _undefines return;
_undefines[info.name] = info;
} const char *symbolName = entry.getKey().data();
info.name = symbolName;
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
entry.setValue(info);
} }
} }
@@ -322,7 +331,6 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
// string is owned by _defines // string is owned by _defines
SmallString<64> Buffer; SmallString<64> Buffer;
mangler.getNameWithPrefix(Buffer, def, false); mangler.getNameWithPrefix(Buffer, def, false);
const char *symbolName = ::strdup(Buffer.c_str());
// set alignment part log2() can have rounding errors // set alignment part log2() can have rounding errors
uint32_t align = def->getAlignment(); uint32_t align = def->getAlignment();
@@ -365,26 +373,31 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler,
// add to table of symbols // add to table of symbols
NameAndAttributes info; NameAndAttributes info;
info.name = symbolName; StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer.c_str());
entry.setValue(1);
StringRef Name = entry.getKey();
info.name = Name.data();
assert(info.name[Name.size()] == '\0');
info.attributes = (lto_symbol_attributes)attr; info.attributes = (lto_symbol_attributes)attr;
_symbols.push_back(info); _symbols.push_back(info);
_defines[info.name] = 1;
} }
void LTOModule::addAsmGlobalSymbol(const char *name) { void LTOModule::addAsmGlobalSymbol(const char *name) {
StringSet::value_type &entry = _defines.GetOrCreateValue(name);
// only add new define if not already defined // only add new define if not already defined
if (_defines.count(name)) if (entry.getValue())
return; return;
// string is owned by _defines entry.setValue(1);
const char *symbolName = ::strdup(name); const char *symbolName = entry.getKey().data();
uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR; uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR;
attr |= LTO_SYMBOL_SCOPE_DEFAULT; attr |= LTO_SYMBOL_SCOPE_DEFAULT;
NameAndAttributes info; NameAndAttributes info;
info.name = symbolName; info.name = symbolName;
info.attributes = (lto_symbol_attributes)attr; info.attributes = (lto_symbol_attributes)attr;
_symbols.push_back(info); _symbols.push_back(info);
_defines[info.name] = 1;
} }
void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
@@ -400,18 +413,22 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl,
SmallString<64> name; SmallString<64> name;
mangler.getNameWithPrefix(name, decl, false); mangler.getNameWithPrefix(name, decl, false);
StringMap<NameAndAttributes>::value_type &entry =
_undefines.GetOrCreateValue(name.c_str());
// we already have the symbol // we already have the symbol
if (_undefines.find(name) != _undefines.end()) if (entry.getValue().name)
return; return;
NameAndAttributes info; NameAndAttributes info;
// string is owned by _undefines
info.name = ::strdup(name.c_str()); info.name = entry.getKey().data();
if (decl->hasExternalWeakLinkage()) if (decl->hasExternalWeakLinkage())
info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF; info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
else else
info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED;
_undefines[name] = info;
entry.setValue(info);
} }