diff options
author | dim <dim@FreeBSD.org> | 2011-02-26 22:03:50 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-02-26 22:03:50 +0000 |
commit | c80ac9d286b8fcc6d1ee5d76048134cf80aa9edc (patch) | |
tree | ddf53b8bd9235bcb0b8aae16c5e22310dcdad665 /tools | |
parent | cbb70ce070d220642b038ea101d9c0f9fbf860d6 (diff) | |
download | FreeBSD-src-c80ac9d286b8fcc6d1ee5d76048134cf80aa9edc.zip FreeBSD-src-c80ac9d286b8fcc6d1ee5d76048134cf80aa9edc.tar.gz |
Vendor import of llvm trunk r126547:
http://llvm.org/svn/llvm-project/llvm/trunk@126547
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bugpoint/OptimizerDriver.cpp | 3 | ||||
-rw-r--r-- | tools/gold/gold-plugin.cpp | 48 | ||||
-rw-r--r-- | tools/llvm-config/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tools/llvm-mc/Disassembler.cpp | 169 | ||||
-rw-r--r-- | tools/lto/LTOCodeGenerator.cpp | 157 | ||||
-rw-r--r-- | tools/lto/LTOCodeGenerator.h | 10 | ||||
-rw-r--r-- | tools/lto/LTOModule.cpp | 81 | ||||
-rw-r--r-- | tools/lto/lto.cpp | 4 |
8 files changed, 198 insertions, 277 deletions
diff --git a/tools/bugpoint/OptimizerDriver.cpp b/tools/bugpoint/OptimizerDriver.cpp index 2471cc1..c6be271 100644 --- a/tools/bugpoint/OptimizerDriver.cpp +++ b/tools/bugpoint/OptimizerDriver.cpp @@ -89,7 +89,8 @@ void BugDriver::EmitProgressBitcode(const Module *M, outs() << getPassesString(PassesToRun) << "\n"; } -cl::opt<bool> SilencePasses("silence-passes", cl::desc("Suppress output of running passes (both stdout and stderr)")); +cl::opt<bool> SilencePasses("silence-passes", + cl::desc("Suppress output of running passes (both stdout and stderr)")); static cl::list<std::string> OptArgs("opt-args", cl::Positional, cl::desc("<opt arguments>..."), diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index ad2774a..7ce1760 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -64,7 +64,7 @@ namespace { std::string output_name = ""; std::list<claimed_file> Modules; std::vector<sys::Path> Cleanup; - lto_code_gen_t code_gen; + lto_code_gen_t code_gen = NULL; } namespace options { @@ -73,8 +73,6 @@ namespace options { static generate_bc generate_bc_file = BC_NO; static std::string bc_path; static std::string obj_path; - static std::string as_path; - static std::vector<std::string> as_args; static std::vector<std::string> pass_through; static std::string extra_library_path; static std::string triple; @@ -96,16 +94,6 @@ namespace options { generate_api_file = true; } else if (opt.startswith("mcpu=")) { mcpu = opt.substr(strlen("mcpu=")); - } else if (opt.startswith("as=")) { - if (!as_path.empty()) { - (*message)(LDPL_WARNING, "Path to as specified twice. " - "Discarding %s", opt_); - } else { - as_path = opt.substr(strlen("as=")); - } - } else if (opt.startswith("as-arg=")) { - llvm::StringRef item = opt.substr(strlen("as-arg=")); - as_args.push_back(item.str()); } else if (opt.startswith("extra-library-path=")) { extra_library_path = opt.substr(strlen("extra_library_path=")); } else if (opt.startswith("pass-through=")) { @@ -196,6 +184,8 @@ ld_plugin_status onload(ld_plugin_tv *tv) { if ((*callback)(all_symbols_read_hook) != LDPS_OK) return LDPS_ERR; + + code_gen = lto_codegen_create(); } break; case LDPT_REGISTER_CLEANUP_HOOK: { ld_plugin_register_cleanup callback; @@ -236,8 +226,6 @@ ld_plugin_status onload(ld_plugin_tv *tv) { return LDPS_ERR; } - code_gen = lto_codegen_create(); - return LDPS_OK; } @@ -322,6 +310,7 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, cf.syms.push_back(ld_plugin_symbol()); ld_plugin_symbol &sym = cf.syms.back(); sym.name = const_cast<char *>(lto_module_get_symbol_name(M, i)); + sym.name = strdup(sym.name); sym.version = NULL; int scope = attrs & LTO_SYMBOL_SCOPE_MASK; @@ -379,7 +368,11 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, } } - lto_codegen_add_module(code_gen, M); + if (code_gen) + lto_codegen_add_module(code_gen, M); + + lto_module_dispose(M); + return LDPS_OK; } @@ -389,6 +382,8 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, /// codegen. static ld_plugin_status all_symbols_read_hook(void) { std::ofstream api_file; + assert(code_gen); + if (options::generate_api_file) { api_file.open("apifile.txt", std::ofstream::out | std::ofstream::trunc); if (!api_file.is_open()) { @@ -425,18 +420,6 @@ static ld_plugin_status all_symbols_read_hook(void) { lto_codegen_set_pic_model(code_gen, output_type); lto_codegen_set_debug_model(code_gen, LTO_DEBUG_MODEL_DWARF); - if (!options::as_path.empty()) { - sys::Path p = sys::Program::FindProgramByName(options::as_path); - lto_codegen_set_assembler_path(code_gen, p.c_str()); - } - if (!options::as_args.empty()) { - std::vector<const char *> as_args_p; - for (std::vector<std::string>::iterator I = options::as_args.begin(), - E = options::as_args.end(); I != E; ++I) { - as_args_p.push_back(I->c_str()); - } - lto_codegen_set_assembler_args(code_gen, &as_args_p[0], as_args_p.size()); - } if (!options::mcpu.empty()) lto_codegen_set_cpu(code_gen, options::mcpu.c_str()); @@ -469,10 +452,10 @@ static ld_plugin_status all_symbols_read_hook(void) { std::string ErrMsg; const char *objPath; + sys::Path uniqueObjPath("/tmp/llvmgold.o"); if (!options::obj_path.empty()) { objPath = options::obj_path.c_str(); } else { - sys::Path uniqueObjPath("/tmp/llvmgold.o"); if (uniqueObjPath.createTemporaryFileOnDisk(true, &ErrMsg)) { (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); return LDPS_ERR; @@ -497,6 +480,13 @@ static ld_plugin_status all_symbols_read_hook(void) { objFile.keep(); lto_codegen_dispose(code_gen); + for (std::list<claimed_file>::iterator I = Modules.begin(), + E = Modules.end(); I != E; ++I) { + for (unsigned i = 0; i != I->syms.size(); ++i) { + ld_plugin_symbol &sym = I->syms[i]; + free(sym.name); + } + } if ((*add_input_file)(objPath) != LDPS_OK) { (*message)(LDPL_ERROR, "Unable to add .o file to the link."); diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt index d33ff0d..b6f4289 100644 --- a/tools/llvm-config/CMakeLists.txt +++ b/tools/llvm-config/CMakeLists.txt @@ -124,8 +124,7 @@ add_custom_command(OUTPUT ${LLVM_CONFIG} add_custom_target(llvm-config.target ALL DEPENDS ${LLVM_CONFIG}) -get_property(llvm_lib_targets GLOBAL PROPERTY LLVM_LIB_TARGETS) -add_dependencies(llvm-config.target ${llvm_lib_targets}) +add_dependencies( llvm-config.target ${llvm_libs} ) # Make sure that llvm-config builds before the llvm tools, so we have # LibDeps.txt and can use it for updating the hard-coded library diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index c29d82a..d98b57e 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -227,113 +227,120 @@ int Disassembler::disassembleEnhanced(const std::string &TS, } EDDisassembler::initialize(); - EDDisassembler *disassembler = - EDDisassembler::getDisassembler(TS.c_str(), AS); + OwningPtr<EDDisassembler> + disassembler(EDDisassembler::getDisassembler(TS.c_str(), AS)); if (disassembler == 0) { errs() << "error: couldn't get disassembler for " << TS << '\n'; return -1; } - EDInst *inst = - disassembler->createInst(byteArrayReader, 0, &ByteArray); - - if (inst == 0) { - errs() << "error: Didn't get an instruction\n"; - return -1; - } + while (ByteArray.size()) { + OwningPtr<EDInst> + inst(disassembler->createInst(byteArrayReader, 0, &ByteArray)); - unsigned numTokens = inst->numTokens(); - if ((int)numTokens < 0) { - errs() << "error: couldn't count the instruction's tokens\n"; - return -1; - } - - for (unsigned tokenIndex = 0; tokenIndex != numTokens; ++tokenIndex) { - EDToken *token; - - if (inst->getToken(token, tokenIndex)) { - errs() << "error: Couldn't get token\n"; + ByteArray.erase (ByteArray.begin(), ByteArray.begin() + inst->byteSize()); + + if (inst == 0) { + errs() << "error: Didn't get an instruction\n"; return -1; } - const char *buf; - if (token->getString(buf)) { - errs() << "error: Couldn't get string for token\n"; + unsigned numTokens = inst->numTokens(); + if ((int)numTokens < 0) { + errs() << "error: couldn't count the instruction's tokens\n"; return -1; } - Out << '['; - int operandIndex = token->operandID(); - - if (operandIndex >= 0) - Out << operandIndex << "-"; - - switch (token->type()) { - default: Out << "?"; break; - case EDToken::kTokenWhitespace: Out << "w"; break; - case EDToken::kTokenPunctuation: Out << "p"; break; - case EDToken::kTokenOpcode: Out << "o"; break; - case EDToken::kTokenLiteral: Out << "l"; break; - case EDToken::kTokenRegister: Out << "r"; break; - } - - Out << ":" << buf; - - if (token->type() == EDToken::kTokenLiteral) { - Out << "="; - if (token->literalSign()) - Out << "-"; - uint64_t absoluteValue; - if (token->literalAbsoluteValue(absoluteValue)) { - errs() << "error: Couldn't get the value of a literal token\n"; + for (unsigned tokenIndex = 0; tokenIndex != numTokens; ++tokenIndex) { + EDToken *token; + + if (inst->getToken(token, tokenIndex)) { + errs() << "error: Couldn't get token\n"; return -1; } - Out << absoluteValue; - } else if (token->type() == EDToken::kTokenRegister) { - Out << "="; - unsigned regID; - if (token->registerID(regID)) { - errs() << "error: Couldn't get the ID of a register token\n"; + + const char *buf; + if (token->getString(buf)) { + errs() << "error: Couldn't get string for token\n"; return -1; } - Out << "r" << regID; + + Out << '['; + int operandIndex = token->operandID(); + + if (operandIndex >= 0) + Out << operandIndex << "-"; + + switch (token->type()) { + default: Out << "?"; break; + case EDToken::kTokenWhitespace: Out << "w"; break; + case EDToken::kTokenPunctuation: Out << "p"; break; + case EDToken::kTokenOpcode: Out << "o"; break; + case EDToken::kTokenLiteral: Out << "l"; break; + case EDToken::kTokenRegister: Out << "r"; break; + } + + Out << ":" << buf; + + if (token->type() == EDToken::kTokenLiteral) { + Out << "="; + if (token->literalSign()) + Out << "-"; + uint64_t absoluteValue; + if (token->literalAbsoluteValue(absoluteValue)) { + errs() << "error: Couldn't get the value of a literal token\n"; + return -1; + } + Out << absoluteValue; + } else if (token->type() == EDToken::kTokenRegister) { + Out << "="; + unsigned regID; + if (token->registerID(regID)) { + errs() << "error: Couldn't get the ID of a register token\n"; + return -1; + } + Out << "r" << regID; + } + + Out << "]"; } - Out << "]"; - } - - Out << " "; + Out << " "; + + if (inst->isBranch()) + Out << "<br> "; + if (inst->isMove()) + Out << "<mov> "; - if (inst->isBranch()) - Out << "<br> "; - if (inst->isMove()) - Out << "<mov> "; - - unsigned numOperands = inst->numOperands(); - - if ((int)numOperands < 0) { - errs() << "error: Couldn't count operands\n"; - return -1; - } - - for (unsigned operandIndex = 0; operandIndex != numOperands; ++operandIndex) { - Out << operandIndex << ":"; + unsigned numOperands = inst->numOperands(); - EDOperand *operand; - if (inst->getOperand(operand, operandIndex)) { - errs() << "error: couldn't get operand\n"; + if ((int)numOperands < 0) { + errs() << "error: Couldn't count operands\n"; return -1; } - uint64_t evaluatedResult; - void *Arg[] = { disassembler, &Out }; - evaluatedResult = operand->evaluate(evaluatedResult, verboseEvaluator, Arg); - Out << "=" << evaluatedResult << " "; + for (unsigned operandIndex = 0; operandIndex != numOperands; ++operandIndex) { + Out << operandIndex << ":"; + + EDOperand *operand; + if (inst->getOperand(operand, operandIndex)) { + errs() << "error: couldn't get operand\n"; + return -1; + } + + uint64_t evaluatedResult; + void *Arg[] = { disassembler.get(), &Out }; + if (operand->evaluate(evaluatedResult, verboseEvaluator, Arg)) { + errs() << "error: Couldn't evaluate an operand\n"; + return -1; + } + Out << "=" << evaluatedResult << " "; + } + + Out << '\n'; } - Out << '\n'; - return 0; } diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index adb7102..f72fdb0 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -71,10 +71,11 @@ LTOCodeGenerator::LTOCodeGenerator() _linker("LinkTimeOptimizer", "ld-temp.o", _context), _target(NULL), _emitDwarfDebugInfo(false), _scopeRestrictionsDone(false), _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), - _nativeObjectFile(NULL), _assemblerPath(NULL) + _nativeObjectFile(NULL) { InitializeAllTargets(); InitializeAllAsmPrinters(); + InitializeAllAsmParsers(); } LTOCodeGenerator::~LTOCodeGenerator() @@ -126,21 +127,6 @@ void LTOCodeGenerator::setCpu(const char* mCpu) _mCpu = mCpu; } -void LTOCodeGenerator::setAssemblerPath(const char* path) -{ - if ( _assemblerPath ) - delete _assemblerPath; - _assemblerPath = new sys::Path(path); -} - -void LTOCodeGenerator::setAssemblerArgs(const char** args, int nargs) -{ - for (int i = 0; i < nargs; ++i) { - const char *arg = args[i]; - _assemblerArgs.push_back(arg); - } -} - void LTOCodeGenerator::addMustPreserveSymbol(const char* sym) { _mustPreserveSymbols[sym] = 1; @@ -183,55 +169,42 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) { - // make unique temp .s file to put generated assembly code - sys::Path uniqueAsmPath("lto-llvm.s"); - if ( uniqueAsmPath.createTemporaryFileOnDisk(false, &errMsg) ) - return NULL; - sys::RemoveFileOnSignal(uniqueAsmPath); - - // generate assembly code - bool genResult = false; - { - tool_output_file asmFile(uniqueAsmPath.c_str(), errMsg); - if (!errMsg.empty()) - return NULL; - genResult = this->generateAssemblyCode(asmFile.os(), errMsg); - asmFile.os().close(); - if (asmFile.os().has_error()) { - asmFile.os().clear_error(); - return NULL; - } - asmFile.keep(); - } - if ( genResult ) { - uniqueAsmPath.eraseFromDisk(); - return NULL; - } - // make unique temp .o file to put generated object file sys::PathWithStatus uniqueObjPath("lto-llvm.o"); if ( uniqueObjPath.createTemporaryFileOnDisk(false, &errMsg) ) { - uniqueAsmPath.eraseFromDisk(); + uniqueObjPath.eraseFromDisk(); return NULL; } sys::RemoveFileOnSignal(uniqueObjPath); - // assemble the assembly code - const std::string& uniqueObjStr = uniqueObjPath.str(); - bool asmResult = this->assemble(uniqueAsmPath.str(), uniqueObjStr, errMsg); - if ( !asmResult ) { - // remove old buffer if compile() called twice - delete _nativeObjectFile; - - // read .o file into memory buffer - OwningPtr<MemoryBuffer> BuffPtr; - if (error_code ec = MemoryBuffer::getFile(uniqueObjStr.c_str(),BuffPtr)) - errMsg = ec.message(); - _nativeObjectFile = BuffPtr.take(); + // generate object file + bool genResult = false; + tool_output_file objFile(uniqueObjPath.c_str(), errMsg); + if (!errMsg.empty()) + return NULL; + genResult = this->generateObjectFile(objFile.os(), errMsg); + objFile.os().close(); + if (objFile.os().has_error()) { + objFile.os().clear_error(); + return NULL; + } + objFile.keep(); + if ( genResult ) { + uniqueObjPath.eraseFromDisk(); + return NULL; } + const std::string& uniqueObjStr = uniqueObjPath.str(); + // remove old buffer if compile() called twice + delete _nativeObjectFile; + + // read .o file into memory buffer + OwningPtr<MemoryBuffer> BuffPtr; + if (error_code ec = MemoryBuffer::getFile(uniqueObjStr.c_str(),BuffPtr)) + errMsg = ec.message(); + _nativeObjectFile = BuffPtr.take(); + // remove temp files - uniqueAsmPath.eraseFromDisk(); uniqueObjPath.eraseFromDisk(); // return buffer, unless error @@ -241,67 +214,6 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) return _nativeObjectFile->getBufferStart(); } - -bool LTOCodeGenerator::assemble(const std::string& asmPath, - const std::string& objPath, std::string& errMsg) -{ - sys::Path tool; - bool needsCompilerOptions = true; - if ( _assemblerPath ) { - tool = *_assemblerPath; - needsCompilerOptions = false; - } else { - // find compiler driver - tool = sys::Program::FindProgramByName("gcc"); - if ( tool.isEmpty() ) { - errMsg = "can't locate gcc"; - return true; - } - } - - // build argument list - std::vector<const char*> args; - llvm::Triple targetTriple(_linker.getModule()->getTargetTriple()); - const char *arch = targetTriple.getArchNameForAssembler(); - - args.push_back(tool.c_str()); - - if (targetTriple.getOS() == Triple::Darwin) { - // darwin specific command line options - if (arch != NULL) { - args.push_back("-arch"); - args.push_back(arch); - } - // add -static to assembler command line when code model requires - if ( (_assemblerPath != NULL) && - (_codeModel == LTO_CODEGEN_PIC_MODEL_STATIC) ) - args.push_back("-static"); - } - if ( needsCompilerOptions ) { - args.push_back("-c"); - args.push_back("-x"); - args.push_back("assembler"); - } else { - for (std::vector<std::string>::iterator I = _assemblerArgs.begin(), - E = _assemblerArgs.end(); I != E; ++I) { - args.push_back(I->c_str()); - } - } - args.push_back("-o"); - args.push_back(objPath.c_str()); - args.push_back(asmPath.c_str()); - args.push_back(0); - - // invoke assembler - if ( sys::Program::ExecuteAndWait(tool, &args[0], 0, 0, 0, 0, &errMsg) ) { - errMsg = "error in assembly"; - return true; - } - return false; // success -} - - - bool LTOCodeGenerator::determineTarget(std::string& errMsg) { if ( _target == NULL ) { @@ -357,7 +269,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { mangler.getNameWithPrefix(Buffer, f, false); if (!f->isDeclaration() && _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(), e = mergedModule->global_end(); v != e; ++v) { @@ -365,7 +277,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { mangler.getNameWithPrefix(Buffer, v, false); if (!v->isDeclaration() && _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(), e = mergedModule->alias_end(); a != e; ++a) { @@ -373,7 +285,7 @@ void LTOCodeGenerator::applyScopeRestrictions() { mangler.getNameWithPrefix(Buffer, a, false); if (!a->isDeclaration() && _mustPreserveSymbols.count(Buffer)) - mustPreserveList.push_back(::strdup(a->getNameStr().c_str())); + mustPreserveList.push_back(a->getName().data()); } passes.add(createInternalizePass(mustPreserveList)); } @@ -385,8 +297,8 @@ void LTOCodeGenerator::applyScopeRestrictions() { } /// Optimize merged modules using various IPO passes -bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, - std::string& errMsg) +bool LTOCodeGenerator::generateObjectFile(raw_ostream& out, + std::string& errMsg) { if ( this->determineTarget(errMsg) ) return true; @@ -423,7 +335,7 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, formatted_raw_ostream Out(out); if (_target->addPassesToEmitFile(*codeGenPasses, Out, - TargetMachine::CGFT_AssemblyFile, + TargetMachine::CGFT_ObjectFile, CodeGenOpt::Aggressive)) { errMsg = "target file type not supported"; return true; @@ -441,6 +353,7 @@ bool LTOCodeGenerator::generateAssemblyCode(raw_ostream& out, codeGenPasses->run(*it); codeGenPasses->doFinalization(); + delete codeGenPasses; return false; // success } diff --git a/tools/lto/LTOCodeGenerator.h b/tools/lto/LTOCodeGenerator.h index f5b78a6..0556520 100644 --- a/tools/lto/LTOCodeGenerator.h +++ b/tools/lto/LTOCodeGenerator.h @@ -37,18 +37,14 @@ struct LTOCodeGenerator { bool setDebugInfo(lto_debug_model, std::string& errMsg); bool setCodePICModel(lto_codegen_model, std::string& errMsg); void setCpu(const char *cpu); - void setAssemblerPath(const char* path); - void setAssemblerArgs(const char** args, int nargs); void addMustPreserveSymbol(const char* sym); bool writeMergedModules(const char* path, std::string& errMsg); const void* compile(size_t* length, std::string& errMsg); void setCodeGenDebugOptions(const char *opts); private: - bool generateAssemblyCode(llvm::raw_ostream& out, - std::string& errMsg); - bool assemble(const std::string& asmPath, - const std::string& objPath, std::string& errMsg); + bool generateObjectFile(llvm::raw_ostream& out, + std::string& errMsg); void applyScopeRestrictions(); bool determineTarget(std::string& errMsg); @@ -63,9 +59,7 @@ private: StringSet _mustPreserveSymbols; llvm::MemoryBuffer* _nativeObjectFile; std::vector<const char*> _codegenOptions; - llvm::sys::Path* _assemblerPath; std::string _mCpu; - std::vector<std::string> _assemblerArgs; }; #endif // LTO_CODE_GENERATOR_H diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 8562f74..1eac22c 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -195,26 +195,28 @@ void LTOModule::addObjCClass(GlobalVariable *clgv) { std::string superclassName; if (objcClassNameFromExpression(c->getOperand(1), superclassName)) { NameAndAttributes info; - if (_undefines.find(superclassName.c_str()) == _undefines.end()) { - const char *symbolName = ::strdup(superclassName.c_str()); + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(superclassName.c_str()); + if (!entry.getValue().name) { + const char *symbolName = entry.getKey().data(); info.name = symbolName; info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - // string is owned by _undefines - _undefines[info.name] = info; + entry.setValue(info); } } // third slot in __OBJC,__class is pointer to class name std::string 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; - info.name = symbolName; + info.name = entry.getKey().data(); info.attributes = (lto_symbol_attributes) (LTO_SYMBOL_PERMISSIONS_DATA | LTO_SYMBOL_DEFINITION_REGULAR | LTO_SYMBOL_SCOPE_DEFAULT); _symbols.push_back(info); - _defines[info.name] = 1; } } } @@ -227,13 +229,17 @@ void LTOModule::addObjCCategory(GlobalVariable *clgv) { std::string targetclassName; if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) { NameAndAttributes info; - if (_undefines.find(targetclassName.c_str()) == _undefines.end()) { - const char *symbolName = ::strdup(targetclassName.c_str()); - info.name = symbolName; - info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - // string is owned by _undefines - _undefines[info.name] = info; - } + + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(targetclassName.c_str()); + + if (entry.getValue().name) + 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; if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) { NameAndAttributes info; - if (_undefines.find(targetclassName.c_str()) == _undefines.end()) { - const char *symbolName = ::strdup(targetclassName.c_str()); - info.name = symbolName; - info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - // string is owned by _undefines - _undefines[info.name] = info; - } + + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(targetclassName.c_str()); + if (entry.getValue().name) + return; + + 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 SmallString<64> Buffer; mangler.getNameWithPrefix(Buffer, def, false); - const char *symbolName = ::strdup(Buffer.c_str()); // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); @@ -365,26 +373,31 @@ void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler, // add to table of symbols 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; _symbols.push_back(info); - _defines[info.name] = 1; } void LTOModule::addAsmGlobalSymbol(const char *name) { + StringSet::value_type &entry = _defines.GetOrCreateValue(name); + // only add new define if not already defined - if (_defines.count(name)) + if (entry.getValue()) return; - // string is owned by _defines - const char *symbolName = ::strdup(name); + entry.setValue(1); + const char *symbolName = entry.getKey().data(); uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR; attr |= LTO_SYMBOL_SCOPE_DEFAULT; NameAndAttributes info; info.name = symbolName; info.attributes = (lto_symbol_attributes)attr; _symbols.push_back(info); - _defines[info.name] = 1; } void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, @@ -400,18 +413,22 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, SmallString<64> name; mangler.getNameWithPrefix(name, decl, false); + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(name.c_str()); + // we already have the symbol - if (_undefines.find(name) != _undefines.end()) + if (entry.getValue().name) return; NameAndAttributes info; - // string is owned by _undefines - info.name = ::strdup(name.c_str()); + + info.name = entry.getKey().data(); if (decl->hasExternalWeakLinkage()) info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF; else info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - _undefines[name] = info; + + entry.setValue(info); } diff --git a/tools/lto/lto.cpp b/tools/lto/lto.cpp index 7d4871d..f48570c 100644 --- a/tools/lto/lto.cpp +++ b/tools/lto/lto.cpp @@ -231,7 +231,7 @@ void lto_codegen_set_cpu(lto_code_gen_t cg, const char* cpu) // void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path) { - cg->setAssemblerPath(path); + // In here only for backwards compatibility. We use MC now. } @@ -241,7 +241,7 @@ void lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path) void lto_codegen_set_assembler_args(lto_code_gen_t cg, const char** args, int nargs) { - cg->setAssemblerArgs(args, nargs); + // In here only for backwards compatibility. We use MC now. } // |