Devang Patel | e330f2d | 2008-07-18 22:59:45 +0000 | [diff] [blame] | 1 | //===- LTOBugPoint.h - Top-Level LTO BugPoint class -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This class contains all of the shared state and information that is used by |
| 11 | // the LTO BugPoint tool to track down bit code files that cause errors. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/ADT/SmallVector.h" |
Devang Patel | cfb5410 | 2008-07-24 00:34:11 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/BitVector.h" |
Devang Patel | 4f574f5 | 2008-07-21 23:04:39 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Devang Patel | 35b39b4f | 2008-07-22 20:03:45 +0000 | [diff] [blame] | 18 | #include "llvm/System/Path.h" |
Devang Patel | e330f2d | 2008-07-18 22:59:45 +0000 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <fstream> |
| 21 | |
| 22 | class LTOBugPoint { |
| 23 | public: |
| 24 | |
| 25 | LTOBugPoint(std::istream &args, std::istream &ins); |
Devang Patel | 35b39b4f | 2008-07-22 20:03:45 +0000 | [diff] [blame] | 26 | ~LTOBugPoint(); |
Devang Patel | e330f2d | 2008-07-18 22:59:45 +0000 | [diff] [blame] | 27 | |
Devang Patel | 5dd66a0 | 2008-07-18 23:46:41 +0000 | [diff] [blame] | 28 | /// findTroubleMakers - Find minimum set of input files that causes error |
| 29 | /// identified by the script. |
| 30 | bool findTroubleMakers(llvm::SmallVector<std::string, 4> &TroubleMakers, |
| 31 | std::string &Script); |
Devang Patel | 4f574f5 | 2008-07-21 23:04:39 +0000 | [diff] [blame] | 32 | |
| 33 | /// getNativeObjectFile - Generate native object file based from llvm |
Devang Patel | cfb5410 | 2008-07-24 00:34:11 +0000 | [diff] [blame] | 34 | /// bitcode file. Return false in case of an error. Generated native |
| 35 | /// object file is inserted in to the NativeInputFiles list. |
Devang Patel | 4f574f5 | 2008-07-21 23:04:39 +0000 | [diff] [blame] | 36 | bool getNativeObjectFile(std::string &FileName); |
| 37 | |
| 38 | std::string &getErrMsg() { return ErrMsg; } |
| 39 | |
Devang Patel | e330f2d | 2008-07-18 22:59:45 +0000 | [diff] [blame] | 40 | private: |
| 41 | /// LinkerInputFiles - This is a list of linker input files. Once populated |
| 42 | /// this list is not modified. |
| 43 | llvm::SmallVector<std::string, 16> LinkerInputFiles; |
Devang Patel | 5dd66a0 | 2008-07-18 23:46:41 +0000 | [diff] [blame] | 44 | |
| 45 | /// LinkerOptions - List of linker command line options. |
Devang Patel | e330f2d | 2008-07-18 22:59:45 +0000 | [diff] [blame] | 46 | llvm::SmallVector<std::string, 16> LinkerOptions; |
| 47 | |
Devang Patel | 5dd66a0 | 2008-07-18 23:46:41 +0000 | [diff] [blame] | 48 | /// NativeInputFiles - This is a list of input files that are not llvm |
| 49 | /// bitcode files. The order in this list is important. The a file |
| 50 | /// in LinkerInputFiles at index 4 is a llvm bitcode file then the file |
| 51 | /// at index 4 in NativeInputFiles is corresponding native object file. |
| 52 | llvm::SmallVector<std::string, 16> NativeInputFiles; |
| 53 | |
Devang Patel | cfb5410 | 2008-07-24 00:34:11 +0000 | [diff] [blame] | 54 | /// BCFiles - This bit vector tracks input bitcode files. |
| 55 | llvm::BitVector BCFiles; |
| 56 | |
| 57 | /// ConfirmedClean - This bit vector tracks input files that are confirmed |
| 58 | /// to be clean. |
| 59 | llvm::BitVector ConfirmedClean; |
| 60 | |
| 61 | /// ConfirmedGuilty - This bit vector tracks input files that are confirmed |
| 62 | /// to contribute to the bug being investigated. |
| 63 | llvm::BitVector ConfirmedGuilty; |
Devang Patel | 4f574f5 | 2008-07-21 23:04:39 +0000 | [diff] [blame] | 64 | std::string getFeatureString(const char *TargetTriple); |
| 65 | std::string ErrMsg; |
| 66 | |
Devang Patel | 35b39b4f | 2008-07-22 20:03:45 +0000 | [diff] [blame] | 67 | llvm::sys::Path TempDir; |
Devang Patel | cfb5410 | 2008-07-24 00:34:11 +0000 | [diff] [blame] | 68 | |
| 69 | /// findLinkingFailure - If true, investigate link failure bugs when |
| 70 | /// one or more linker input files are llvm bitcode files. If false, |
| 71 | /// investigate optimization or code generation bugs in LTO mode. |
| 72 | bool findLinkingFailure; |
| 73 | |
Devang Patel | 4f574f5 | 2008-07-21 23:04:39 +0000 | [diff] [blame] | 74 | private: |
| 75 | /// assembleBitcode - Generate assembly code from the module. Return false |
| 76 | /// in case of an error. |
| 77 | bool assembleBitcode(llvm::Module *M, const char *AsmFileName); |
Devang Patel | a11ec25 | 2008-07-22 22:20:18 +0000 | [diff] [blame] | 78 | |
| 79 | /// relinkProgram - Relink program. Return false if linking fails. |
| 80 | bool relinkProgram(llvm::SmallVector<std::string, 16> &InputFiles); |
| 81 | |
| 82 | /// reproduceProgramError - Validate program using user provided script. |
| 83 | bool reproduceProgramError(std::string &Script); |
Devang Patel | cfb5410 | 2008-07-24 00:34:11 +0000 | [diff] [blame] | 84 | |
| 85 | /// identifyTroubleMakers - Identify set of inputs from the given |
| 86 | /// bitvector that are causing the bug under investigation. |
| 87 | void identifyTroubleMakers(llvm::BitVector &In); |
Devang Patel | e330f2d | 2008-07-18 22:59:45 +0000 | [diff] [blame] | 88 | }; |