From b3ecdedbe0ae9a08f9080f9b24d97a6efdf37f99 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Tue, 11 Nov 2008 19:35:38 +0000 Subject: [PATCH] Remove incomplete lto-bugpoint tool. If there is an interest then we can resurrect this tool later on and finish implementation. llvm-svn: 59071 --- tools/lto-bugpoint/LTOBugPoint.cpp | 438 ---------------------------- tools/lto-bugpoint/LTOBugPoint.h | 88 ------ tools/lto-bugpoint/Makefile | 22 -- tools/lto-bugpoint/lto-bugpoint.cpp | 66 ----- 4 files changed, 614 deletions(-) delete mode 100644 tools/lto-bugpoint/LTOBugPoint.cpp delete mode 100644 tools/lto-bugpoint/LTOBugPoint.h delete mode 100644 tools/lto-bugpoint/Makefile delete mode 100644 tools/lto-bugpoint/lto-bugpoint.cpp diff --git a/tools/lto-bugpoint/LTOBugPoint.cpp b/tools/lto-bugpoint/LTOBugPoint.cpp deleted file mode 100644 index 96acf4afd06..00000000000 --- a/tools/lto-bugpoint/LTOBugPoint.cpp +++ /dev/null @@ -1,438 +0,0 @@ -//===- LTOBugPoint.cpp - Top-Level LTO BugPoint class ---------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This class contains all of the shared state and information that is used by -// the LTO BugPoint tool to track down bit code files that cause errors. -// -//===----------------------------------------------------------------------===// - -#include "LTOBugPoint.h" -#include "llvm/PassManager.h" -#include "llvm/ModuleProvider.h" -#include "llvm/CodeGen/FileWriters.h" -#include "llvm/Target/SubtargetFeature.h" -#include "llvm/Target/TargetOptions.h" -#include "llvm/Target/TargetMachine.h" -#include "llvm/Target/TargetData.h" -#include "llvm/Target/TargetAsmInfo.h" -#include "llvm/Target/TargetMachineRegistry.h" -#include "llvm/Support/SystemUtils.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Bitcode/ReaderWriter.h" -#include "llvm/Config/config.h" -#include -#include - -using namespace llvm; -using namespace Reloc; - -/// printBitVector - Helper function. -static void printBitVector(BitVector &BV, const char *Title) { - std::cerr << Title; - for (unsigned i = 0, e = BV.size(); i < e; i++) { - if (BV[i]) - std::cerr << " " << i; - } - std::cerr << "\n"; -} - -/// printBitVector - Helper function. -static void printBitVectorFiles(BitVector &BV, const char *Title, - SmallVector &InFiles) { - std::cerr << Title << "\n"; - for (unsigned i = 0, e = BV.size(); i < e; i++) { - if (BV[i]) - std::cerr << "\t" << InFiles[i] << "\n"; - } -} - -/// LTOBugPoint -- Constructor. Popuate list of linker options and -/// list of linker input files. -LTOBugPoint::LTOBugPoint(std::istream &args, std::istream &ins) { - - // Read linker options. Order is important here. - std::string option; - while (getline(args, option)) - LinkerOptions.push_back(option); - - // Read linker input files. Order is important here. - std::string inFile; - while(getline(ins, inFile)) - LinkerInputFiles.push_back(inFile); - - TempDir = sys::Path::GetTemporaryDirectory(); - - // FIXME - Use command line option to set this. - findLinkingFailure = true; -} - -LTOBugPoint::~LTOBugPoint() { - TempDir.eraseFromDisk(true); -} - -/// findTroubleMakers - Find minimum set of input files that causes error -/// identified by the script. -bool -LTOBugPoint::findTroubleMakers(SmallVector &TroubleMakers, - std::string &Script) { - - // Reproduce original error. - if (!relinkProgram(LinkerInputFiles) && !findLinkingFailure) { - ErrMsg = " Unable to reproduce original error!"; - return false; - } - - if (!findLinkingFailure && !reproduceProgramError(Script)) { - ErrMsg = " Unable to reproduce original error!"; - return false; - } - - // Build native object files set. - unsigned Size = LinkerInputFiles.size(); - BCFiles.resize(Size); - ConfirmedClean.resize(Size); - ConfirmedGuilty.resize(Size); - for (unsigned I = 0; I < Size; ++I) { - std::string &FileName = LinkerInputFiles[I]; - sys::Path InputFile(FileName.c_str()); - if (InputFile.isDynamicLibrary() || InputFile.isArchive()) { - ErrMsg = "Unable to handle input file " + FileName; - return false; - } - else if (InputFile.isBitcodeFile()) { - BCFiles.set(I); - if (getNativeObjectFile(FileName) == false) - return false; - } - else { - // Original native object input files are always clean. - ConfirmedClean.set(I); - NativeInputFiles.push_back(FileName); - } - } - - if (BCFiles.none()) { - ErrMsg = "Unable to help!"; - ErrMsg = " Need at least one input file that contains llvm bitcode"; - return false; - } - - // Try to reproduce error using native object files first. If the error - // occurs then this is not a LTO error. - if (!relinkProgram(NativeInputFiles)) { - ErrMsg = " Unable to link the program using all native object files!"; - return false; - } - if (!findLinkingFailure && reproduceProgramError(Script) == true) { - ErrMsg = " Unable to fix program error using all native object files!"; - return false; - } - - printBitVector(BCFiles, "Initial set of llvm bitcode files"); - identifyTroubleMakers(BCFiles); - printBitVectorFiles(ConfirmedGuilty, - "Identified minimal set of bitcode files!", - LinkerInputFiles); - return true; -} - -/// getFeatureString - Return a string listing the features associated with the -/// target triple. -/// -/// FIXME: This is an inelegant way of specifying the features of a -/// subtarget. It would be better if we could encode this information into the -/// IR. -std::string LTOBugPoint::getFeatureString(const char *TargetTriple) { - SubtargetFeatures Features; - - if (strncmp(TargetTriple, "powerpc-apple-", 14) == 0) { - Features.AddFeature("altivec", true); - } else if (strncmp(TargetTriple, "powerpc64-apple-", 16) == 0) { - Features.AddFeature("64bit", true); - Features.AddFeature("altivec", true); - } - - return Features.getString(); -} - -/// assembleBitcode - Generate assembly code from the module. Return false -/// in case of an error. -bool LTOBugPoint::assembleBitcode(llvm::Module *M, const char *AsmFileName) { - std::string TargetTriple = M->getTargetTriple(); - std::string FeatureStr = - getFeatureString(TargetTriple.c_str()); - - const TargetMachineRegistry::entry* Registry = - TargetMachineRegistry::getClosestStaticTargetForModule( - *M, ErrMsg); - if ( Registry == NULL ) - return false; - - TargetMachine *Target = Registry->CtorFn(*M, FeatureStr.c_str()); - - // If target supports exception handling then enable it now. - if (Target->getTargetAsmInfo()->doesSupportExceptionHandling()) - ExceptionHandling = true; - - // FIXME - Target->setRelocationModel(Reloc::PIC_); - - FunctionPassManager* CGPasses = - new FunctionPassManager(new ExistingModuleProvider(M)); - - CGPasses->add(new TargetData(*Target->getTargetData())); - MachineCodeEmitter* mce = NULL; - - std::string error; - raw_ostream *Out = new raw_fd_ostream(AsmFileName, error); - if (!error.empty()) { - std::cerr << error << '\n'; - delete Out; - return false; - } - - switch (Target->addPassesToEmitFile(*CGPasses, *Out, - TargetMachine::AssemblyFile, true)) { - case FileModel::MachOFile: - mce = AddMachOWriter(*CGPasses, *Out, *Target); - break; - case FileModel::ElfFile: - mce = AddELFWriter(*CGPasses, *Out, *Target); - break; - case FileModel::AsmFile: - break; - case FileModel::Error: - case FileModel::None: - ErrMsg = "target file type not supported"; - return false; - } - - if (Target->addPassesToEmitFileFinish(*CGPasses, mce, true)) { - ErrMsg = "target does not support generation of this file type"; - return false; - } - - CGPasses->doInitialization(); - for (Module::iterator - it = M->begin(), e = M->end(); it != e; ++it) - if (!it->isDeclaration()) - CGPasses->run(*it); - CGPasses->doFinalization(); - delete Out; - return true; -} - -/// getNativeObjectFile - Generate native object file based from llvm -/// bitcode file. Return false in case of an error. -bool LTOBugPoint::getNativeObjectFile(std::string &FileName) { - - std::auto_ptr M; - MemoryBuffer *Buffer - = MemoryBuffer::getFile(FileName.c_str(), &ErrMsg); - if (!Buffer) { - ErrMsg = "Unable to read " + FileName; - return false; - } - M.reset(ParseBitcodeFile(Buffer, &ErrMsg)); - std::string TargetTriple = M->getTargetTriple(); - - sys::Path AsmFile(TempDir); - if(AsmFile.createTemporaryFileOnDisk(false, &ErrMsg)) - return false; - - if (assembleBitcode(M.get(), AsmFile.c_str()) == false) { - AsmFile.eraseFromDisk(); - return false; - } - - sys::Path NativeFile(TempDir); - if(NativeFile.createTemporaryFileOnDisk(false, &ErrMsg)) { - AsmFile.eraseFromDisk(); - return false; - } - - // find compiler driver - const sys::Path gcc = sys::Program::FindProgramByName("gcc"); - if ( gcc.isEmpty() ) { - ErrMsg = "can't locate gcc"; - AsmFile.eraseFromDisk(); - NativeFile.eraseFromDisk(); - return false; - } - - // build argument list - std::vector args; - args.push_back(gcc.c_str()); - if ( TargetTriple.find("darwin") != TargetTriple.size() ) { - if (strncmp(TargetTriple.c_str(), "i686-apple-", 11) == 0) { - args.push_back("-arch"); - args.push_back("i386"); - } - else if (strncmp(TargetTriple.c_str(), "x86_64-apple-", 13) == 0) { - args.push_back("-arch"); - args.push_back("x86_64"); - } - else if (strncmp(TargetTriple.c_str(), "powerpc-apple-", 14) == 0) { - args.push_back("-arch"); - args.push_back("ppc"); - } - else if (strncmp(TargetTriple.c_str(), "powerpc64-apple-", 16) == 0) { - args.push_back("-arch"); - args.push_back("ppc64"); - } - } - args.push_back("-c"); - args.push_back("-x"); - args.push_back("assembler"); - args.push_back("-o"); - args.push_back(NativeFile.c_str()); - args.push_back(AsmFile.c_str()); - args.push_back(0); - - // invoke assembler - if (sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 0, 0, &ErrMsg)) { - ErrMsg = "error in assembly"; - AsmFile.eraseFromDisk(); - NativeFile.eraseFromDisk(); - return false; - } - - AsmFile.eraseFromDisk(); - NativeInputFiles.push_back(NativeFile.c_str()); - return true; -} - -/// relinkProgram - Relink program. Return false if linking fails. -bool LTOBugPoint::relinkProgram(llvm::SmallVector &InFiles) { - if (InFiles.empty()) - return false; - - // Atleast three options: linker path, -o and output file name. - if (LinkerOptions.size() < 3) - return false; - - const sys::Path linker = sys::Program::FindProgramByName(LinkerOptions[0]); - if (linker.isEmpty()) { - ErrMsg = "can't locate linker"; - return false; - } - - std::vector Args; - for (unsigned i = 0, e = LinkerOptions.size(); i < e; ++i) - Args.push_back(LinkerOptions[i].c_str()); - - for (unsigned i = 0, e = InFiles.size(); i < e; ++i) - Args.push_back(InFiles[i].c_str()); - - Args.push_back(0); - - if (sys::Program::ExecuteAndWait(linker, &Args[0], 0, 0, 0, 0, &ErrMsg)) { - ErrMsg = "error while linking program"; - return false; - } - return true; -} - -/// reproduceProgramError - Validate program using user provided script. -/// Return true if program error is reproduced. -bool LTOBugPoint::reproduceProgramError(std::string &Script) { - - const sys::Path validator = sys::Program::FindProgramByName(Script); - if (validator.isEmpty()) { - ErrMsg = "can't locate validation script"; - return false; - } - - std::vector Args; - Args.push_back(Script.c_str()); - Args.push_back(0); - - int result = - sys::Program::ExecuteAndWait(validator, &Args[0], 0, 0, 0, 0, &ErrMsg); - - // Validation scrip returns non-zero if the error is reproduced. - if (result > 0) - // Able to reproduce program error. - return true; - - else if (result < 0) - // error occured while running validation script. ErrMsg contains error - // description. - return false; - - return false; -} - -/// identifyTroubleMakers - Identify set of bit code files that are causing -/// the error. This is a recursive function. -void LTOBugPoint::identifyTroubleMakers(llvm::BitVector &In) { - - assert (In.size() == LinkerInputFiles.size() - && "Invalid identifyTroubleMakers input!\n"); - - printBitVector(In, "Processing files "); - BitVector CandidateVector; - CandidateVector.resize(LinkerInputFiles.size()); - - // Process first half - unsigned count = 0; - for (unsigned i = 0, e = In.size(); i < e; ++i) { - if (!ConfirmedClean[i]) { - count++; - CandidateVector.set(i); - } - if (count >= In.count()/2) - break; - } - - if (CandidateVector.none()) - return; - - printBitVector(CandidateVector, "Candidate vector "); - - // Reproduce the error using native object files for candidate files. - SmallVector CandidateFiles; - for (unsigned i = 0, e = CandidateVector.size(); i < e; ++i) { - if (CandidateVector[i] || ConfirmedClean[i]) - CandidateFiles.push_back(NativeInputFiles[i]); - else - CandidateFiles.push_back(LinkerInputFiles[i]); - } - - bool result = relinkProgram(CandidateFiles); - if (findLinkingFailure) { - if (result == true) { - // Candidate files are suspected. - if (CandidateVector.count() == 1) { - ConfirmedGuilty.set(CandidateVector.find_first()); - return; - } - else - identifyTroubleMakers(CandidateVector); - } else { - // Candidate files are not causing this error. - for (unsigned i = 0, e = CandidateVector.size(); i < e; ++i) { - if (CandidateVector[i]) - ConfirmedClean.set(i); - } - } - } else { - std::cerr << "FIXME : Not yet implemented!\n"; - } - - // Process remaining cadidates - CandidateVector.clear(); - CandidateVector.resize(LinkerInputFiles.size()); - for (unsigned i = 0, e = LinkerInputFiles.size(); i < e; ++i) { - if (!ConfirmedClean[i] && !ConfirmedGuilty[i]) - CandidateVector.set(i); - } - identifyTroubleMakers(CandidateVector); -} diff --git a/tools/lto-bugpoint/LTOBugPoint.h b/tools/lto-bugpoint/LTOBugPoint.h deleted file mode 100644 index 41791243096..00000000000 --- a/tools/lto-bugpoint/LTOBugPoint.h +++ /dev/null @@ -1,88 +0,0 @@ -//===- LTOBugPoint.h - Top-Level LTO BugPoint class -------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This class contains all of the shared state and information that is used by -// the LTO BugPoint tool to track down bit code files that cause errors. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/BitVector.h" -#include "llvm/Module.h" -#include "llvm/System/Path.h" -#include -#include - -class LTOBugPoint { - public: - - LTOBugPoint(std::istream &args, std::istream &ins); - ~LTOBugPoint(); - - /// findTroubleMakers - Find minimum set of input files that causes error - /// identified by the script. - bool findTroubleMakers(llvm::SmallVector &TroubleMakers, - std::string &Script); - - /// getNativeObjectFile - Generate native object file based from llvm - /// bitcode file. Return false in case of an error. Generated native - /// object file is inserted in to the NativeInputFiles list. - bool getNativeObjectFile(std::string &FileName); - - std::string &getErrMsg() { return ErrMsg; } - - private: - /// LinkerInputFiles - This is a list of linker input files. Once populated - /// this list is not modified. - llvm::SmallVector LinkerInputFiles; - - /// LinkerOptions - List of linker command line options. - llvm::SmallVector LinkerOptions; - - /// NativeInputFiles - This is a list of input files that are not llvm - /// bitcode files. The order in this list is important. The a file - /// in LinkerInputFiles at index 4 is a llvm bitcode file then the file - /// at index 4 in NativeInputFiles is corresponding native object file. - llvm::SmallVector NativeInputFiles; - - /// BCFiles - This bit vector tracks input bitcode files. - llvm::BitVector BCFiles; - - /// ConfirmedClean - This bit vector tracks input files that are confirmed - /// to be clean. - llvm::BitVector ConfirmedClean; - - /// ConfirmedGuilty - This bit vector tracks input files that are confirmed - /// to contribute to the bug being investigated. - llvm::BitVector ConfirmedGuilty; - std::string getFeatureString(const char *TargetTriple); - std::string ErrMsg; - - llvm::sys::Path TempDir; - - /// findLinkingFailure - If true, investigate link failure bugs when - /// one or more linker input files are llvm bitcode files. If false, - /// investigate optimization or code generation bugs in LTO mode. - bool findLinkingFailure; - -private: - /// assembleBitcode - Generate assembly code from the module. Return false - /// in case of an error. - bool assembleBitcode(llvm::Module *M, const char *AsmFileName); - - /// relinkProgram - Relink program. Return false if linking fails. - bool relinkProgram(llvm::SmallVector &InputFiles); - - /// reproduceProgramError - Validate program using user provided script. - bool reproduceProgramError(std::string &Script); - - /// identifyTroubleMakers - Identify set of inputs from the given - /// bitvector that are causing the bug under investigation. - void identifyTroubleMakers(llvm::BitVector &In); -}; diff --git a/tools/lto-bugpoint/Makefile b/tools/lto-bugpoint/Makefile deleted file mode 100644 index 6a08c919c01..00000000000 --- a/tools/lto-bugpoint/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -##===- tools/lto-bugpoint/Makefile -------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## -LEVEL = ../.. - -TOOLNAME = lto-bugpoint - -# Include this here so we can get the configuration of the targets -# that have been configured for construction. We have to do this -# early so we can set up LINK_COMPONENTS before including Makefile.rules -include $(LEVEL)/Makefile.config - -LINK_COMPONENTS := $(TARGETS_TO_BUILD) bitreader - -REQUIRES_EH := 1 - -include $(LEVEL)/Makefile.common diff --git a/tools/lto-bugpoint/lto-bugpoint.cpp b/tools/lto-bugpoint/lto-bugpoint.cpp deleted file mode 100644 index 230d3eb44f1..00000000000 --- a/tools/lto-bugpoint/lto-bugpoint.cpp +++ /dev/null @@ -1,66 +0,0 @@ -//===- lto-bugpoing.cpp - The lto-bugpoint driver -------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// lto-bugpoint tool identifies minmal set of bitcode files that is causing -// failure when Link Time Optimization is enabled. The failure is identified -// using developer provided validation script. -// -//===----------------------------------------------------------------------===// - -#include "LTOBugPoint.h" -#include -#include - -int main(int argc, char **argv) { - try { - - if (argc != 4) { - std::cerr << "Invalid number of lto-bugpoint arguments!\n"; - return 1; - } - - std::ios::openmode input_mode = std::ios::in; - - // First argument is linker command line options file. This text file - // is a list of linker command line options, one option per line. - // First line always list the absolute path to invoke the linker. - std::istream *LinkerArgsFile = new std::ifstream(argv[1], input_mode); - if (!LinkerArgsFile->good()) { - std::cerr << argv[0] << ": error opening " << argv[1] << "!\n"; - return 1; - } - - // Second argment is a text file that includes the linker input - // file paths, one input file path per line. - std::istream *LinkerInputsFile = new std::ifstream(argv[2], input_mode); - if (!LinkerInputsFile->good()) { - std::cerr << argv[0] << ": error opening " << argv[2] << "!\n"; - delete LinkerArgsFile; - return 1; - } - - // Third argument is absolute path to the validation script. This - // script is used to validate LTO error under investigation. - std::string ValidationScript = argv[3]; - LTOBugPoint bugFinder(*LinkerArgsFile, *LinkerInputsFile); - - llvm::SmallVector TroubleMakers; - if (!bugFinder.findTroubleMakers(TroubleMakers, ValidationScript)) { - std::cerr << "lto-bugpoint:" << bugFinder.getErrMsg() << "\n"; - return 1; - } - - return 0; - } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; - } catch (...) { - std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; - } - return 1; -}