Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 1 | //===-- llvm-bcanalyzer.cpp - Bitcode Analyzer --------------------------===// |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 345353d | 2007-12-29 20:44:31 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame] | 10 | // This tool may be invoked in the following manner: |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 11 | // llvm-bcanalyzer [options] - Read LLVM bitcode from stdin |
| 12 | // llvm-bcanalyzer [options] x.bc - Read LLVM bitcode from the x.bc file |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 13 | // |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame] | 14 | // Options: |
Reid Spencer | b3a4e0b | 2004-06-10 18:38:44 +0000 | [diff] [blame] | 15 | // --help - Output information about command line switches |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 16 | // --dump - Dump low-level bitcode structure in readable format |
Reid Spencer | ddc6fb1 | 2004-06-08 05:56:58 +0000 | [diff] [blame] | 17 | // |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 18 | // This tool provides analytical information about a bitcode file. It is |
| 19 | // intended as an aid to developers of bitcode reading and writing software. It |
| 20 | // produces on std::out a summary of the bitcode file that shows various |
Reid Spencer | b3a4e0b | 2004-06-10 18:38:44 +0000 | [diff] [blame] | 21 | // statistics about the contents of the file. By default this information is |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 22 | // detailed and contains information about individual bitcode blocks and the |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 23 | // functions in the module. |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 24 | // The tool is also able to print a bitcode file in a straight forward text |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 25 | // format that shows the containment and relationships of the information in |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 26 | // the bitcode file (-dump option). |
Chris Lattner | cc18989 | 2007-04-29 05:51:00 +0000 | [diff] [blame] | 27 | // |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringExtras.h" |
Teresa Johnson | ad17679 | 2016-11-11 05:34:58 +0000 | [diff] [blame^] | 31 | #include "llvm/Bitcode/BitcodeReader.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 32 | #include "llvm/Bitcode/BitstreamReader.h" |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 33 | #include "llvm/Bitcode/LLVMBitCodes.h" |
Chandler Carruth | 5ad5f15 | 2014-01-13 09:26:24 +0000 | [diff] [blame] | 34 | #include "llvm/IR/Verifier.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 35 | #include "llvm/Support/CommandLine.h" |
Daniel Dunbar | e813b22 | 2009-09-25 16:04:21 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Format.h" |
Chris Lattner | 76d4632 | 2006-12-06 01:18:01 +0000 | [diff] [blame] | 37 | #include "llvm/Support/ManagedStatic.h" |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 38 | #include "llvm/Support/MemoryBuffer.h" |
Chris Lattner | e3fc2d1 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 39 | #include "llvm/Support/PrettyStackTrace.h" |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 40 | #include "llvm/Support/SHA1.h" |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 41 | #include "llvm/Support/Signals.h" |
Chandler Carruth | 4d88a1c | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 42 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 43 | #include <algorithm> |
Will Dietz | 981af00 | 2013-10-12 00:55:57 +0000 | [diff] [blame] | 44 | #include <cctype> |
Chandler Carruth | 4d88a1c | 2012-12-04 10:44:52 +0000 | [diff] [blame] | 45 | #include <map> |
Rafael Espindola | a6e9c3e | 2014-06-12 17:38:55 +0000 | [diff] [blame] | 46 | #include <system_error> |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 47 | using namespace llvm; |
| 48 | |
| 49 | static cl::opt<std::string> |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 50 | InputFilename(cl::Positional, cl::desc("<input bitcode>"), cl::init("-")); |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 51 | |
Gabor Greif | 0e535c3c | 2007-07-04 21:55:50 +0000 | [diff] [blame] | 52 | static cl::opt<bool> Dump("dump", cl::desc("Dump low level bitcode trace")); |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 53 | |
| 54 | //===----------------------------------------------------------------------===// |
| 55 | // Bitcode specific analysis. |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 58 | static cl::opt<bool> NoHistogram("disable-histogram", |
| 59 | cl::desc("Do not print per-code histogram")); |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 61 | static cl::opt<bool> |
| 62 | NonSymbolic("non-symbolic", |
Michael J. Spencer | 39a0ffc | 2010-12-16 03:29:14 +0000 | [diff] [blame] | 63 | cl::desc("Emit numeric info in dump even if" |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 64 | " symbolic info is available")); |
| 65 | |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 66 | static cl::opt<std::string> |
| 67 | BlockInfoFilename("block-info", |
| 68 | cl::desc("Use the BLOCK_INFO from the given file")); |
| 69 | |
Jordan Rose | 0fa38b8 | 2015-05-13 18:51:49 +0000 | [diff] [blame] | 70 | static cl::opt<bool> |
| 71 | ShowBinaryBlobs("show-binary-blobs", |
| 72 | cl::desc("Print binary blobs using hex escapes")); |
| 73 | |
Dan Gohman | f749ad7 | 2010-12-09 20:35:40 +0000 | [diff] [blame] | 74 | namespace { |
| 75 | |
| 76 | /// CurStreamTypeType - A type for CurStreamType |
| 77 | enum CurStreamTypeType { |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 78 | UnknownBitstream, |
| 79 | LLVMIRBitstream |
Dan Gohman | f749ad7 | 2010-12-09 20:35:40 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | } |
| 83 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 84 | /// GetBlockName - Return a symbolic block name if known, otherwise return |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 85 | /// null. |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 86 | static const char *GetBlockName(unsigned BlockID, |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 87 | const BitstreamBlockInfo &BlockInfo, |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 88 | CurStreamTypeType CurStreamType) { |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 89 | // Standard blocks for all bitcode files. |
| 90 | if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) { |
| 91 | if (BlockID == bitc::BLOCKINFO_BLOCK_ID) |
| 92 | return "BLOCKINFO_BLOCK"; |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 93 | return nullptr; |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 94 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 95 | |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 96 | // Check to see if we have a blockinfo record for this block, with a name. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 97 | if (const BitstreamBlockInfo::BlockInfo *Info = |
| 98 | BlockInfo.getBlockInfo(BlockID)) { |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 99 | if (!Info->Name.empty()) |
| 100 | return Info->Name.c_str(); |
| 101 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 102 | |
| 103 | |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 104 | if (CurStreamType != LLVMIRBitstream) return nullptr; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 106 | switch (BlockID) { |
Sanjoy Das | 65c1332 | 2016-04-26 05:59:14 +0000 | [diff] [blame] | 107 | default: return nullptr; |
Sanjoy Das | 51df5fa | 2016-04-26 05:59:08 +0000 | [diff] [blame] | 108 | case bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID: return "OPERAND_BUNDLE_TAGS_BLOCK"; |
Sanjoy Das | 65c1332 | 2016-04-26 05:59:14 +0000 | [diff] [blame] | 109 | case bitc::MODULE_BLOCK_ID: return "MODULE_BLOCK"; |
| 110 | case bitc::PARAMATTR_BLOCK_ID: return "PARAMATTR_BLOCK"; |
| 111 | case bitc::PARAMATTR_GROUP_BLOCK_ID: return "PARAMATTR_GROUP_BLOCK_ID"; |
| 112 | case bitc::TYPE_BLOCK_ID_NEW: return "TYPE_BLOCK_ID"; |
| 113 | case bitc::CONSTANTS_BLOCK_ID: return "CONSTANTS_BLOCK"; |
| 114 | case bitc::FUNCTION_BLOCK_ID: return "FUNCTION_BLOCK"; |
Mehdi Amini | 5d30328 | 2015-10-26 18:37:00 +0000 | [diff] [blame] | 115 | case bitc::IDENTIFICATION_BLOCK_ID: |
Sanjoy Das | 65c1332 | 2016-04-26 05:59:14 +0000 | [diff] [blame] | 116 | return "IDENTIFICATION_BLOCK_ID"; |
| 117 | case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB"; |
| 118 | case bitc::METADATA_BLOCK_ID: return "METADATA_BLOCK"; |
| 119 | case bitc::METADATA_KIND_BLOCK_ID: return "METADATA_KIND_BLOCK"; |
| 120 | case bitc::METADATA_ATTACHMENT_ID: return "METADATA_ATTACHMENT_BLOCK"; |
| 121 | case bitc::USELIST_BLOCK_ID: return "USELIST_BLOCK_ID"; |
Teresa Johnson | 76a1c1d | 2016-03-11 18:52:24 +0000 | [diff] [blame] | 122 | case bitc::GLOBALVAL_SUMMARY_BLOCK_ID: |
Sanjoy Das | 65c1332 | 2016-04-26 05:59:14 +0000 | [diff] [blame] | 123 | return "GLOBALVAL_SUMMARY_BLOCK"; |
| 124 | case bitc::MODULE_STRTAB_BLOCK_ID: return "MODULE_STRTAB_BLOCK"; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 128 | /// GetCodeName - Return a symbolic code name if known, otherwise return |
| 129 | /// null. |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 130 | static const char *GetCodeName(unsigned CodeID, unsigned BlockID, |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 131 | const BitstreamBlockInfo &BlockInfo, |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 132 | CurStreamTypeType CurStreamType) { |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 133 | // Standard blocks for all bitcode files. |
| 134 | if (BlockID < bitc::FIRST_APPLICATION_BLOCKID) { |
| 135 | if (BlockID == bitc::BLOCKINFO_BLOCK_ID) { |
| 136 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 137 | default: return nullptr; |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 138 | case bitc::BLOCKINFO_CODE_SETBID: return "SETBID"; |
| 139 | case bitc::BLOCKINFO_CODE_BLOCKNAME: return "BLOCKNAME"; |
| 140 | case bitc::BLOCKINFO_CODE_SETRECORDNAME: return "SETRECORDNAME"; |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 141 | } |
| 142 | } |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 143 | return nullptr; |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 144 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 145 | |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 146 | // Check to see if we have a blockinfo record for this record, with a name. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 147 | if (const BitstreamBlockInfo::BlockInfo *Info = |
| 148 | BlockInfo.getBlockInfo(BlockID)) { |
Chris Lattner | a6fdf5a | 2009-04-26 22:21:57 +0000 | [diff] [blame] | 149 | for (unsigned i = 0, e = Info->RecordNames.size(); i != e; ++i) |
| 150 | if (Info->RecordNames[i].first == CodeID) |
| 151 | return Info->RecordNames[i].second.c_str(); |
| 152 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 153 | |
| 154 | |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 155 | if (CurStreamType != LLVMIRBitstream) return nullptr; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 156 | |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 157 | #define STRINGIFY_CODE(PREFIX, CODE) \ |
| 158 | case bitc::PREFIX##_##CODE: \ |
| 159 | return #CODE; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 160 | switch (BlockID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 161 | default: return nullptr; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 162 | case bitc::MODULE_BLOCK_ID: |
| 163 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 164 | default: return nullptr; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 165 | STRINGIFY_CODE(MODULE_CODE, VERSION) |
| 166 | STRINGIFY_CODE(MODULE_CODE, TRIPLE) |
| 167 | STRINGIFY_CODE(MODULE_CODE, DATALAYOUT) |
| 168 | STRINGIFY_CODE(MODULE_CODE, ASM) |
| 169 | STRINGIFY_CODE(MODULE_CODE, SECTIONNAME) |
| 170 | STRINGIFY_CODE(MODULE_CODE, DEPLIB) // FIXME: Remove in 4.0 |
| 171 | STRINGIFY_CODE(MODULE_CODE, GLOBALVAR) |
| 172 | STRINGIFY_CODE(MODULE_CODE, FUNCTION) |
| 173 | STRINGIFY_CODE(MODULE_CODE, ALIAS) |
| 174 | STRINGIFY_CODE(MODULE_CODE, PURGEVALS) |
| 175 | STRINGIFY_CODE(MODULE_CODE, GCNAME) |
Teresa Johnson | ff642b9 | 2015-09-17 20:12:00 +0000 | [diff] [blame] | 176 | STRINGIFY_CODE(MODULE_CODE, VSTOFFSET) |
Duncan P. N. Exon Smith | 68f5624 | 2016-03-25 01:29:50 +0000 | [diff] [blame] | 177 | STRINGIFY_CODE(MODULE_CODE, METADATA_VALUES_UNUSED) |
Teresa Johnson | e1164de | 2016-02-10 21:55:02 +0000 | [diff] [blame] | 178 | STRINGIFY_CODE(MODULE_CODE, SOURCE_FILENAME) |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 179 | STRINGIFY_CODE(MODULE_CODE, HASH) |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 180 | } |
Mehdi Amini | 5d30328 | 2015-10-26 18:37:00 +0000 | [diff] [blame] | 181 | case bitc::IDENTIFICATION_BLOCK_ID: |
| 182 | switch (CodeID) { |
| 183 | default: |
| 184 | return nullptr; |
| 185 | STRINGIFY_CODE(IDENTIFICATION_CODE, STRING) |
| 186 | STRINGIFY_CODE(IDENTIFICATION_CODE, EPOCH) |
| 187 | } |
Chris Lattner | 0b7c512 | 2007-05-04 03:01:41 +0000 | [diff] [blame] | 188 | case bitc::PARAMATTR_BLOCK_ID: |
| 189 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 190 | default: return nullptr; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 191 | // FIXME: Should these be different? |
Bill Wendling | d7e05d6 | 2013-02-10 23:17:10 +0000 | [diff] [blame] | 192 | case bitc::PARAMATTR_CODE_ENTRY_OLD: return "ENTRY"; |
| 193 | case bitc::PARAMATTR_CODE_ENTRY: return "ENTRY"; |
Justin Bogner | 68b28d0 | 2016-03-15 22:37:25 +0000 | [diff] [blame] | 194 | } |
| 195 | case bitc::PARAMATTR_GROUP_BLOCK_ID: |
| 196 | switch (CodeID) { |
| 197 | default: return nullptr; |
Bill Wendling | d7e05d6 | 2013-02-10 23:17:10 +0000 | [diff] [blame] | 198 | case bitc::PARAMATTR_GRP_CODE_ENTRY: return "ENTRY"; |
Chris Lattner | 0b7c512 | 2007-05-04 03:01:41 +0000 | [diff] [blame] | 199 | } |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 200 | case bitc::TYPE_BLOCK_ID_NEW: |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 201 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 202 | default: return nullptr; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 203 | STRINGIFY_CODE(TYPE_CODE, NUMENTRY) |
| 204 | STRINGIFY_CODE(TYPE_CODE, VOID) |
| 205 | STRINGIFY_CODE(TYPE_CODE, FLOAT) |
| 206 | STRINGIFY_CODE(TYPE_CODE, DOUBLE) |
| 207 | STRINGIFY_CODE(TYPE_CODE, LABEL) |
| 208 | STRINGIFY_CODE(TYPE_CODE, OPAQUE) |
| 209 | STRINGIFY_CODE(TYPE_CODE, INTEGER) |
| 210 | STRINGIFY_CODE(TYPE_CODE, POINTER) |
| 211 | STRINGIFY_CODE(TYPE_CODE, ARRAY) |
| 212 | STRINGIFY_CODE(TYPE_CODE, VECTOR) |
| 213 | STRINGIFY_CODE(TYPE_CODE, X86_FP80) |
| 214 | STRINGIFY_CODE(TYPE_CODE, FP128) |
| 215 | STRINGIFY_CODE(TYPE_CODE, PPC_FP128) |
| 216 | STRINGIFY_CODE(TYPE_CODE, METADATA) |
| 217 | STRINGIFY_CODE(TYPE_CODE, STRUCT_ANON) |
| 218 | STRINGIFY_CODE(TYPE_CODE, STRUCT_NAME) |
| 219 | STRINGIFY_CODE(TYPE_CODE, STRUCT_NAMED) |
| 220 | STRINGIFY_CODE(TYPE_CODE, FUNCTION) |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 221 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 222 | |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 223 | case bitc::CONSTANTS_BLOCK_ID: |
| 224 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 225 | default: return nullptr; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 226 | STRINGIFY_CODE(CST_CODE, SETTYPE) |
| 227 | STRINGIFY_CODE(CST_CODE, NULL) |
| 228 | STRINGIFY_CODE(CST_CODE, UNDEF) |
| 229 | STRINGIFY_CODE(CST_CODE, INTEGER) |
| 230 | STRINGIFY_CODE(CST_CODE, WIDE_INTEGER) |
| 231 | STRINGIFY_CODE(CST_CODE, FLOAT) |
| 232 | STRINGIFY_CODE(CST_CODE, AGGREGATE) |
| 233 | STRINGIFY_CODE(CST_CODE, STRING) |
| 234 | STRINGIFY_CODE(CST_CODE, CSTRING) |
| 235 | STRINGIFY_CODE(CST_CODE, CE_BINOP) |
| 236 | STRINGIFY_CODE(CST_CODE, CE_CAST) |
| 237 | STRINGIFY_CODE(CST_CODE, CE_GEP) |
| 238 | STRINGIFY_CODE(CST_CODE, CE_INBOUNDS_GEP) |
| 239 | STRINGIFY_CODE(CST_CODE, CE_SELECT) |
| 240 | STRINGIFY_CODE(CST_CODE, CE_EXTRACTELT) |
| 241 | STRINGIFY_CODE(CST_CODE, CE_INSERTELT) |
| 242 | STRINGIFY_CODE(CST_CODE, CE_SHUFFLEVEC) |
| 243 | STRINGIFY_CODE(CST_CODE, CE_CMP) |
| 244 | STRINGIFY_CODE(CST_CODE, INLINEASM) |
| 245 | STRINGIFY_CODE(CST_CODE, CE_SHUFVEC_EX) |
Chris Lattner | 372dd1e | 2012-01-30 00:51:16 +0000 | [diff] [blame] | 246 | case bitc::CST_CODE_BLOCKADDRESS: return "CST_CODE_BLOCKADDRESS"; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 247 | STRINGIFY_CODE(CST_CODE, DATA) |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 248 | } |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 249 | case bitc::FUNCTION_BLOCK_ID: |
| 250 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 251 | default: return nullptr; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 252 | STRINGIFY_CODE(FUNC_CODE, DECLAREBLOCKS) |
| 253 | STRINGIFY_CODE(FUNC_CODE, INST_BINOP) |
| 254 | STRINGIFY_CODE(FUNC_CODE, INST_CAST) |
| 255 | STRINGIFY_CODE(FUNC_CODE, INST_GEP_OLD) |
| 256 | STRINGIFY_CODE(FUNC_CODE, INST_INBOUNDS_GEP_OLD) |
| 257 | STRINGIFY_CODE(FUNC_CODE, INST_SELECT) |
| 258 | STRINGIFY_CODE(FUNC_CODE, INST_EXTRACTELT) |
| 259 | STRINGIFY_CODE(FUNC_CODE, INST_INSERTELT) |
| 260 | STRINGIFY_CODE(FUNC_CODE, INST_SHUFFLEVEC) |
| 261 | STRINGIFY_CODE(FUNC_CODE, INST_CMP) |
| 262 | STRINGIFY_CODE(FUNC_CODE, INST_RET) |
| 263 | STRINGIFY_CODE(FUNC_CODE, INST_BR) |
| 264 | STRINGIFY_CODE(FUNC_CODE, INST_SWITCH) |
| 265 | STRINGIFY_CODE(FUNC_CODE, INST_INVOKE) |
| 266 | STRINGIFY_CODE(FUNC_CODE, INST_UNREACHABLE) |
David Majnemer | 654e130 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 267 | STRINGIFY_CODE(FUNC_CODE, INST_CLEANUPRET) |
| 268 | STRINGIFY_CODE(FUNC_CODE, INST_CATCHRET) |
| 269 | STRINGIFY_CODE(FUNC_CODE, INST_CATCHPAD) |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 270 | STRINGIFY_CODE(FUNC_CODE, INST_PHI) |
| 271 | STRINGIFY_CODE(FUNC_CODE, INST_ALLOCA) |
| 272 | STRINGIFY_CODE(FUNC_CODE, INST_LOAD) |
| 273 | STRINGIFY_CODE(FUNC_CODE, INST_VAARG) |
| 274 | STRINGIFY_CODE(FUNC_CODE, INST_STORE) |
| 275 | STRINGIFY_CODE(FUNC_CODE, INST_EXTRACTVAL) |
| 276 | STRINGIFY_CODE(FUNC_CODE, INST_INSERTVAL) |
| 277 | STRINGIFY_CODE(FUNC_CODE, INST_CMP2) |
| 278 | STRINGIFY_CODE(FUNC_CODE, INST_VSELECT) |
| 279 | STRINGIFY_CODE(FUNC_CODE, DEBUG_LOC_AGAIN) |
| 280 | STRINGIFY_CODE(FUNC_CODE, INST_CALL) |
| 281 | STRINGIFY_CODE(FUNC_CODE, DEBUG_LOC) |
| 282 | STRINGIFY_CODE(FUNC_CODE, INST_GEP) |
Sanjoy Das | 51df5fa | 2016-04-26 05:59:08 +0000 | [diff] [blame] | 283 | STRINGIFY_CODE(FUNC_CODE, OPERAND_BUNDLE) |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 284 | } |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 285 | case bitc::VALUE_SYMTAB_BLOCK_ID: |
| 286 | switch (CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 287 | default: return nullptr; |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 288 | STRINGIFY_CODE(VST_CODE, ENTRY) |
| 289 | STRINGIFY_CODE(VST_CODE, BBENTRY) |
Teresa Johnson | ff642b9 | 2015-09-17 20:12:00 +0000 | [diff] [blame] | 290 | STRINGIFY_CODE(VST_CODE, FNENTRY) |
Teresa Johnson | 76a1c1d | 2016-03-11 18:52:24 +0000 | [diff] [blame] | 291 | STRINGIFY_CODE(VST_CODE, COMBINED_ENTRY) |
Teresa Johnson | 403a787 | 2015-10-04 14:33:43 +0000 | [diff] [blame] | 292 | } |
| 293 | case bitc::MODULE_STRTAB_BLOCK_ID: |
| 294 | switch (CodeID) { |
Teresa Johnson | f72278f | 2015-11-02 18:02:11 +0000 | [diff] [blame] | 295 | default: |
| 296 | return nullptr; |
| 297 | STRINGIFY_CODE(MST_CODE, ENTRY) |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 298 | STRINGIFY_CODE(MST_CODE, HASH) |
Teresa Johnson | 403a787 | 2015-10-04 14:33:43 +0000 | [diff] [blame] | 299 | } |
Teresa Johnson | 76a1c1d | 2016-03-11 18:52:24 +0000 | [diff] [blame] | 300 | case bitc::GLOBALVAL_SUMMARY_BLOCK_ID: |
Teresa Johnson | 403a787 | 2015-10-04 14:33:43 +0000 | [diff] [blame] | 301 | switch (CodeID) { |
Teresa Johnson | f72278f | 2015-11-02 18:02:11 +0000 | [diff] [blame] | 302 | default: |
| 303 | return nullptr; |
Teresa Johnson | 76a1c1d | 2016-03-11 18:52:24 +0000 | [diff] [blame] | 304 | STRINGIFY_CODE(FS, PERMODULE) |
| 305 | STRINGIFY_CODE(FS, PERMODULE_PROFILE) |
| 306 | STRINGIFY_CODE(FS, PERMODULE_GLOBALVAR_INIT_REFS) |
| 307 | STRINGIFY_CODE(FS, COMBINED) |
| 308 | STRINGIFY_CODE(FS, COMBINED_PROFILE) |
| 309 | STRINGIFY_CODE(FS, COMBINED_GLOBALVAR_INIT_REFS) |
Mehdi Amini | 2d28f7a | 2016-04-16 06:56:44 +0000 | [diff] [blame] | 310 | STRINGIFY_CODE(FS, ALIAS) |
| 311 | STRINGIFY_CODE(FS, COMBINED_ALIAS) |
Mehdi Amini | ae64eaf | 2016-04-23 23:38:17 +0000 | [diff] [blame] | 312 | STRINGIFY_CODE(FS, COMBINED_ORIGINAL_NAME) |
Mehdi Amini | 8fe6936 | 2016-04-24 03:18:11 +0000 | [diff] [blame] | 313 | STRINGIFY_CODE(FS, VERSION) |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 314 | } |
Devang Patel | af206b8 | 2009-09-18 19:26:43 +0000 | [diff] [blame] | 315 | case bitc::METADATA_ATTACHMENT_ID: |
| 316 | switch(CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 317 | default:return nullptr; |
Duncan P. N. Exon Smith | 706b80d | 2015-06-29 22:50:35 +0000 | [diff] [blame] | 318 | STRINGIFY_CODE(METADATA, ATTACHMENT) |
Devang Patel | af206b8 | 2009-09-18 19:26:43 +0000 | [diff] [blame] | 319 | } |
Devang Patel | 7428d8a | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 320 | case bitc::METADATA_BLOCK_ID: |
| 321 | switch(CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 322 | default:return nullptr; |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 323 | STRINGIFY_CODE(METADATA, STRING_OLD) |
| 324 | STRINGIFY_CODE(METADATA, STRINGS) |
Duncan P. N. Exon Smith | 706b80d | 2015-06-29 22:50:35 +0000 | [diff] [blame] | 325 | STRINGIFY_CODE(METADATA, NAME) |
Teresa Johnson | 1254507 | 2015-11-15 02:00:09 +0000 | [diff] [blame] | 326 | STRINGIFY_CODE(METADATA, KIND) // Older bitcode has it in a MODULE_BLOCK |
Duncan P. N. Exon Smith | 706b80d | 2015-06-29 22:50:35 +0000 | [diff] [blame] | 327 | STRINGIFY_CODE(METADATA, NODE) |
| 328 | STRINGIFY_CODE(METADATA, VALUE) |
| 329 | STRINGIFY_CODE(METADATA, OLD_NODE) |
| 330 | STRINGIFY_CODE(METADATA, OLD_FN_NODE) |
| 331 | STRINGIFY_CODE(METADATA, NAMED_NODE) |
| 332 | STRINGIFY_CODE(METADATA, DISTINCT_NODE) |
| 333 | STRINGIFY_CODE(METADATA, LOCATION) |
| 334 | STRINGIFY_CODE(METADATA, GENERIC_DEBUG) |
| 335 | STRINGIFY_CODE(METADATA, SUBRANGE) |
| 336 | STRINGIFY_CODE(METADATA, ENUMERATOR) |
| 337 | STRINGIFY_CODE(METADATA, BASIC_TYPE) |
| 338 | STRINGIFY_CODE(METADATA, FILE) |
| 339 | STRINGIFY_CODE(METADATA, DERIVED_TYPE) |
| 340 | STRINGIFY_CODE(METADATA, COMPOSITE_TYPE) |
| 341 | STRINGIFY_CODE(METADATA, SUBROUTINE_TYPE) |
| 342 | STRINGIFY_CODE(METADATA, COMPILE_UNIT) |
| 343 | STRINGIFY_CODE(METADATA, SUBPROGRAM) |
| 344 | STRINGIFY_CODE(METADATA, LEXICAL_BLOCK) |
| 345 | STRINGIFY_CODE(METADATA, LEXICAL_BLOCK_FILE) |
| 346 | STRINGIFY_CODE(METADATA, NAMESPACE) |
| 347 | STRINGIFY_CODE(METADATA, TEMPLATE_TYPE) |
| 348 | STRINGIFY_CODE(METADATA, TEMPLATE_VALUE) |
| 349 | STRINGIFY_CODE(METADATA, GLOBAL_VAR) |
| 350 | STRINGIFY_CODE(METADATA, LOCAL_VAR) |
| 351 | STRINGIFY_CODE(METADATA, EXPRESSION) |
| 352 | STRINGIFY_CODE(METADATA, OBJC_PROPERTY) |
| 353 | STRINGIFY_CODE(METADATA, IMPORTED_ENTITY) |
Adrian Prantl | a7ad09d | 2015-06-30 00:25:41 +0000 | [diff] [blame] | 354 | STRINGIFY_CODE(METADATA, MODULE) |
Devang Patel | 7428d8a | 2009-07-22 17:43:22 +0000 | [diff] [blame] | 355 | } |
Teresa Johnson | 1254507 | 2015-11-15 02:00:09 +0000 | [diff] [blame] | 356 | case bitc::METADATA_KIND_BLOCK_ID: |
| 357 | switch (CodeID) { |
| 358 | default: |
| 359 | return nullptr; |
| 360 | STRINGIFY_CODE(METADATA, KIND) |
| 361 | } |
Chad Rosier | dd4ffae | 2011-12-07 21:45:13 +0000 | [diff] [blame] | 362 | case bitc::USELIST_BLOCK_ID: |
| 363 | switch(CodeID) { |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 364 | default:return nullptr; |
Duncan P. N. Exon Smith | 1f66c85 | 2014-07-28 21:19:41 +0000 | [diff] [blame] | 365 | case bitc::USELIST_CODE_DEFAULT: return "USELIST_CODE_DEFAULT"; |
| 366 | case bitc::USELIST_CODE_BB: return "USELIST_CODE_BB"; |
Chad Rosier | dd4ffae | 2011-12-07 21:45:13 +0000 | [diff] [blame] | 367 | } |
Sanjoy Das | 51df5fa | 2016-04-26 05:59:08 +0000 | [diff] [blame] | 368 | |
| 369 | case bitc::OPERAND_BUNDLE_TAGS_BLOCK_ID: |
| 370 | switch(CodeID) { |
| 371 | default: return nullptr; |
| 372 | case bitc::OPERAND_BUNDLE_TAG: return "OPERAND_BUNDLE_TAG"; |
| 373 | } |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 374 | } |
Duncan P. N. Exon Smith | cb8ee00 | 2015-06-29 22:50:32 +0000 | [diff] [blame] | 375 | #undef STRINGIFY_CODE |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Chris Lattner | bf419a9 | 2009-04-27 17:59:34 +0000 | [diff] [blame] | 378 | struct PerRecordStats { |
| 379 | unsigned NumInstances; |
Chris Lattner | 1cf8069 | 2009-04-27 18:15:27 +0000 | [diff] [blame] | 380 | unsigned NumAbbrev; |
| 381 | uint64_t TotalBits; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 382 | |
Mehdi Amini | d263856 | 2015-10-21 06:10:55 +0000 | [diff] [blame] | 383 | PerRecordStats() : NumInstances(0), NumAbbrev(0), TotalBits(0) {} |
Chris Lattner | bf419a9 | 2009-04-27 17:59:34 +0000 | [diff] [blame] | 384 | }; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 385 | |
| 386 | struct PerBlockIDStats { |
| 387 | /// NumInstances - This the number of times this block ID has been seen. |
| 388 | unsigned NumInstances; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 389 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 390 | /// NumBits - The total size in bits of all of these blocks. |
| 391 | uint64_t NumBits; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 392 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 393 | /// NumSubBlocks - The total number of blocks these blocks contain. |
| 394 | unsigned NumSubBlocks; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 395 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 396 | /// NumAbbrevs - The total number of abbreviations. |
| 397 | unsigned NumAbbrevs; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 398 | |
| 399 | /// NumRecords - The total number of records these blocks contain, and the |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 400 | /// number that are abbreviated. |
| 401 | unsigned NumRecords, NumAbbreviatedRecords; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 402 | |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 403 | /// CodeFreq - Keep track of the number of times we see each code. |
Chris Lattner | bf419a9 | 2009-04-27 17:59:34 +0000 | [diff] [blame] | 404 | std::vector<PerRecordStats> CodeFreq; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 405 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 406 | PerBlockIDStats() |
| 407 | : NumInstances(0), NumBits(0), |
| 408 | NumSubBlocks(0), NumAbbrevs(0), NumRecords(0), NumAbbreviatedRecords(0) {} |
| 409 | }; |
| 410 | |
| 411 | static std::map<unsigned, PerBlockIDStats> BlockIDStats; |
| 412 | |
| 413 | |
| 414 | |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 415 | /// ReportError - All bitcode analysis errors go through this function, making this a |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 416 | /// good place to breakpoint if debugging. |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 417 | static bool ReportError(const Twine &Err) { |
Dan Gohman | d8db376 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 418 | errs() << Err << "\n"; |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 419 | return true; |
| 420 | } |
| 421 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 422 | static bool decodeMetadataStringsBlob(StringRef Indent, |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 423 | ArrayRef<uint64_t> Record, |
| 424 | StringRef Blob) { |
| 425 | if (Blob.empty()) |
| 426 | return true; |
| 427 | |
| 428 | if (Record.size() != 2) |
| 429 | return true; |
| 430 | |
| 431 | unsigned NumStrings = Record[0]; |
| 432 | unsigned StringsOffset = Record[1]; |
| 433 | outs() << " num-strings = " << NumStrings << " {\n"; |
| 434 | |
| 435 | StringRef Lengths = Blob.slice(0, StringsOffset); |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 436 | SimpleBitstreamCursor R(Lengths); |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 437 | StringRef Strings = Blob.drop_front(StringsOffset); |
| 438 | do { |
| 439 | if (R.AtEndOfStream()) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 440 | return ReportError("bad length"); |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 441 | |
| 442 | unsigned Size = R.ReadVBR(6); |
| 443 | if (Strings.size() < Size) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 444 | return ReportError("truncated chars"); |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 445 | |
| 446 | outs() << Indent << " '"; |
| 447 | outs().write_escaped(Strings.slice(0, Size), /*hex=*/true); |
| 448 | outs() << "'\n"; |
| 449 | Strings = Strings.drop_front(Size); |
| 450 | } while (--NumStrings); |
| 451 | |
| 452 | outs() << Indent << " }"; |
| 453 | return false; |
| 454 | } |
| 455 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 456 | static bool decodeBlob(unsigned Code, unsigned BlockID, StringRef Indent, |
| 457 | ArrayRef<uint64_t> Record, StringRef Blob) { |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 458 | if (BlockID != bitc::METADATA_BLOCK_ID) |
| 459 | return true; |
| 460 | if (Code != bitc::METADATA_STRINGS) |
| 461 | return true; |
| 462 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 463 | return decodeMetadataStringsBlob(Indent, Record, Blob); |
Duncan P. N. Exon Smith | 6565a0d | 2016-03-27 23:17:54 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 466 | /// ParseBlock - Read a block, updating statistics, etc. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 467 | static bool ParseBlock(BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo, |
| 468 | unsigned BlockID, unsigned IndentLevel, |
| 469 | CurStreamTypeType CurStreamType) { |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 470 | std::string Indent(IndentLevel*2, ' '); |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 471 | uint64_t BlockBitStart = Stream.GetCurrentBitNo(); |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 472 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 473 | // Get the statistics for this BlockID. |
| 474 | PerBlockIDStats &BlockStats = BlockIDStats[BlockID]; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 475 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 476 | BlockStats.NumInstances++; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 477 | |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 478 | // BLOCKINFO is a special part of the stream. |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 479 | bool DumpRecords = Dump; |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 480 | if (BlockID == bitc::BLOCKINFO_BLOCK_ID) { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 481 | if (Dump) outs() << Indent << "<BLOCKINFO_BLOCK/>\n"; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 482 | Optional<BitstreamBlockInfo> NewBlockInfo = |
| 483 | Stream.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true); |
| 484 | if (!NewBlockInfo) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 485 | return ReportError("Malformed BlockInfoBlock"); |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 486 | BlockInfo = std::move(*NewBlockInfo); |
| 487 | Stream.JumpToBit(BlockBitStart); |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 488 | // It's not really interesting to dump the contents of the blockinfo block. |
| 489 | DumpRecords = false; |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 490 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 491 | |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 492 | unsigned NumWords = 0; |
Chris Lattner | 9181ddf | 2007-05-05 00:17:42 +0000 | [diff] [blame] | 493 | if (Stream.EnterSubBlock(BlockID, &NumWords)) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 494 | return ReportError("Malformed block record"); |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 495 | |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 496 | // Keep it for later, when we see a MODULE_HASH record |
| 497 | uint64_t BlockEntryPos = Stream.getCurrentByteNo(); |
| 498 | |
Craig Topper | e6cb63e | 2014-04-25 04:24:47 +0000 | [diff] [blame] | 499 | const char *BlockName = nullptr; |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 500 | if (DumpRecords) { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 501 | outs() << Indent << "<"; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 502 | if ((BlockName = GetBlockName(BlockID, BlockInfo, CurStreamType))) |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 503 | outs() << BlockName; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 504 | else |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 505 | outs() << "UnknownBlock" << BlockID; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 506 | |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 507 | if (NonSymbolic && BlockName) |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 508 | outs() << " BlockID=" << BlockID; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 509 | |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 510 | outs() << " NumWords=" << NumWords |
Chris Lattner | 3fa323d | 2013-01-19 21:37:14 +0000 | [diff] [blame] | 511 | << " BlockCodeSize=" << Stream.getAbbrevIDWidth() << ">\n"; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 512 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 513 | |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 514 | SmallVector<uint64_t, 64> Record; |
| 515 | |
| 516 | // Read all the records for this block. |
| 517 | while (1) { |
| 518 | if (Stream.AtEndOfStream()) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 519 | return ReportError("Premature end of bitstream"); |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 520 | |
Chris Lattner | 1cf8069 | 2009-04-27 18:15:27 +0000 | [diff] [blame] | 521 | uint64_t RecordStartBit = Stream.GetCurrentBitNo(); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 522 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 523 | BitstreamEntry Entry = |
| 524 | Stream.advance(BitstreamCursor::AF_DontAutoprocessAbbrevs); |
| 525 | |
| 526 | switch (Entry.Kind) { |
| 527 | case BitstreamEntry::Error: |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 528 | return ReportError("malformed bitcode file"); |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 529 | case BitstreamEntry::EndBlock: { |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 530 | uint64_t BlockBitEnd = Stream.GetCurrentBitNo(); |
| 531 | BlockStats.NumBits += BlockBitEnd-BlockBitStart; |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 532 | if (DumpRecords) { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 533 | outs() << Indent << "</"; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 534 | if (BlockName) |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 535 | outs() << BlockName << ">\n"; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 536 | else |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 537 | outs() << "UnknownBlock" << BlockID << ">\n"; |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 538 | } |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 539 | return false; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 540 | } |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 541 | |
| 542 | case BitstreamEntry::SubBlock: { |
Chris Lattner | 9e808cd | 2007-05-05 01:29:31 +0000 | [diff] [blame] | 543 | uint64_t SubBlockBitStart = Stream.GetCurrentBitNo(); |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 544 | if (ParseBlock(Stream, BlockInfo, Entry.ID, IndentLevel + 1, |
| 545 | CurStreamType)) |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 546 | return true; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 547 | ++BlockStats.NumSubBlocks; |
Chris Lattner | 9e808cd | 2007-05-05 01:29:31 +0000 | [diff] [blame] | 548 | uint64_t SubBlockBitEnd = Stream.GetCurrentBitNo(); |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 549 | |
Chris Lattner | 9e808cd | 2007-05-05 01:29:31 +0000 | [diff] [blame] | 550 | // Don't include subblock sizes in the size of this block. |
| 551 | BlockBitStart += SubBlockBitEnd-SubBlockBitStart; |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 552 | continue; |
| 553 | } |
| 554 | case BitstreamEntry::Record: |
| 555 | // The interesting case. |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 556 | break; |
Chris Lattner | 9e808cd | 2007-05-05 01:29:31 +0000 | [diff] [blame] | 557 | } |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 558 | |
| 559 | if (Entry.ID == bitc::DEFINE_ABBREV) { |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 560 | Stream.ReadAbbrevRecord(); |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 561 | ++BlockStats.NumAbbrevs; |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 562 | continue; |
| 563 | } |
| 564 | |
| 565 | Record.clear(); |
Chris Lattner | 2ed6a20 | 2009-04-06 22:44:40 +0000 | [diff] [blame] | 566 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 567 | ++BlockStats.NumRecords; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 568 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 569 | StringRef Blob; |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 570 | unsigned CurrentRecordPos = Stream.getCurrentByteNo(); |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 571 | unsigned Code = Stream.readRecord(Entry.ID, Record, &Blob); |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 572 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 573 | // Increment the # occurrences of this code. |
| 574 | if (BlockStats.CodeFreq.size() <= Code) |
| 575 | BlockStats.CodeFreq.resize(Code+1); |
| 576 | BlockStats.CodeFreq[Code].NumInstances++; |
| 577 | BlockStats.CodeFreq[Code].TotalBits += |
| 578 | Stream.GetCurrentBitNo()-RecordStartBit; |
| 579 | if (Entry.ID != bitc::UNABBREV_RECORD) { |
| 580 | BlockStats.CodeFreq[Code].NumAbbrev++; |
| 581 | ++BlockStats.NumAbbreviatedRecords; |
| 582 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 583 | |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 584 | if (DumpRecords) { |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 585 | outs() << Indent << " <"; |
| 586 | if (const char *CodeName = |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 587 | GetCodeName(Code, BlockID, BlockInfo, CurStreamType)) |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 588 | outs() << CodeName; |
| 589 | else |
| 590 | outs() << "UnknownCode" << Code; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 591 | if (NonSymbolic && GetCodeName(Code, BlockID, BlockInfo, CurStreamType)) |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 592 | outs() << " codeid=" << Code; |
Teresa Johnson | b1cfcd4 | 2015-10-08 15:56:24 +0000 | [diff] [blame] | 593 | const BitCodeAbbrev *Abbv = nullptr; |
| 594 | if (Entry.ID != bitc::UNABBREV_RECORD) { |
| 595 | Abbv = Stream.getAbbrev(Entry.ID); |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 596 | outs() << " abbrevid=" << Entry.ID; |
Teresa Johnson | b1cfcd4 | 2015-10-08 15:56:24 +0000 | [diff] [blame] | 597 | } |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 598 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 599 | for (unsigned i = 0, e = Record.size(); i != e; ++i) |
| 600 | outs() << " op" << i << "=" << (int64_t)Record[i]; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 601 | |
Mehdi Amini | d7ad221 | 2016-04-01 05:33:11 +0000 | [diff] [blame] | 602 | // If we found a module hash, let's verify that it matches! |
| 603 | if (BlockID == bitc::MODULE_BLOCK_ID && Code == bitc::MODULE_CODE_HASH) { |
| 604 | if (Record.size() != 5) |
| 605 | outs() << " (invalid)"; |
| 606 | else { |
| 607 | // Recompute the hash and compare it to the one in the bitcode |
| 608 | SHA1 Hasher; |
| 609 | StringRef Hash; |
| 610 | { |
| 611 | int BlockSize = CurrentRecordPos - BlockEntryPos; |
| 612 | auto Ptr = Stream.getPointerToByte(BlockEntryPos, BlockSize); |
| 613 | Hasher.update(ArrayRef<uint8_t>(Ptr, BlockSize)); |
| 614 | Hash = Hasher.result(); |
| 615 | } |
| 616 | SmallString<20> RecordedHash; |
| 617 | RecordedHash.resize(20); |
| 618 | int Pos = 0; |
| 619 | for (auto &Val : Record) { |
| 620 | assert(!(Val >> 32) && "Unexpected high bits set"); |
| 621 | RecordedHash[Pos++] = (Val >> 24) & 0xFF; |
| 622 | RecordedHash[Pos++] = (Val >> 16) & 0xFF; |
| 623 | RecordedHash[Pos++] = (Val >> 8) & 0xFF; |
| 624 | RecordedHash[Pos++] = (Val >> 0) & 0xFF; |
| 625 | } |
| 626 | if (Hash == RecordedHash) |
| 627 | outs() << " (match)"; |
| 628 | else |
| 629 | outs() << " (!mismatch!)"; |
| 630 | } |
| 631 | } |
| 632 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 633 | outs() << "/>"; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 634 | |
Teresa Johnson | b1cfcd4 | 2015-10-08 15:56:24 +0000 | [diff] [blame] | 635 | if (Abbv) { |
| 636 | for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) { |
| 637 | const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); |
| 638 | if (!Op.isEncoding() || Op.getEncoding() != BitCodeAbbrevOp::Array) |
| 639 | continue; |
| 640 | assert(i + 2 == e && "Array op not second to last"); |
| 641 | std::string Str; |
| 642 | bool ArrayIsPrintable = true; |
| 643 | for (unsigned j = i - 1, je = Record.size(); j != je; ++j) { |
| 644 | if (!isprint(static_cast<unsigned char>(Record[j]))) { |
| 645 | ArrayIsPrintable = false; |
| 646 | break; |
| 647 | } |
| 648 | Str += (char)Record[j]; |
| 649 | } |
Teresa Johnson | f72278f | 2015-11-02 18:02:11 +0000 | [diff] [blame] | 650 | if (ArrayIsPrintable) |
| 651 | outs() << " record string = '" << Str << "'"; |
Teresa Johnson | b1cfcd4 | 2015-10-08 15:56:24 +0000 | [diff] [blame] | 652 | break; |
| 653 | } |
| 654 | } |
| 655 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 656 | if (Blob.data() && decodeBlob(Code, BlockID, Indent, Record, Blob)) { |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 657 | outs() << " blob data = "; |
Jordan Rose | 0fa38b8 | 2015-05-13 18:51:49 +0000 | [diff] [blame] | 658 | if (ShowBinaryBlobs) { |
| 659 | outs() << "'"; |
| 660 | outs().write_escaped(Blob, /*hex=*/true) << "'"; |
| 661 | } else { |
| 662 | bool BlobIsPrintable = true; |
| 663 | for (unsigned i = 0, e = Blob.size(); i != e; ++i) |
| 664 | if (!isprint(static_cast<unsigned char>(Blob[i]))) { |
| 665 | BlobIsPrintable = false; |
| 666 | break; |
| 667 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 668 | |
Jordan Rose | 0fa38b8 | 2015-05-13 18:51:49 +0000 | [diff] [blame] | 669 | if (BlobIsPrintable) |
| 670 | outs() << "'" << Blob << "'"; |
| 671 | else |
| 672 | outs() << "unprintable, " << Blob.size() << " bytes."; |
| 673 | } |
Chris Lattner | 3543caa | 2007-04-29 21:48:19 +0000 | [diff] [blame] | 674 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 675 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 676 | outs() << "\n"; |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 681 | static void PrintSize(double Bits) { |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 682 | outs() << format("%.2f/%.2fB/%luW", Bits, Bits/8,(unsigned long)(Bits/32)); |
Chris Lattner | bf419a9 | 2009-04-27 17:59:34 +0000 | [diff] [blame] | 683 | } |
| 684 | static void PrintSize(uint64_t Bits) { |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 685 | outs() << format("%lub/%.2fB/%luW", (unsigned long)Bits, |
| 686 | (double)Bits/8, (unsigned long)(Bits/32)); |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 689 | static bool openBitcodeFile(StringRef Path, |
| 690 | std::unique_ptr<MemoryBuffer> &MemBuf, |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 691 | BitstreamCursor &Stream, |
| 692 | CurStreamTypeType &CurStreamType) { |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 693 | // Read the input file. |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 694 | ErrorOr<std::unique_ptr<MemoryBuffer>> MemBufOrErr = |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 695 | MemoryBuffer::getFileOrSTDIN(Path); |
Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 696 | if (std::error_code EC = MemBufOrErr.getError()) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 697 | return ReportError(Twine("ReportError reading '") + Path + "': " + EC.message()); |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 698 | MemBuf = std::move(MemBufOrErr.get()); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 699 | |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 700 | if (MemBuf->getBufferSize() & 3) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 701 | return ReportError("Bitcode stream should be a multiple of 4 bytes in length"); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 702 | |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 703 | const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); |
| 704 | const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 705 | |
Chris Lattner | b9e07fd | 2009-04-06 20:54:32 +0000 | [diff] [blame] | 706 | // If we have a wrapper header, parse it and ignore the non-bc file contents. |
| 707 | // The magic number is 0x0B17C0DE stored in little endian. |
Akira Hatanaka | 4f472a88 | 2016-01-29 05:55:09 +0000 | [diff] [blame] | 708 | if (isBitcodeWrapper(BufPtr, EndBufPtr)) { |
Mehdi Amini | eed2693 | 2016-04-01 05:19:14 +0000 | [diff] [blame] | 709 | if (MemBuf->getBufferSize() < BWH_HeaderSize) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 710 | return ReportError("Invalid bitcode wrapper header"); |
Akira Hatanaka | 4f472a88 | 2016-01-29 05:55:09 +0000 | [diff] [blame] | 711 | |
| 712 | if (Dump) { |
| 713 | unsigned Magic = support::endian::read32le(&BufPtr[BWH_MagicField]); |
| 714 | unsigned Version = support::endian::read32le(&BufPtr[BWH_VersionField]); |
| 715 | unsigned Offset = support::endian::read32le(&BufPtr[BWH_OffsetField]); |
| 716 | unsigned Size = support::endian::read32le(&BufPtr[BWH_SizeField]); |
| 717 | unsigned CPUType = support::endian::read32le(&BufPtr[BWH_CPUTypeField]); |
| 718 | |
| 719 | outs() << "<BITCODE_WRAPPER_HEADER" |
| 720 | << " Magic=" << format_hex(Magic, 10) |
| 721 | << " Version=" << format_hex(Version, 10) |
| 722 | << " Offset=" << format_hex(Offset, 10) |
| 723 | << " Size=" << format_hex(Size, 10) |
| 724 | << " CPUType=" << format_hex(CPUType, 10) << "/>\n"; |
| 725 | } |
| 726 | |
Derek Schuff | 8b2dcad | 2012-02-06 22:30:29 +0000 | [diff] [blame] | 727 | if (SkipBitcodeWrapperHeader(BufPtr, EndBufPtr, true)) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 728 | return ReportError("Invalid bitcode wrapper header"); |
Akira Hatanaka | 4f472a88 | 2016-01-29 05:55:09 +0000 | [diff] [blame] | 729 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 730 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 731 | Stream = BitstreamCursor(ArrayRef<uint8_t>(BufPtr, EndBufPtr)); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 732 | |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 733 | // Read the stream signature. |
| 734 | char Signature[6]; |
| 735 | Signature[0] = Stream.Read(8); |
| 736 | Signature[1] = Stream.Read(8); |
| 737 | Signature[2] = Stream.Read(4); |
| 738 | Signature[3] = Stream.Read(4); |
| 739 | Signature[4] = Stream.Read(4); |
| 740 | Signature[5] = Stream.Read(4); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 741 | |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 742 | // Autodetect the file contents, if it is one we know. |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 743 | CurStreamType = UnknownBitstream; |
| 744 | if (Signature[0] == 'B' && Signature[1] == 'C' && |
| 745 | Signature[2] == 0x0 && Signature[3] == 0xC && |
| 746 | Signature[4] == 0xE && Signature[5] == 0xD) |
| 747 | CurStreamType = LLVMIRBitstream; |
| 748 | |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 749 | return false; |
| 750 | } |
| 751 | |
| 752 | /// AnalyzeBitcode - Analyze the bitcode file specified by InputFilename. |
| 753 | static int AnalyzeBitcode() { |
| 754 | std::unique_ptr<MemoryBuffer> StreamBuffer; |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 755 | BitstreamCursor Stream; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 756 | BitstreamBlockInfo BlockInfo; |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 757 | CurStreamTypeType CurStreamType; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 758 | if (openBitcodeFile(InputFilename, StreamBuffer, Stream, CurStreamType)) |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 759 | return true; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 760 | Stream.setBlockInfo(&BlockInfo); |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 761 | |
| 762 | // Read block info from BlockInfoFilename, if specified. |
| 763 | // The block info must be a top-level block. |
| 764 | if (!BlockInfoFilename.empty()) { |
| 765 | std::unique_ptr<MemoryBuffer> BlockInfoBuffer; |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 766 | BitstreamCursor BlockInfoCursor; |
| 767 | CurStreamTypeType BlockInfoStreamType; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 768 | if (openBitcodeFile(BlockInfoFilename, BlockInfoBuffer, BlockInfoCursor, |
| 769 | BlockInfoStreamType)) |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 770 | return true; |
| 771 | |
| 772 | while (!BlockInfoCursor.AtEndOfStream()) { |
| 773 | unsigned Code = BlockInfoCursor.ReadCode(); |
| 774 | if (Code != bitc::ENTER_SUBBLOCK) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 775 | return ReportError("Invalid record at top-level in block info file"); |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 776 | |
| 777 | unsigned BlockID = BlockInfoCursor.ReadSubBlockID(); |
| 778 | if (BlockID == bitc::BLOCKINFO_BLOCK_ID) { |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 779 | Optional<BitstreamBlockInfo> NewBlockInfo = |
| 780 | BlockInfoCursor.ReadBlockInfoBlock(/*ReadBlockInfoNames=*/true); |
| 781 | if (!NewBlockInfo) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 782 | return ReportError("Malformed BlockInfoBlock in block info file"); |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 783 | BlockInfo = std::move(*NewBlockInfo); |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 784 | break; |
| 785 | } |
| 786 | |
| 787 | BlockInfoCursor.SkipBlock(); |
| 788 | } |
Jordan Rose | 88eb534 | 2014-08-30 17:07:55 +0000 | [diff] [blame] | 789 | } |
| 790 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 791 | unsigned NumTopBlocks = 0; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 792 | |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 793 | // Parse the top-level structure. We only allow blocks at the top-level. |
| 794 | while (!Stream.AtEndOfStream()) { |
| 795 | unsigned Code = Stream.ReadCode(); |
| 796 | if (Code != bitc::ENTER_SUBBLOCK) |
Zachary Turner | 2ee505e | 2016-10-03 18:17:18 +0000 | [diff] [blame] | 797 | return ReportError("Invalid record at top-level"); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 798 | |
Chris Lattner | 0271af8 | 2013-01-20 02:50:32 +0000 | [diff] [blame] | 799 | unsigned BlockID = Stream.ReadSubBlockID(); |
| 800 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 801 | if (ParseBlock(Stream, BlockInfo, BlockID, 0, CurStreamType)) |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 802 | return true; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 803 | ++NumTopBlocks; |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 804 | } |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 805 | |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 806 | if (Dump) outs() << "\n\n"; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 807 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 808 | uint64_t BufferSizeBits = Stream.getBitcodeBytes().size() * CHAR_BIT; |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 809 | // Print a summary of the read file. |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 810 | outs() << "Summary of " << InputFilename << ":\n"; |
| 811 | outs() << " Total size: "; |
Chris Lattner | 5fab65d | 2007-05-01 02:43:46 +0000 | [diff] [blame] | 812 | PrintSize(BufferSizeBits); |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 813 | outs() << "\n"; |
| 814 | outs() << " Stream type: "; |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 815 | switch (CurStreamType) { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 816 | case UnknownBitstream: outs() << "unknown\n"; break; |
| 817 | case LLVMIRBitstream: outs() << "LLVM IR\n"; break; |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 818 | } |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 819 | outs() << " # Toplevel Blocks: " << NumTopBlocks << "\n"; |
| 820 | outs() << "\n"; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 821 | |
| 822 | // Emit per-block stats. |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 823 | outs() << "Per-block Summary:\n"; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 824 | for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(), |
| 825 | E = BlockIDStats.end(); I != E; ++I) { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 826 | outs() << " Block ID #" << I->first; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 827 | if (const char *BlockName = |
| 828 | GetBlockName(I->first, BlockInfo, CurStreamType)) |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 829 | outs() << " (" << BlockName << ")"; |
| 830 | outs() << ":\n"; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 831 | |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 832 | const PerBlockIDStats &Stats = I->second; |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 833 | outs() << " Num Instances: " << Stats.NumInstances << "\n"; |
| 834 | outs() << " Total Size: "; |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 835 | PrintSize(Stats.NumBits); |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 836 | outs() << "\n"; |
Daniel Dunbar | e813b22 | 2009-09-25 16:04:21 +0000 | [diff] [blame] | 837 | double pct = (Stats.NumBits * 100.0) / BufferSizeBits; |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 838 | outs() << " Percent of file: " << format("%2.4f%%", pct) << "\n"; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 839 | if (Stats.NumInstances > 1) { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 840 | outs() << " Average Size: "; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 841 | PrintSize(Stats.NumBits/(double)Stats.NumInstances); |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 842 | outs() << "\n"; |
| 843 | outs() << " Tot/Avg SubBlocks: " << Stats.NumSubBlocks << "/" |
Dan Gohman | d8db376 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 844 | << Stats.NumSubBlocks/(double)Stats.NumInstances << "\n"; |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 845 | outs() << " Tot/Avg Abbrevs: " << Stats.NumAbbrevs << "/" |
Dan Gohman | d8db376 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 846 | << Stats.NumAbbrevs/(double)Stats.NumInstances << "\n"; |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 847 | outs() << " Tot/Avg Records: " << Stats.NumRecords << "/" |
Dan Gohman | d8db376 | 2009-07-15 16:35:29 +0000 | [diff] [blame] | 848 | << Stats.NumRecords/(double)Stats.NumInstances << "\n"; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 849 | } else { |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 850 | outs() << " Num SubBlocks: " << Stats.NumSubBlocks << "\n"; |
| 851 | outs() << " Num Abbrevs: " << Stats.NumAbbrevs << "\n"; |
| 852 | outs() << " Num Records: " << Stats.NumRecords << "\n"; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 853 | } |
Daniel Dunbar | e813b22 | 2009-09-25 16:04:21 +0000 | [diff] [blame] | 854 | if (Stats.NumRecords) { |
| 855 | double pct = (Stats.NumAbbreviatedRecords * 100.0) / Stats.NumRecords; |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 856 | outs() << " Percent Abbrevs: " << format("%2.4f%%", pct) << "\n"; |
Daniel Dunbar | e813b22 | 2009-09-25 16:04:21 +0000 | [diff] [blame] | 857 | } |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 858 | outs() << "\n"; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 859 | |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 860 | // Print a histogram of the codes we see. |
| 861 | if (!NoHistogram && !Stats.CodeFreq.empty()) { |
Mehdi Amini | d263856 | 2015-10-21 06:10:55 +0000 | [diff] [blame] | 862 | std::vector<std::pair<unsigned, unsigned> > FreqPairs; // <freq,code> |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 863 | for (unsigned i = 0, e = Stats.CodeFreq.size(); i != e; ++i) |
Mehdi Amini | d263856 | 2015-10-21 06:10:55 +0000 | [diff] [blame] | 864 | if (unsigned Freq = Stats.CodeFreq[i].NumInstances) |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 865 | FreqPairs.push_back(std::make_pair(Freq, i)); |
| 866 | std::stable_sort(FreqPairs.begin(), FreqPairs.end()); |
| 867 | std::reverse(FreqPairs.begin(), FreqPairs.end()); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 868 | |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 869 | outs() << "\tRecord Histogram:\n"; |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 870 | outs() << "\t\t Count # Bits b/Rec % Abv Record Kind\n"; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 871 | for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) { |
Chris Lattner | 1cf8069 | 2009-04-27 18:15:27 +0000 | [diff] [blame] | 872 | const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second]; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 873 | |
Mehdi Amini | d263856 | 2015-10-21 06:10:55 +0000 | [diff] [blame] | 874 | outs() << format("\t\t%7d %9lu", |
Jan Wen Voung | 05ff570 | 2012-09-05 20:55:57 +0000 | [diff] [blame] | 875 | RecStats.NumInstances, |
| 876 | (unsigned long)RecStats.TotalBits); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 877 | |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 878 | if (RecStats.NumInstances > 1) |
| 879 | outs() << format(" %9.1f", |
| 880 | (double)RecStats.TotalBits/RecStats.NumInstances); |
| 881 | else |
| 882 | outs() << " "; |
| 883 | |
Chris Lattner | 1cf8069 | 2009-04-27 18:15:27 +0000 | [diff] [blame] | 884 | if (RecStats.NumAbbrev) |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 885 | outs() << |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 886 | format(" %7.2f", |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 887 | (double)RecStats.NumAbbrev/RecStats.NumInstances*100); |
Chris Lattner | 1cf8069 | 2009-04-27 18:15:27 +0000 | [diff] [blame] | 888 | else |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 889 | outs() << " "; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 890 | |
Richard Smith | dc1414b | 2016-02-06 00:46:09 +0000 | [diff] [blame] | 891 | outs() << " "; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 892 | if (const char *CodeName = GetCodeName(FreqPairs[i].second, I->first, |
| 893 | BlockInfo, CurStreamType)) |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 894 | outs() << CodeName << "\n"; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 895 | else |
Jan Wen Voung | 52ad208 | 2012-09-05 20:55:54 +0000 | [diff] [blame] | 896 | outs() << "UnknownCode" << FreqPairs[i].second << "\n"; |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 897 | } |
Chris Lattner | 633ab16 | 2012-03-19 23:40:48 +0000 | [diff] [blame] | 898 | outs() << "\n"; |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 899 | |
Chris Lattner | 4a7ac9f | 2007-05-05 01:46:49 +0000 | [diff] [blame] | 900 | } |
Chris Lattner | 1684cee | 2007-04-29 20:00:02 +0000 | [diff] [blame] | 901 | } |
Chris Lattner | 0399758 | 2007-04-29 08:12:22 +0000 | [diff] [blame] | 902 | return 0; |
| 903 | } |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 904 | |
Chris Lattner | ca0ea54 | 2007-04-29 08:31:14 +0000 | [diff] [blame] | 905 | |
Chris Lattner | 76d4632 | 2006-12-06 01:18:01 +0000 | [diff] [blame] | 906 | int main(int argc, char **argv) { |
Chris Lattner | e3fc2d1 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 907 | // Print a stack trace if we signal out. |
Richard Smith | 2ad6d48 | 2016-06-09 00:53:21 +0000 | [diff] [blame] | 908 | sys::PrintStackTraceOnErrorSignal(argv[0]); |
Chris Lattner | e3fc2d1 | 2009-03-06 05:34:10 +0000 | [diff] [blame] | 909 | PrettyStackTraceProgram X(argc, argv); |
| 910 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 911 | cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n"); |
Daniel Dunbar | 75359a7c | 2009-09-25 16:03:57 +0000 | [diff] [blame] | 912 | |
Chris Lattner | 6d80e21 | 2007-05-06 09:29:57 +0000 | [diff] [blame] | 913 | return AnalyzeBitcode(); |
Reid Spencer | db5c86d | 2004-06-07 17:53:43 +0000 | [diff] [blame] | 914 | } |