diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:19:57 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-07-13 17:19:57 +0000 |
commit | 9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74 (patch) | |
tree | 9de1c5f67a98cd0e73c60838396486c984f63ac2 /tools/bugpoint | |
parent | 1e3dec662ea18131c495db50caccc57f77b7a5fe (diff) | |
download | FreeBSD-src-9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74.zip FreeBSD-src-9112829d76cbb8e0c8ef51bbc2d7d1be48cd7b74.tar.gz |
Update LLVM to r108243.
Diffstat (limited to 'tools/bugpoint')
-rw-r--r-- | tools/bugpoint/BugDriver.h | 6 | ||||
-rw-r--r-- | tools/bugpoint/CrashDebugger.cpp | 31 | ||||
-rw-r--r-- | tools/bugpoint/ExtractFunction.cpp | 28 | ||||
-rw-r--r-- | tools/bugpoint/ListReducer.h | 4 | ||||
-rw-r--r-- | tools/bugpoint/Miscompilation.cpp | 48 | ||||
-rw-r--r-- | tools/bugpoint/ToolRunner.h | 2 |
6 files changed, 59 insertions, 60 deletions
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 <vector> #include <string> @@ -269,7 +269,7 @@ public: /// recreate the failure. This returns true if a compiler error is found. /// bool runManyPasses(const std::vector<const PassInfo*> &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<Function*> &F, - DenseMap<const Value*, Value*> &ValueMap); + ValueMap<const Value*, Value*> &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<GlobalVariable*> &GVs) { // Clone the program to try hacking it apart... - DenseMap<const Value*, Value*> ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... std::set<GlobalVariable*> GVSet; for (unsigned i = 0, e = GVs.size(); i != e; ++i) { - GlobalVariable* CMGV = cast<GlobalVariable>(ValueMap[GVs[i]]); + GlobalVariable* CMGV = cast<GlobalVariable>(VMap[GVs[i]]); assert(CMGV && "Global Variable not in module?!"); GVSet.insert(CMGV); } @@ -204,13 +204,13 @@ bool ReduceCrashingFunctions::TestFuncs(std::vector<Function*> &Funcs) { return false; // Clone the program to try hacking it apart... - DenseMap<const Value*, Value*> ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... std::set<Function*> Functions; for (unsigned i = 0, e = Funcs.size(); i != e; ++i) { - Function *CMF = cast<Function>(ValueMap[Funcs[i]]); + Function *CMF = cast<Function>(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<const BasicBlock*> &BBs) { // Clone the program to try hacking it apart... - DenseMap<const Value*, Value*> ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet<BasicBlock*, 8> Blocks; for (unsigned i = 0, e = BBs.size(); i != e; ++i) - Blocks.insert(cast<BasicBlock>(ValueMap[BBs[i]])); + Blocks.insert(cast<BasicBlock>(VMap[BBs[i]])); outs() << "Checking for crash with only these blocks:"; unsigned NumPrint = Blocks.size(); @@ -298,10 +298,7 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &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<const Instruction*> &Insts) { // Clone the program to try hacking it apart... - DenseMap<const Value*, Value*> ValueMap; - Module *M = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> VMap; + Module *M = CloneModule(BD.getProgram(), VMap); // Convert list to set for fast lookup... SmallPtrSet<Instruction*, 64> Instructions; for (unsigned i = 0, e = Insts.size(); i != e; ++i) { assert(!isa<TerminatorInst>(Insts[i])); - Instructions.insert(cast<Instruction>(ValueMap[Insts[i]])); + Instructions.insert(cast<Instruction>(VMap[Insts[i]])); } outs() << "Checking for crash with only " << Instructions.size(); @@ -395,7 +392,7 @@ bool ReduceCrashingInstructions::TestInsts(std::vector<const Instruction*> for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { Instruction *Inst = I++; if (!Instructions.count(Inst) && !isa<TerminatorInst>(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<const PassInfo*> 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<std::pair<Function*, int> > &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<const Value*, Value*> ValueMap) { + ValueMap<const Value*, Value*> 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<Function>(ValueMap[F]); + F = cast<Function>(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<Function*> &F, - DenseMap<const Value*, Value*> &ValueMap) { + ValueMap<const Value*, Value*> &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<const Value*, Value*> NewValueMap; - Module *New = CloneModule(M, NewValueMap); + ValueMap<const Value*, Value*> 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<Function *> TestFunctions; for (unsigned i = 0, e = F.size(); i != e; ++i) { - Function *TNOF = cast<Function>(ValueMap[F[i]]); + Function *TNOF = cast<Function>(VMap[F[i]]); DEBUG(errs() << "Removing function "); DEBUG(WriteAsOperand(errs(), TNOF, false)); DEBUG(errs() << "\n"); - TestFunctions.insert(cast<Function>(NewValueMap[TNOF])); + TestFunctions.insert(cast<Function>(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<Function*> &Funcs, outs() << '\n'; // Split the module into the two halves of the program we want. - DenseMap<const Value*, Value*> ValueMap; - Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> 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<const Value*, Value*> ValueMap; - Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> 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<BasicBlock*> &BBs, outs() << '\n'; // Split the module into the two halves of the program we want. - DenseMap<const Value*, Value*> ValueMap; - Module *ToNotOptimize = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> 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<const Value*, Value*> ValueMap; - Module *ProgClone = CloneModule(BD.getProgram(), ValueMap); + ValueMap<const Value*, Value*> 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<const Value*, Value*> ValueMap; - Module *ToNotOptimize = CloneModule(getProgram(), ValueMap); + ValueMap<const Value*, Value*> 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<const Value*, Value*> ValueMap; - Module *ToNotCodeGen = CloneModule(getProgram(), ValueMap); - Module *ToCodeGen = SplitFunctionsOutOfModule(ToNotCodeGen, Funcs, ValueMap); + ValueMap<const Value*, Value*> 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<std::string> &GCCArgs = std::vector<std::string>(), unsigned Timeout = 0, |