From 9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74 Mon Sep 17 00:00:00 2001 From: rdivacky Date: Tue, 13 Jul 2010 17:19:57 +0000 Subject: Update LLVM to r108243. --- tools/bugpoint/BugDriver.h | 6 +- tools/bugpoint/CrashDebugger.cpp | 31 ++++---- tools/bugpoint/ExtractFunction.cpp | 28 +++---- tools/bugpoint/ListReducer.h | 4 +- tools/bugpoint/Miscompilation.cpp | 48 ++++++----- tools/bugpoint/ToolRunner.h | 2 +- tools/edis/EDDisassembler.cpp | 2 +- tools/gold/gold-plugin.cpp | 155 ++++++++++++++++++++++++------------ tools/llc/llc.cpp | 12 +-- tools/llvm-extract/llvm-extract.cpp | 1 + tools/llvm-link/llvm-link.cpp | 20 ++--- tools/llvm-mc/Makefile | 1 - tools/llvm-mc/llvm-mc.cpp | 5 +- tools/llvm-nm/llvm-nm.cpp | 3 +- tools/llvmc/plugins/Base/Base.td.in | 12 ++- tools/lto/LTOCodeGenerator.cpp | 10 +-- tools/opt/GraphPrinters.cpp | 2 +- tools/opt/PrintSCC.cpp | 2 +- tools/opt/opt.cpp | 48 ++++++----- 19 files changed, 226 insertions(+), 166 deletions(-) (limited to 'tools') diff --git a/tools/bugpoint/BugDriver.h b/tools/bugpoint/BugDriver.h index e5b7373..4f6bae5 100644 --- a/tools/bugpoint/BugDriver.h +++ b/tools/bugpoint/BugDriver.h @@ -16,7 +16,7 @@ #ifndef BUGDRIVER_H #define BUGDRIVER_H -#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/ValueMap.h" #include #include @@ -269,7 +269,7 @@ public: /// recreate the failure. This returns true if a compiler error is found. /// bool runManyPasses(const std::vector &AllPasses, - std::string &ErrMsg); + std::string &ErrMsg); /// writeProgramToFile - This writes the current "Program" to the named /// bitcode file. If an error occurs, true is returned. @@ -325,7 +325,7 @@ void DeleteFunctionBody(Function *F); /// module, split the functions OUT of the specified module, and place them in /// the new module. Module *SplitFunctionsOutOfModule(Module *M, const std::vector &F, - DenseMap &ValueMap); + ValueMap &VMap); } // End llvm namespace diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index 46b33d2..2d0631c 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -130,14 +130,14 @@ bool ReduceCrashingGlobalVariables::TestGlobalVariables( std::vector &GVs) { // Clone the program to try hacking it apart... - DenseMap ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... std::set GVSet; for (unsigned i = 0, e = GVs.size(); i != e; ++i) { - GlobalVariable* CMGV = cast(ValueMap[GVs[i]]); + GlobalVariable* CMGV = cast(VMap[GVs[i]]); assert(CMGV && "Global Variable not in module?!"); GVSet.insert(CMGV); } @@ -204,13 +204,13 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector &Funcs) { return false; // Clone the program to try hacking it apart... - DenseMap ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... std::set Functions; for (unsigned i = 0, e = Funcs.size(); i != e; ++i) { - Function *CMF = cast(ValueMap[Funcs[i]]); + Function *CMF = cast(VMap[Funcs[i]]); assert(CMF && "Function not in module?!"); assert(CMF->getFunctionType() == Funcs[i]->getFunctionType() && "wrong ty"); assert(CMF->getName() == Funcs[i]->getName() && "wrong name"); @@ -270,13 +270,13 @@ namespace { bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { // Clone the program to try hacking it apart... - DenseMap ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet Blocks; for (unsigned i = 0, e = BBs.size(); i != e; ++i) - Blocks.insert(cast(ValueMap[BBs[i]])); + Blocks.insert(cast(VMap[BBs[i]])); outs() << "Checking for crash with only these blocks:"; unsigned NumPrint = Blocks.size(); @@ -298,10 +298,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector &BBs) { TerminatorInst *BBTerm = BB->getTerminator(); - if (BBTerm->getType()->isStructTy()) - BBTerm->replaceAllUsesWith(UndefValue::get(BBTerm->getType())); - else if (BB->getTerminator()->getType() != - Type::getVoidTy(BB->getContext())) + if (!BB->getTerminator()->getType()->isVoidTy()) BBTerm->replaceAllUsesWith(Constant::getNullValue(BBTerm->getType())); // Replace the old terminator instruction. @@ -374,14 +371,14 @@ namespace { bool ReduceCrashingInstructions::TestInsts(std::vector &Insts) { // Clone the program to try hacking it apart... - DenseMap ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet Instructions; for (unsigned i = 0, e = Insts.size(); i != e; ++i) { assert(!isa(Insts[i])); - Instructions.insert(cast(ValueMap[Insts[i]])); + Instructions.insert(cast(VMap[Insts[i]])); } outs() << "Checking for crash with only " << Instructions.size(); @@ -395,7 +392,7 @@ bool ReduceCrashingInstructions::TestInsts(std::vector for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { Instruction *Inst = I++; if (!Instructions.count(Inst) && !isa(Inst)) { - if (Inst->getType() != Type::getVoidTy(Inst->getContext())) + if (!Inst->getType()->isVoidTy()) Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); Inst->eraseFromParent(); } diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index eaa2c53..d5611b5 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -73,9 +73,7 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I, Instruction *TheInst = RI; // Got the corresponding instruction! // If this instruction produces a value, replace any users with null values - if (TheInst->getType()->isStructTy()) - TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType())); - else if (TheInst->getType() != Type::getVoidTy(I->getContext())) + if (!TheInst->getType()->isVoidTy()) TheInst->replaceAllUsesWith(Constant::getNullValue(TheInst->getType())); // Remove the instruction from the program. @@ -118,13 +116,14 @@ Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) { std::vector CleanupPasses; CleanupPasses.push_back(getPI(createGlobalDCEPass())); - CleanupPasses.push_back(getPI(createDeadTypeEliminationPass())); if (MayModifySemantics) CleanupPasses.push_back(getPI(createDeadArgHackingPass())); else CleanupPasses.push_back(getPI(createDeadArgEliminationPass())); + CleanupPasses.push_back(getPI(createDeadTypeEliminationPass())); + Module *New = runPassesOn(M, CleanupPasses); if (New == 0) { errs() << "Final cleanups failed. Sorry. :( Please report a bug!\n"; @@ -202,7 +201,7 @@ static Constant *GetTorInit(std::vector > &TorList) { /// static ctors/dtors, we need to add an llvm.global_[cd]tors global to M2, and /// prune appropriate entries out of M1s list. static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, - DenseMap ValueMap) { + ValueMap VMap) { GlobalVariable *GV = M1->getNamedGlobal(GlobalName); if (!GV || GV->isDeclaration() || GV->hasLocalLinkage() || !GV->use_empty()) return; @@ -230,7 +229,7 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, M1Tors.push_back(std::make_pair(F, Priority)); else { // Map to M2's version of the function. - F = cast(ValueMap[F]); + F = cast(VMap[F]); M2Tors.push_back(std::make_pair(F, Priority)); } } @@ -265,7 +264,7 @@ static void SplitStaticCtorDtor(const char *GlobalName, Module *M1, Module *M2, Module * llvm::SplitFunctionsOutOfModule(Module *M, const std::vector &F, - DenseMap &ValueMap) { + ValueMap &VMap) { // Make sure functions & globals are all external so that linkage // between the two modules will work. for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) @@ -277,8 +276,8 @@ llvm::SplitFunctionsOutOfModule(Module *M, I->setLinkage(GlobalValue::ExternalLinkage); } - DenseMap NewValueMap; - Module *New = CloneModule(M, NewValueMap); + ValueMap NewVMap; + Module *New = CloneModule(M, NewVMap); // Make sure global initializers exist only in the safe module (CBE->.so) for (Module::global_iterator I = New->global_begin(), E = New->global_end(); @@ -288,11 +287,11 @@ llvm::SplitFunctionsOutOfModule(Module *M, // Remove the Test functions from the Safe module std::set TestFunctions; for (unsigned i = 0, e = F.size(); i != e; ++i) { - Function *TNOF = cast(ValueMap[F[i]]); + Function *TNOF = cast(VMap[F[i]]); DEBUG(errs() << "Removing function "); DEBUG(WriteAsOperand(errs(), TNOF, false)); DEBUG(errs() << "\n"); - TestFunctions.insert(cast(NewValueMap[TNOF])); + TestFunctions.insert(cast(NewVMap[TNOF])); DeleteFunctionBody(TNOF); // Function is now external in this module! } @@ -305,8 +304,8 @@ llvm::SplitFunctionsOutOfModule(Module *M, // Make sure that there is a global ctor/dtor array in both halves of the // module if they both have static ctor/dtor functions. - SplitStaticCtorDtor("llvm.global_ctors", M, New, NewValueMap); - SplitStaticCtorDtor("llvm.global_dtors", M, New, NewValueMap); + SplitStaticCtorDtor("llvm.global_ctors", M, New, NewVMap); + SplitStaticCtorDtor("llvm.global_dtors", M, New, NewVMap); return New; } @@ -365,8 +364,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const PI.push_back(getPI(createBlockExtractorPass(EmptyBBs))); Module *Ret = runPassesOn(M, PI, false, 1, &ExtraArg); - if (uniqueFilename.exists()) - uniqueFilename.eraseFromDisk(); // Free disk space + uniqueFilename.eraseFromDisk(); // Free disk space if (Ret == 0) { outs() << "*** Basic Block extraction failed, please report a bug!\n"; diff --git a/tools/bugpoint/ListReducer.h b/tools/bugpoint/ListReducer.h index 5e9cff0..bd1c5da 100644 --- a/tools/bugpoint/ListReducer.h +++ b/tools/bugpoint/ListReducer.h @@ -183,8 +183,8 @@ Backjump: --i; // Don't skip an element of the list Changed = true; } - if (!Error.empty()) - return true; + if (!Error.empty()) + return true; } // This can take a long time if left uncontrolled. For now, don't // iterate. diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp index 71484a2..47ac3c5 100644 --- a/tools/bugpoint/Miscompilation.cpp +++ b/tools/bugpoint/Miscompilation.cpp @@ -251,10 +251,10 @@ int ReduceMiscompilingFunctions::TestFuncs(const std::vector &Funcs, outs() << '\n'; // Split the module into the two halves of the program we want. - DenseMap ValueMap; - Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, Funcs, - ValueMap); + VMap); // Run the predicate, note that the predicate will delete both input modules. return TestFn(BD, ToOptimize, ToNotOptimize, Error); @@ -285,11 +285,11 @@ static bool ExtractLoops(BugDriver &BD, while (1) { if (BugpointIsInterrupted) return MadeChange; - DenseMap ValueMap; - Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, MiscompiledFunctions, - ValueMap); + VMap); Module *ToOptimizeLoopExtracted = BD.ExtractLoop(ToOptimize); if (!ToOptimizeLoopExtracted) { // If the loop extractor crashed or if there were no extractible loops, @@ -448,11 +448,11 @@ bool ReduceMiscompiledBlocks::TestFuncs(const std::vector &BBs, outs() << '\n'; // Split the module into the two halves of the program we want. - DenseMap ValueMap; - Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *ToNotOptimize = CloneModule(BD.getProgram(), VMap); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, FunctionsBeingTested, - ValueMap); + VMap); // Try the extraction. If it doesn't work, then the block extractor crashed // or something, in which case bugpoint can't chase down this possibility. @@ -505,11 +505,11 @@ static bool ExtractBlocks(BugDriver &BD, return false; } - DenseMap ValueMap; - Module *ProgClone = CloneModule(BD.getProgram(), ValueMap); + ValueMap VMap; + Module *ProgClone = CloneModule(BD.getProgram(), VMap); Module *ToExtract = SplitFunctionsOutOfModule(ProgClone, MiscompiledFunctions, - ValueMap); + VMap); Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract); if (Extracted == 0) { // Weird, extraction should have worked. @@ -687,11 +687,11 @@ void BugDriver::debugMiscompilation(std::string *Error) { // Output a bunch of bitcode files for the user... outs() << "Outputting reduced bitcode files which expose the problem:\n"; - DenseMap ValueMap; - Module *ToNotOptimize = CloneModule(getProgram(), ValueMap); + ValueMap VMap; + Module *ToNotOptimize = CloneModule(getProgram(), VMap); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, MiscompiledFunctions, - ValueMap); + VMap); outs() << " Non-optimized portion: "; ToNotOptimize = swapProgramIn(ToNotOptimize); @@ -848,7 +848,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test, Args.push_back(i); // Pass on the arguments to the real function, return its result - if (F->getReturnType() == Type::getVoidTy(F->getContext())) { + if (F->getReturnType()->isVoidTy()) { CallInst::Create(FuncPtr, Args.begin(), Args.end(), "", DoCallBB); ReturnInst::Create(F->getContext(), DoCallBB); } else { @@ -894,6 +894,8 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, } delete Test; + FileRemover TestModuleBCRemover(TestModuleBC, !SaveTemps); + // Make the shared library sys::Path SafeModuleBC("bugpoint.safe.bc"); if (SafeModuleBC.makeUnique(true, &ErrMsg)) { @@ -907,11 +909,16 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, << "'\nExiting."; exit(1); } + + FileRemover SafeModuleBCRemover(SafeModuleBC, !SaveTemps); + std::string SharedObject = BD.compileSharedObject(SafeModuleBC.str(), Error); if (!Error.empty()) return false; delete Safe; + FileRemover SharedObjectRemover(sys::Path(SharedObject), !SaveTemps); + // Run the code generator on the `Test' code, loading the shared library. // The function returns whether or not the new output differs from reference. bool Result = BD.diffProgram(TestModuleBC.str(), SharedObject, false, &Error); @@ -922,9 +929,6 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe, errs() << ": still failing!\n"; else errs() << ": didn't fail.\n"; - TestModuleBC.eraseFromDisk(); - SafeModuleBC.eraseFromDisk(); - sys::Path(SharedObject).eraseFromDisk(); return Result; } @@ -956,9 +960,9 @@ bool BugDriver::debugCodeGenerator(std::string *Error) { return true; // Split the module into the two halves of the program we want. - DenseMap ValueMap; - Module *ToNotCodeGen = CloneModule(getProgram(), ValueMap); - Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, ValueMap); + ValueMap VMap; + Module *ToNotCodeGen = CloneModule(getProgram(), VMap); + Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, VMap); // Condition the modules CleanupAndPrepareModules(*this, ToCodeGen, ToNotCodeGen); diff --git a/tools/bugpoint/ToolRunner.h b/tools/bugpoint/ToolRunner.h index d966fc0..cda0ddf 100644 --- a/tools/bugpoint/ToolRunner.h +++ b/tools/bugpoint/ToolRunner.h @@ -64,7 +64,7 @@ public: FileType fileType, const std::string &InputFile, const std::string &OutputFile, - std::string *Error = 0, + std::string *Error = 0, const std::vector &GCCArgs = std::vector(), unsigned Timeout = 0, diff --git a/tools/edis/EDDisassembler.cpp b/tools/edis/EDDisassembler.cpp index 00b5d8d..85e41e6 100644 --- a/tools/edis/EDDisassembler.cpp +++ b/tools/edis/EDDisassembler.cpp @@ -364,7 +364,7 @@ int EDDisassembler::parseInst(SmallVectorImpl &operands, sourceMgr.AddNewSourceBuffer(buf, SMLoc()); // ownership of buf handed over MCContext context(*AsmInfo); OwningPtr streamer(createNullStreamer(context)); - AsmParser genericParser(sourceMgr, context, *streamer, *AsmInfo); + AsmParser genericParser(*Tgt, sourceMgr, context, *streamer, *AsmInfo); OwningPtr TargetParser(Tgt->createAsmParser(genericParser)); AsmToken OpcodeToken = genericParser.Lex(); diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 2e5c179..2d0f5bd 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -41,6 +41,8 @@ namespace { ld_plugin_add_symbols add_symbols = NULL; ld_plugin_get_symbols get_symbols = NULL; ld_plugin_add_input_file add_input_file = NULL; + ld_plugin_add_input_library add_input_library = NULL; + ld_plugin_set_extra_library_path set_extra_library_path = NULL; ld_plugin_message message = discard_message; int api_version = 0; @@ -53,46 +55,62 @@ namespace { }; lto_codegen_model output_type = LTO_CODEGEN_PIC_MODEL_STATIC; + std::string output_name = ""; std::list Modules; std::vector Cleanup; } namespace options { + enum generate_bc { BC_NO, BC_ALSO, BC_ONLY }; static bool generate_api_file = false; + static generate_bc generate_bc_file = BC_NO; static std::string bc_path; - static const char *as_path = NULL; + static std::string as_path; + static std::vector pass_through; + static std::string extra_library_path; // Additional options to pass into the code generator. - // Note: This array will contain all plugin options which are not claimed + // Note: This array will contain all plugin options which are not claimed // as plugin exclusive to pass to the code generator. - // For example, "generate-api-file" and "as"options are for the plugin + // For example, "generate-api-file" and "as"options are for the plugin // use only and will not be passed. static std::vector extra; - static void process_plugin_option(const char* opt) + static void process_plugin_option(const char* opt_) { - if (opt == NULL) + if (opt_ == NULL) return; + llvm::StringRef opt = opt_; - if (strcmp("generate-api-file", opt) == 0) { + if (opt == "generate-api-file") { generate_api_file = true; - } else if (strncmp("as=", opt, 3) == 0) { - if (as_path) { + } else if (opt.startswith("as=")) { + if (!as_path.empty()) { (*message)(LDPL_WARNING, "Path to as specified twice. " - "Discarding %s", opt); + "Discarding %s", opt_); } else { - as_path = strdup(opt + 3); + as_path = opt.substr(strlen("as=")); } - } else if(llvm::StringRef(opt).startswith("also-emit-llvm=")) { - const char *path = opt + strlen("also-emit-llvm="); - if (bc_path != "") { + } else if (opt.startswith("extra-library-path=")) { + extra_library_path = opt.substr(strlen("extra_library_path=")); + } else if (opt.startswith("pass-through=")) { + llvm::StringRef item = opt.substr(strlen("pass-through=")); + pass_through.push_back(item.str()); + } else if (opt == "emit-llvm") { + generate_bc_file = BC_ONLY; + } else if (opt == "also-emit-llvm") { + generate_bc_file = BC_ALSO; + } else if (opt.startswith("also-emit-llvm=")) { + llvm::StringRef path = opt.substr(strlen("also-emit-llvm=")); + generate_bc_file = BC_ALSO; + if (!bc_path.empty()) { (*message)(LDPL_WARNING, "Path to the output IL file specified twice. " - "Discarding %s", opt); + "Discarding %s", opt_); } else { bc_path = path; } } else { // Save this option to pass to the code generator. - extra.push_back(std::string(opt)); + extra.push_back(opt); } } } @@ -111,8 +129,6 @@ ld_plugin_status onload(ld_plugin_tv *tv) { // for services. bool registeredClaimFile = false; - bool registeredAllSymbolsRead = false; - bool registeredCleanup = false; for (; tv->tv_tag != LDPT_NULL; ++tv) { switch (tv->tv_tag) { @@ -122,6 +138,9 @@ ld_plugin_status onload(ld_plugin_tv *tv) { case LDPT_GOLD_VERSION: // major * 100 + minor gold_version = tv->tv_u.tv_val; break; + case LDPT_OUTPUT_NAME: + output_name = tv->tv_u.tv_string; + break; case LDPT_LINKER_OUTPUT: switch (tv->tv_u.tv_val) { case LDPO_REL: // .o @@ -157,8 +176,6 @@ ld_plugin_status onload(ld_plugin_tv *tv) { if ((*callback)(all_symbols_read_hook) != LDPS_OK) return LDPS_ERR; - - registeredAllSymbolsRead = true; } break; case LDPT_REGISTER_CLEANUP_HOOK: { ld_plugin_register_cleanup callback; @@ -166,8 +183,6 @@ ld_plugin_status onload(ld_plugin_tv *tv) { if ((*callback)(cleanup_hook) != LDPS_OK) return LDPS_ERR; - - registeredCleanup = true; } break; case LDPT_ADD_SYMBOLS: add_symbols = tv->tv_u.tv_add_symbols; @@ -178,6 +193,12 @@ ld_plugin_status onload(ld_plugin_tv *tv) { case LDPT_ADD_INPUT_FILE: add_input_file = tv->tv_u.tv_add_input_file; break; + case LDPT_ADD_INPUT_LIBRARY: + add_input_library = tv->tv_u.tv_add_input_file; + break; + case LDPT_SET_EXTRA_LIBRARY_PATH: + set_extra_library_path = tv->tv_u.tv_set_extra_library_path; + break; case LDPT_MESSAGE: message = tv->tv_u.tv_message; break; @@ -209,7 +230,7 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, // an .a archive. if (lseek(file->fd, file->offset, SEEK_SET) == -1) { (*message)(LDPL_ERROR, - "Failed to seek to archive member of %s at offset %d: %s\n", + "Failed to seek to archive member of %s at offset %d: %s\n", file->name, file->offset, sys::StrError(errno).c_str()); return LDPS_ERR; @@ -217,7 +238,7 @@ static ld_plugin_status claim_file_hook(const ld_plugin_input_file *file, buf = malloc(file->filesize); if (!buf) { (*message)(LDPL_ERROR, - "Failed to allocate buffer for archive member of size: %d\n", + "Failed to allocate buffer for archive member of size: %d\n", file->filesize); return LDPS_ERR; } @@ -343,35 +364,33 @@ static ld_plugin_status all_symbols_read_hook(void) { // If we don't preserve any symbols, libLTO will assume that all symbols are // needed. Keep all symbols unless we're producing a final executable. - if (output_type == LTO_CODEGEN_PIC_MODEL_STATIC) { - bool anySymbolsPreserved = false; - for (std::list::iterator I = Modules.begin(), + bool anySymbolsPreserved = false; + for (std::list::iterator I = Modules.begin(), E = Modules.end(); I != E; ++I) { - (*get_symbols)(I->handle, I->syms.size(), &I->syms[0]); - for (unsigned i = 0, e = I->syms.size(); i != e; i++) { - if (I->syms[i].resolution == LDPR_PREVAILING_DEF) { - lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name); - anySymbolsPreserved = true; - - if (options::generate_api_file) - api_file << I->syms[i].name << "\n"; - } + (*get_symbols)(I->handle, I->syms.size(), &I->syms[0]); + for (unsigned i = 0, e = I->syms.size(); i != e; i++) { + if (I->syms[i].resolution == LDPR_PREVAILING_DEF) { + lto_codegen_add_must_preserve_symbol(cg, I->syms[i].name); + anySymbolsPreserved = true; + + if (options::generate_api_file) + api_file << I->syms[i].name << "\n"; } } + } - if (options::generate_api_file) - api_file.close(); + if (options::generate_api_file) + api_file.close(); - if (!anySymbolsPreserved) { - // This entire file is unnecessary! - lto_codegen_dispose(cg); - return LDPS_OK; - } + if (!anySymbolsPreserved) { + // All of the IL is unnecessary! + lto_codegen_dispose(cg); + return LDPS_OK; } lto_codegen_set_pic_model(cg, output_type); lto_codegen_set_debug_model(cg, LTO_DEBUG_MODEL_DWARF); - if (options::as_path) { + if (!options::as_path.empty()) { sys::Path p = sys::Program::FindProgramByName(options::as_path); lto_codegen_set_assembler_path(cg, p.c_str()); } @@ -383,10 +402,20 @@ static ld_plugin_status all_symbols_read_hook(void) { } } - if (options::bc_path != "") { - bool err = lto_codegen_write_merged_modules(cg, options::bc_path.c_str()); + + if (options::generate_bc_file != options::BC_NO) { + std::string path; + if (options::generate_bc_file == options::BC_ONLY) + path = output_name; + else if (!options::bc_path.empty()) + path = options::bc_path; + else + path = output_name + ".bc"; + bool err = lto_codegen_write_merged_modules(cg, path.c_str()); if (err) (*message)(LDPL_FATAL, "Failed to write the output file."); + if (options::generate_bc_file == options::BC_ONLY) + exit(0); } size_t bufsize = 0; const char *buffer = static_cast(lto_codegen_compile(cg, @@ -399,26 +428,48 @@ static ld_plugin_status all_symbols_read_hook(void) { (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); return LDPS_ERR; } - raw_fd_ostream *objFile = - new raw_fd_ostream(uniqueObjPath.c_str(), ErrMsg, - raw_fd_ostream::F_Binary); + raw_fd_ostream objFile(uniqueObjPath.c_str(), ErrMsg, + raw_fd_ostream::F_Binary); if (!ErrMsg.empty()) { - delete objFile; (*message)(LDPL_ERROR, "%s", ErrMsg.c_str()); return LDPS_ERR; } - objFile->write(buffer, bufsize); - objFile->close(); + objFile.write(buffer, bufsize); + objFile.close(); lto_codegen_dispose(cg); - if ((*add_input_file)(const_cast(uniqueObjPath.c_str())) != LDPS_OK) { + if ((*add_input_file)(uniqueObjPath.c_str()) != LDPS_OK) { (*message)(LDPL_ERROR, "Unable to add .o file to the link."); (*message)(LDPL_ERROR, "File left behind in: %s", uniqueObjPath.c_str()); return LDPS_ERR; } + if (!options::extra_library_path.empty() && + set_extra_library_path(options::extra_library_path.c_str()) != LDPS_OK) { + (*message)(LDPL_ERROR, "Unable to set the extra library path."); + return LDPS_ERR; + } + + for (std::vector::iterator i = options::pass_through.begin(), + e = options::pass_through.end(); + i != e; ++i) { + std::string &item = *i; + const char *item_p = item.c_str(); + if (llvm::StringRef(item).startswith("-l")) { + if (add_input_library(item_p + 2) != LDPS_OK) { + (*message)(LDPL_ERROR, "Unable to add library to the link."); + return LDPS_ERR; + } + } else { + if (add_input_file(item_p) != LDPS_OK) { + (*message)(LDPL_ERROR, "Unable to add .o file to the link."); + return LDPS_ERR; + } + } + } + Cleanup.push_back(uniqueObjPath); return LDPS_OK; diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index f3eed56..199a1a9 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -124,7 +124,8 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName, const char *ProgName) { if (OutputFilename != "") { if (OutputFilename == "-") - return &fouts(); + return new formatted_raw_ostream(outs(), + formatted_raw_ostream::PRESERVE_STREAM); // Make sure that the Out file gets unlinked from the disk if we get a // SIGINT @@ -147,7 +148,8 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName, if (InputFilename == "-") { OutputFilename = "-"; - return &fouts(); + return new formatted_raw_ostream(outs(), + formatted_raw_ostream::PRESERVE_STREAM); } OutputFilename = GetFileNameRoot(InputFilename); @@ -332,7 +334,7 @@ int main(int argc, char **argv) { DisableVerify)) { errs() << argv[0] << ": target does not support generation of this" << " file type!\n"; - if (Out != &fouts()) delete Out; + delete Out; // And the Out file is empty and useless, so remove it now. sys::Path(OutputFilename).eraseFromDisk(); return 1; @@ -340,8 +342,8 @@ int main(int argc, char **argv) { PM.run(mod); - // Delete the ostream if it's not a stdout stream - if (Out != &fouts()) delete Out; + // Delete the ostream. + delete Out; return 0; } diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index 276dfd6..e6b5b84 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -112,6 +112,7 @@ int main(int argc, char **argv) { Passes.add(createGVExtractionPass(GVs, DeleteFn, Relink)); if (!DeleteFn) Passes.add(createGlobalDCEPass()); // Delete unreachable globals + Passes.add(createStripDeadDebugInfoPass()); // Remove dead debug info Passes.add(createDeadTypeEliminationPass()); // Remove dead types... Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls diff --git a/tools/llvm-link/llvm-link.cpp b/tools/llvm-link/llvm-link.cpp index c60e56a..f7dad3d 100644 --- a/tools/llvm-link/llvm-link.cpp +++ b/tools/llvm-link/llvm-link.cpp @@ -62,20 +62,14 @@ static inline std::auto_ptr LoadFile(const char *argv0, } SMDiagnostic Err; - if (Filename.exists()) { - if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n"; - Module* Result = 0; - - const std::string &FNStr = Filename.str(); - Result = ParseIRFile(FNStr, Err, Context); - if (Result) return std::auto_ptr(Result); // Load successful! - - if (Verbose) - Err.Print(argv0, errs()); - } else { - errs() << "Bitcode file: '" << Filename.c_str() << "' does not exist.\n"; - } + if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n"; + Module* Result = 0; + + const std::string &FNStr = Filename.str(); + Result = ParseIRFile(FNStr, Err, Context); + if (Result) return std::auto_ptr(Result); // Load successful! + Err.Print(argv0, errs()); return std::auto_ptr(); } diff --git a/tools/llvm-mc/Makefile b/tools/llvm-mc/Makefile index f92e643..a127493 100644 --- a/tools/llvm-mc/Makefile +++ b/tools/llvm-mc/Makefile @@ -12,7 +12,6 @@ TOOLNAME = llvm-mc # This tool has no plugins, optimize startup time. TOOL_NO_EXPORTS = 1 -NO_INSTALL = 1 # Include this here so we can get the configuration of the targets # that have been configured for construction. We have to do this diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index a114ab0..fc8a1c5 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -312,7 +312,7 @@ static int AssembleInput(const char *ProgName) { Str.reset(createLoggingStreamer(Str.take(), errs())); } - AsmParser Parser(SrcMgr, Ctx, *Str.get(), *MAI); + AsmParser Parser(*TheTarget, SrcMgr, Ctx, *Str.get(), *MAI); OwningPtr TAP(TheTarget->createAsmParser(Parser)); if (!TAP) { errs() << ProgName @@ -323,8 +323,7 @@ static int AssembleInput(const char *ProgName) { Parser.setTargetParser(*TAP.get()); int Res = Parser.Run(NoInitialTextSection); - if (Out != &fouts()) - delete Out; + delete Out; // Delete output on errors. if (Res && OutputFilename != "-") diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 2baf532..fd7e7f6 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -89,7 +89,8 @@ static char TypeCharForSymbol(GlobalValue &GV) { static void DumpSymbolNameForGlobalValue(GlobalValue &GV) { // Private linkage and available_externally linkage don't exist in symtab. if (GV.hasPrivateLinkage() || GV.hasLinkerPrivateLinkage() || - GV.hasAvailableExternallyLinkage()) return; + GV.hasLinkerPrivateWeakLinkage() || GV.hasAvailableExternallyLinkage()) + return; const std::string SymbolAddrStr = " "; // Not used yet... char TypeChar = TypeCharForSymbol(GV); diff --git a/tools/llvmc/plugins/Base/Base.td.in b/tools/llvmc/plugins/Base/Base.td.in index 23f46b7..a042997 100644 --- a/tools/llvmc/plugins/Base/Base.td.in +++ b/tools/llvmc/plugins/Base/Base.td.in @@ -262,12 +262,12 @@ def llc : Tool< ]>; // Base class for linkers -class llvm_gcc_based_linker : Tool< +class llvm_gcc_based_linker : Tool< [(in_language ["object-code", "static-library"]), (out_language "executable"), (output_suffix "out"), (command cmd_prefix), - (works_on_empty (case (not_empty "filelist"), true, + (works_on_empty (case (and (not_empty "filelist"), on_empty), true, (default), false)), (join), (actions (case @@ -295,9 +295,13 @@ class llvm_gcc_based_linker : Tool< ]>; // Default linker -def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@">; +def llvm_gcc_linker : llvm_gcc_based_linker<"@LLVMGCCCOMMAND@", + (not (or (parameter_equals "linker", "g++"), + (parameter_equals "linker", "c++")))>; // Alternative linker for C++ -def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@">; +def llvm_gcc_cpp_linker : llvm_gcc_based_linker<"@LLVMGXXCOMMAND@", + (or (parameter_equals "linker", "g++"), + (parameter_equals "linker", "c++"))>; // Language map diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 59e8405..911fddf 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -152,10 +152,12 @@ bool LTOCodeGenerator::writeMergedModules(const char *path, // write bitcode to it WriteBitcodeToFile(_linker.getModule(), Out); - + Out.close(); + if (Out.has_error()) { errMsg = "could not write bitcode file: "; errMsg += path; + Out.clear_error(); return true; } @@ -181,16 +183,14 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg) genResult = this->generateAssemblyCode(asmFile, errMsg); } if ( genResult ) { - if ( uniqueAsmPath.exists() ) - uniqueAsmPath.eraseFromDisk(); + uniqueAsmPath.eraseFromDisk(); return NULL; } // make unique temp .o file to put generated object file sys::PathWithStatus uniqueObjPath("lto-llvm.o"); if ( uniqueObjPath.createTemporaryFileOnDisk(true, &errMsg) ) { - if ( uniqueAsmPath.exists() ) - uniqueAsmPath.eraseFromDisk(); + uniqueAsmPath.eraseFromDisk(); return NULL; } sys::RemoveFileOnSignal(uniqueObjPath); diff --git a/tools/opt/GraphPrinters.cpp b/tools/opt/GraphPrinters.cpp index 86f9932..e7c6d1e 100644 --- a/tools/opt/GraphPrinters.cpp +++ b/tools/opt/GraphPrinters.cpp @@ -56,7 +56,7 @@ namespace llvm { if (Node->getFunction()) return ((Value*)Node->getFunction())->getName(); else - return "Indirect call node"; + return "external node"; } }; } diff --git a/tools/opt/PrintSCC.cpp b/tools/opt/PrintSCC.cpp index 66709ff..ea486ca 100644 --- a/tools/opt/PrintSCC.cpp +++ b/tools/opt/PrintSCC.cpp @@ -102,7 +102,7 @@ bool CallGraphSCC::runOnModule(Module &M) { for (std::vector::const_iterator I = nextSCC.begin(), E = nextSCC.end(); I != E; ++I) outs() << ((*I)->getFunction() ? (*I)->getFunction()->getNameStr() - : std::string("Indirect CallGraph node")) << ", "; + : std::string("external node")) << ", "; if (nextSCC.size() == 1 && SCCI.hasLoop()) outs() << " (Has self-loop)."; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 51b920f..0878737 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -112,7 +112,7 @@ OptLevelO3("O3", static cl::opt UnitAtATime("funit-at-a-time", cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"), - cl::init(true)); + cl::init(true)); static cl::opt DisableSimplifyLibCalls("disable-simplify-libcalls", @@ -377,24 +377,34 @@ int main(int argc, char **argv) { } // Figure out what stream we are supposed to write to... - // FIXME: outs() is not binary! - raw_ostream *Out = &outs(); // Default to printing to stdout... - if (OutputFilename != "-") { - if (NoOutput || AnalyzeOnly) { - errs() << "WARNING: The -o (output filename) option is ignored when\n" - "the --disable-output or --analyze options are used.\n"; + raw_ostream *Out = 0; + bool DeleteStream = false; + if (!NoOutput && !AnalyzeOnly) { + if (OutputFilename == "-") { + // Print to stdout. + Out = &outs(); + // If we're printing a bitcode file, switch stdout to binary mode. + // FIXME: This switches outs() globally, not just for the bitcode output. + if (!OutputAssembly) + sys::Program::ChangeStdoutToBinary(); } else { - // Make sure that the Output file gets unlinked from the disk if we get a - // SIGINT - sys::RemoveFileOnSignal(sys::Path(OutputFilename)); - - std::string ErrorInfo; - Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, - raw_fd_ostream::F_Binary); - if (!ErrorInfo.empty()) { - errs() << ErrorInfo << '\n'; - delete Out; - return 1; + if (NoOutput || AnalyzeOnly) { + errs() << "WARNING: The -o (output filename) option is ignored when\n" + "the --disable-output or --analyze options are used.\n"; + } else { + // Make sure that the Output file gets unlinked from the disk if we get + // a SIGINT. + sys::RemoveFileOnSignal(sys::Path(OutputFilename)); + + std::string ErrorInfo; + Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo, + raw_fd_ostream::F_Binary); + if (!ErrorInfo.empty()) { + errs() << ErrorInfo << '\n'; + delete Out; + return 1; + } + DeleteStream = true; } } } @@ -540,7 +550,7 @@ int main(int argc, char **argv) { Passes.run(*M.get()); // Delete the raw_fd_ostream. - if (Out != &outs()) + if (DeleteStream) delete Out; return 0; } -- cgit v1.1