OLD | NEW |
1 //===--- Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp - Bitcode Writer -------===// | 1 //===--- Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp - Bitcode Writer -------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Bitcode writer implementation. | 10 // Bitcode writer implementation. |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "llvm/Support/Program.h" | 29 #include "llvm/Support/Program.h" |
30 #include "llvm/Support/raw_ostream.h" | 30 #include "llvm/Support/raw_ostream.h" |
31 #include <cctype> | 31 #include <cctype> |
32 #include <map> | 32 #include <map> |
33 using namespace llvm; | 33 using namespace llvm; |
34 | 34 |
35 /// These are manifest constants used by the bitcode writer. They do not need to | 35 /// These are manifest constants used by the bitcode writer. They do not need to |
36 /// be kept in sync with the reader, but need to be consistent within this file. | 36 /// be kept in sync with the reader, but need to be consistent within this file. |
37 enum { | 37 enum { |
38 // VALUE_SYMTAB_BLOCK abbrev id's. | 38 // VALUE_SYMTAB_BLOCK abbrev id's. |
39 VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV, | 39 VST_ENTRY_8_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
40 VST_ENTRY_7_ABBREV, | 40 VST_ENTRY_7_ABBREV, |
41 VST_ENTRY_6_ABBREV, | 41 VST_ENTRY_6_ABBREV, |
42 VST_BBENTRY_6_ABBREV, | 42 VST_BBENTRY_6_ABBREV, |
43 | 43 |
44 // CONSTANTS_BLOCK abbrev id's. | 44 // CONSTANTS_BLOCK abbrev id's. |
45 CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV, | 45 CONSTANTS_SETTYPE_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
46 CONSTANTS_INTEGER_ABBREV, | 46 CONSTANTS_INTEGER_ABBREV, |
47 CONSTANTS_CE_CAST_Abbrev, | 47 CONSTANTS_CE_CAST_Abbrev, |
48 CONSTANTS_NULL_Abbrev, | 48 CONSTANTS_NULL_Abbrev, |
49 | 49 |
50 // FUNCTION_BLOCK abbrev id's. | 50 // FUNCTION_BLOCK abbrev id's. |
51 FUNCTION_INST_LOAD_ABBREV = bitc::FIRST_APPLICATION_ABBREV, | 51 FUNCTION_INST_LOAD_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, |
52 FUNCTION_INST_BINOP_ABBREV, | 52 FUNCTION_INST_BINOP_ABBREV, |
53 FUNCTION_INST_BINOP_FLAGS_ABBREV, | 53 FUNCTION_INST_BINOP_FLAGS_ABBREV, |
54 FUNCTION_INST_CAST_ABBREV, | 54 FUNCTION_INST_CAST_ABBREV, |
55 FUNCTION_INST_RET_VOID_ABBREV, | 55 FUNCTION_INST_RET_VOID_ABBREV, |
56 FUNCTION_INST_RET_VAL_ABBREV, | 56 FUNCTION_INST_RET_VAL_ABBREV, |
57 FUNCTION_INST_UNREACHABLE_ABBREV, | 57 FUNCTION_INST_UNREACHABLE_ABBREV, |
58 | 58 |
59 // SwitchInst Magic | 59 // SwitchInst Magic |
60 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex | 60 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex |
61 }; | 61 }; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 static unsigned GetEncodedSynchScope(SynchronizationScope SynchScope) { | 135 static unsigned GetEncodedSynchScope(SynchronizationScope SynchScope) { |
136 switch (SynchScope) { | 136 switch (SynchScope) { |
137 case SingleThread: return naclbitc::SYNCHSCOPE_SINGLETHREAD; | 137 case SingleThread: return naclbitc::SYNCHSCOPE_SINGLETHREAD; |
138 case CrossThread: return naclbitc::SYNCHSCOPE_CROSSTHREAD; | 138 case CrossThread: return naclbitc::SYNCHSCOPE_CROSSTHREAD; |
139 } | 139 } |
140 llvm_unreachable("Invalid synch scope"); | 140 llvm_unreachable("Invalid synch scope"); |
141 } | 141 } |
142 | 142 |
143 static void WriteStringRecord(unsigned Code, StringRef Str, | 143 static void WriteStringRecord(unsigned Code, StringRef Str, |
144 unsigned AbbrevToUse, NaClBitstreamWriter &Stream)
{ | 144 unsigned AbbrevToUse, |
| 145 NaClBitstreamWriter &Stream) { |
145 SmallVector<unsigned, 64> Vals; | 146 SmallVector<unsigned, 64> Vals; |
146 | 147 |
147 // Code: [strchar x N] | 148 // Code: [strchar x N] |
148 for (unsigned i = 0, e = Str.size(); i != e; ++i) { | 149 for (unsigned i = 0, e = Str.size(); i != e; ++i) { |
149 if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(Str[i])) | 150 if (AbbrevToUse && !NaClBitCodeAbbrevOp::isChar6(Str[i])) |
150 AbbrevToUse = 0; | 151 AbbrevToUse = 0; |
151 Vals.push_back(Str[i]); | 152 Vals.push_back(Str[i]); |
152 } | 153 } |
153 | 154 |
154 // Emit the finished record. | 155 // Emit the finished record. |
155 Stream.EmitRecord(Code, Vals, AbbrevToUse); | 156 Stream.EmitRecord(Code, Vals, AbbrevToUse); |
156 } | 157 } |
157 | 158 |
158 static void WriteAttributeGroupTable(const NaClValueEnumerator &VE, | 159 static void WriteAttributeGroupTable(const NaClValueEnumerator &VE, |
159 NaClBitstreamWriter &Stream) { | 160 NaClBitstreamWriter &Stream) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 222 } |
222 | 223 |
223 Stream.ExitBlock(); | 224 Stream.ExitBlock(); |
224 } | 225 } |
225 | 226 |
226 /// WriteTypeTable - Write out the type table for a module. | 227 /// WriteTypeTable - Write out the type table for a module. |
227 static void WriteTypeTable(const NaClValueEnumerator &VE, | 228 static void WriteTypeTable(const NaClValueEnumerator &VE, |
228 NaClBitstreamWriter &Stream) { | 229 NaClBitstreamWriter &Stream) { |
229 const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); | 230 const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); |
230 | 231 |
231 Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */)
; | 232 Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, |
| 233 4 /*count from # abbrevs */); |
232 SmallVector<uint64_t, 64> TypeVals; | 234 SmallVector<uint64_t, 64> TypeVals; |
233 | 235 |
234 uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); | 236 uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); |
235 | 237 |
236 // Abbrev for TYPE_CODE_POINTER. | 238 // Abbrev for TYPE_CODE_POINTER. |
237 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 239 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
238 Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); | 240 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); |
239 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 241 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
240 Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0 | 242 Abbv->Add(NaClBitCodeAbbrevOp(0)); // Addrspace = 0 |
241 unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv); | 243 unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv); |
242 | 244 |
243 // Abbrev for TYPE_CODE_FUNCTION. | 245 // Abbrev for TYPE_CODE_FUNCTION. |
244 Abbv = new BitCodeAbbrev(); | 246 Abbv = new NaClBitCodeAbbrev(); |
245 Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_FUNCTION)); | 247 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_FUNCTION)); |
246 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg | 248 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // isvararg |
247 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 249 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
248 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 250 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
249 | 251 |
250 unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv); | 252 unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv); |
251 | 253 |
252 // Abbrev for TYPE_CODE_STRUCT_ANON. | 254 // Abbrev for TYPE_CODE_STRUCT_ANON. |
253 Abbv = new BitCodeAbbrev(); | 255 Abbv = new NaClBitCodeAbbrev(); |
254 Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_ANON)); | 256 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_ANON)); |
255 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked | 257 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked |
256 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 258 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
257 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 259 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
258 | 260 |
259 unsigned StructAnonAbbrev = Stream.EmitAbbrev(Abbv); | 261 unsigned StructAnonAbbrev = Stream.EmitAbbrev(Abbv); |
260 | 262 |
261 // Abbrev for TYPE_CODE_STRUCT_NAME. | 263 // Abbrev for TYPE_CODE_STRUCT_NAME. |
262 Abbv = new BitCodeAbbrev(); | 264 Abbv = new NaClBitCodeAbbrev(); |
263 Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAME)); | 265 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAME)); |
264 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 266 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
265 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | 267 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
266 unsigned StructNameAbbrev = Stream.EmitAbbrev(Abbv); | 268 unsigned StructNameAbbrev = Stream.EmitAbbrev(Abbv); |
267 | 269 |
268 // Abbrev for TYPE_CODE_STRUCT_NAMED. | 270 // Abbrev for TYPE_CODE_STRUCT_NAMED. |
269 Abbv = new BitCodeAbbrev(); | 271 Abbv = new NaClBitCodeAbbrev(); |
270 Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAMED)); | 272 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_STRUCT_NAMED)); |
271 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked | 273 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // ispacked |
272 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 274 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
273 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 275 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
274 | 276 |
275 unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv); | 277 unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv); |
276 | 278 |
277 // Abbrev for TYPE_CODE_ARRAY. | 279 // Abbrev for TYPE_CODE_ARRAY. |
278 Abbv = new BitCodeAbbrev(); | 280 Abbv = new NaClBitCodeAbbrev(); |
279 Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_ARRAY)); | 281 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_ARRAY)); |
280 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size | 282 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // size |
281 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 283 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |
282 | 284 |
283 unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv); | 285 unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv); |
284 | 286 |
285 // Emit an entry count so the reader can reserve space. | 287 // Emit an entry count so the reader can reserve space. |
286 TypeVals.push_back(TypeList.size()); | 288 TypeVals.push_back(TypeList.size()); |
287 Stream.EmitRecord(naclbitc::TYPE_CODE_NUMENTRY, TypeVals); | 289 Stream.EmitRecord(naclbitc::TYPE_CODE_NUMENTRY, TypeVals); |
288 TypeVals.clear(); | 290 TypeVals.clear(); |
289 | 291 |
290 // Loop over all of the types, emitting each in turn. | 292 // Loop over all of the types, emitting each in turn. |
291 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { | 293 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 0/*TODO*/, Stream); | 483 0/*TODO*/, Stream); |
482 Entry = GCMap.size(); | 484 Entry = GCMap.size(); |
483 } | 485 } |
484 } | 486 } |
485 } | 487 } |
486 | 488 |
487 // Emit abbrev for globals, now that we know # sections and max alignment. | 489 // Emit abbrev for globals, now that we know # sections and max alignment. |
488 unsigned SimpleGVarAbbrev = 0; | 490 unsigned SimpleGVarAbbrev = 0; |
489 if (!M->global_empty()) { | 491 if (!M->global_empty()) { |
490 // Add an abbrev for common globals with no visibility or thread localness. | 492 // Add an abbrev for common globals with no visibility or thread localness. |
491 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 493 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
492 Abbv->Add(BitCodeAbbrevOp(naclbitc::MODULE_CODE_GLOBALVAR)); | 494 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::MODULE_CODE_GLOBALVAR)); |
493 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, | 495 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
494 Log2_32_Ceil(MaxGlobalType+1))); | 496 Log2_32_Ceil(MaxGlobalType+1))); |
495 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constant. | 497 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // Constant. |
496 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Initializer. | 498 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // Initialize
r. |
497 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // Linkage. | 499 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // Linkage. |
498 if (MaxAlignment == 0) // Alignment. | 500 if (MaxAlignment == 0) // Alignment. |
499 Abbv->Add(BitCodeAbbrevOp(0)); | 501 Abbv->Add(NaClBitCodeAbbrevOp(0)); |
500 else { | 502 else { |
501 unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1; | 503 unsigned MaxEncAlignment = Log2_32(MaxAlignment)+1; |
502 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, | 504 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
503 Log2_32_Ceil(MaxEncAlignment+1))); | 505 Log2_32_Ceil(MaxEncAlignment+1))); |
504 } | 506 } |
505 if (SectionMap.empty()) // Section. | 507 if (SectionMap.empty()) // Section. |
506 Abbv->Add(BitCodeAbbrevOp(0)); | 508 Abbv->Add(NaClBitCodeAbbrevOp(0)); |
507 else | 509 else |
508 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, | 510 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
509 Log2_32_Ceil(SectionMap.size()+1))); | 511 Log2_32_Ceil(SectionMap.size()+1))); |
510 // Don't bother emitting vis + thread local. | 512 // Don't bother emitting vis + thread local. |
511 SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv); | 513 SimpleGVarAbbrev = Stream.EmitAbbrev(Abbv); |
512 } | 514 } |
513 | 515 |
514 // Emit the global variable information. | 516 // Emit the global variable information. |
515 SmallVector<unsigned, 64> Vals; | 517 SmallVector<unsigned, 64> Vals; |
516 for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); | 518 for (Module::const_global_iterator GV = M->global_begin(),E = M->global_end(); |
517 GV != E; ++GV) { | 519 GV != E; ++GV) { |
518 unsigned AbbrevToUse = 0; | 520 unsigned AbbrevToUse = 0; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 642 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
641 StartedMetadataBlock = true; | 643 StartedMetadataBlock = true; |
642 } | 644 } |
643 WriteMDNode(N, VE, Stream, Record); | 645 WriteMDNode(N, VE, Stream, Record); |
644 } | 646 } |
645 } else if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) { | 647 } else if (const MDString *MDS = dyn_cast<MDString>(Vals[i].first)) { |
646 if (!StartedMetadataBlock) { | 648 if (!StartedMetadataBlock) { |
647 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 649 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
648 | 650 |
649 // Abbrev for METADATA_STRING. | 651 // Abbrev for METADATA_STRING. |
650 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 652 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
651 Abbv->Add(BitCodeAbbrevOp(naclbitc::METADATA_STRING)); | 653 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::METADATA_STRING)); |
652 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 654 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
653 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); | 655 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
654 MDSAbbrev = Stream.EmitAbbrev(Abbv); | 656 MDSAbbrev = Stream.EmitAbbrev(Abbv); |
655 StartedMetadataBlock = true; | 657 StartedMetadataBlock = true; |
656 } | 658 } |
657 | 659 |
658 // Code: [strchar x N] | 660 // Code: [strchar x N] |
659 Record.append(MDS->begin(), MDS->end()); | 661 Record.append(MDS->begin(), MDS->end()); |
660 | 662 |
661 // Emit the finished record. | 663 // Emit the finished record. |
662 Stream.EmitRecord(naclbitc::METADATA_STRING, Record, MDSAbbrev); | 664 Stream.EmitRecord(naclbitc::METADATA_STRING, Record, MDSAbbrev); |
663 Record.clear(); | 665 Record.clear(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 Record.push_back(MDs[i].first); | 739 Record.push_back(MDs[i].first); |
738 Record.push_back(VE.getValueID(MDs[i].second)); | 740 Record.push_back(VE.getValueID(MDs[i].second)); |
739 } | 741 } |
740 Stream.EmitRecord(naclbitc::METADATA_ATTACHMENT, Record, 0); | 742 Stream.EmitRecord(naclbitc::METADATA_ATTACHMENT, Record, 0); |
741 Record.clear(); | 743 Record.clear(); |
742 } | 744 } |
743 | 745 |
744 Stream.ExitBlock(); | 746 Stream.ExitBlock(); |
745 } | 747 } |
746 | 748 |
747 static void WriteModuleMetadataStore(const Module *M, NaClBitstreamWriter &Strea
m) { | 749 static void WriteModuleMetadataStore(const Module *M, |
| 750 NaClBitstreamWriter &Stream) { |
748 SmallVector<uint64_t, 64> Record; | 751 SmallVector<uint64_t, 64> Record; |
749 | 752 |
750 // Write metadata kinds | 753 // Write metadata kinds |
751 // METADATA_KIND - [n x [id, name]] | 754 // METADATA_KIND - [n x [id, name]] |
752 SmallVector<StringRef, 8> Names; | 755 SmallVector<StringRef, 8> Names; |
753 M->getMDKindNames(Names); | 756 M->getMDKindNames(Names); |
754 | 757 |
755 if (Names.empty()) return; | 758 if (Names.empty()) return; |
756 | 759 |
757 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); | 760 Stream.EnterSubblock(naclbitc::METADATA_BLOCK_ID, 3); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 | 813 |
811 Stream.EnterSubblock(naclbitc::CONSTANTS_BLOCK_ID, 4); | 814 Stream.EnterSubblock(naclbitc::CONSTANTS_BLOCK_ID, 4); |
812 | 815 |
813 unsigned AggregateAbbrev = 0; | 816 unsigned AggregateAbbrev = 0; |
814 unsigned String8Abbrev = 0; | 817 unsigned String8Abbrev = 0; |
815 unsigned CString7Abbrev = 0; | 818 unsigned CString7Abbrev = 0; |
816 unsigned CString6Abbrev = 0; | 819 unsigned CString6Abbrev = 0; |
817 // If this is a constant pool for the module, emit module-specific abbrevs. | 820 // If this is a constant pool for the module, emit module-specific abbrevs. |
818 if (isGlobal) { | 821 if (isGlobal) { |
819 // Abbrev for CST_CODE_AGGREGATE. | 822 // Abbrev for CST_CODE_AGGREGATE. |
820 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 823 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
821 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_AGGREGATE)); | 824 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_AGGREGATE)); |
822 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 825 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
823 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, Log2_32_Ceil(LastVal+1))); | 826 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
| 827 Log2_32_Ceil(LastVal+1))); |
824 AggregateAbbrev = Stream.EmitAbbrev(Abbv); | 828 AggregateAbbrev = Stream.EmitAbbrev(Abbv); |
825 | 829 |
826 // Abbrev for CST_CODE_STRING. | 830 // Abbrev for CST_CODE_STRING. |
827 Abbv = new BitCodeAbbrev(); | 831 Abbv = new NaClBitCodeAbbrev(); |
828 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_STRING)); | 832 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_STRING)); |
829 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 833 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
830 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); | 834 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
831 String8Abbrev = Stream.EmitAbbrev(Abbv); | 835 String8Abbrev = Stream.EmitAbbrev(Abbv); |
832 // Abbrev for CST_CODE_CSTRING. | 836 // Abbrev for CST_CODE_CSTRING. |
833 Abbv = new BitCodeAbbrev(); | 837 Abbv = new NaClBitCodeAbbrev(); |
834 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); | 838 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); |
835 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 839 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
836 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); | 840 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); |
837 CString7Abbrev = Stream.EmitAbbrev(Abbv); | 841 CString7Abbrev = Stream.EmitAbbrev(Abbv); |
838 // Abbrev for CST_CODE_CSTRING. | 842 // Abbrev for CST_CODE_CSTRING. |
839 Abbv = new BitCodeAbbrev(); | 843 Abbv = new NaClBitCodeAbbrev(); |
840 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); | 844 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CSTRING)); |
841 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 845 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
842 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | 846 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
843 CString6Abbrev = Stream.EmitAbbrev(Abbv); | 847 CString6Abbrev = Stream.EmitAbbrev(Abbv); |
844 } | 848 } |
845 | 849 |
846 SmallVector<uint64_t, 64> Record; | 850 SmallVector<uint64_t, 64> Record; |
847 | 851 |
848 const NaClValueEnumerator::ValueList &Vals = VE.getValues(); | 852 const NaClValueEnumerator::ValueList &Vals = VE.getValues(); |
849 Type *LastTy = 0; | 853 Type *LastTy = 0; |
850 for (unsigned i = FirstVal; i != LastVal; ++i) { | 854 for (unsigned i = FirstVal; i != LastVal; ++i) { |
851 const Value *V = Vals[i].first; | 855 const Value *V = Vals[i].first; |
852 // If we need to switch types, do so now. | 856 // If we need to switch types, do so now. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 Code = naclbitc::CST_CODE_STRING; | 924 Code = naclbitc::CST_CODE_STRING; |
921 AbbrevToUse = String8Abbrev; | 925 AbbrevToUse = String8Abbrev; |
922 } | 926 } |
923 bool isCStr7 = Code == naclbitc::CST_CODE_CSTRING; | 927 bool isCStr7 = Code == naclbitc::CST_CODE_CSTRING; |
924 bool isCStrChar6 = Code == naclbitc::CST_CODE_CSTRING; | 928 bool isCStrChar6 = Code == naclbitc::CST_CODE_CSTRING; |
925 for (unsigned i = 0; i != NumElts; ++i) { | 929 for (unsigned i = 0; i != NumElts; ++i) { |
926 unsigned char V = Str->getElementAsInteger(i); | 930 unsigned char V = Str->getElementAsInteger(i); |
927 Record.push_back(V); | 931 Record.push_back(V); |
928 isCStr7 &= (V & 128) == 0; | 932 isCStr7 &= (V & 128) == 0; |
929 if (isCStrChar6) | 933 if (isCStrChar6) |
930 isCStrChar6 = BitCodeAbbrevOp::isChar6(V); | 934 isCStrChar6 = NaClBitCodeAbbrevOp::isChar6(V); |
931 } | 935 } |
932 | 936 |
933 if (isCStrChar6) | 937 if (isCStrChar6) |
934 AbbrevToUse = CString6Abbrev; | 938 AbbrevToUse = CString6Abbrev; |
935 else if (isCStr7) | 939 else if (isCStr7) |
936 AbbrevToUse = CString7Abbrev; | 940 AbbrevToUse = CString7Abbrev; |
937 } else if (const ConstantDataSequential *CDS = | 941 } else if (const ConstantDataSequential *CDS = |
938 dyn_cast<ConstantDataSequential>(C)) { | 942 dyn_cast<ConstantDataSequential>(C)) { |
939 Code = naclbitc::CST_CODE_DATA; | 943 Code = naclbitc::CST_CODE_DATA; |
940 Type *EltTy = CDS->getType()->getElementType(); | 944 Type *EltTy = CDS->getType()->getElementType(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 static void pushValueSigned(const Value *V, unsigned InstID, | 1108 static void pushValueSigned(const Value *V, unsigned InstID, |
1105 SmallVector<uint64_t, 128> &Vals, | 1109 SmallVector<uint64_t, 128> &Vals, |
1106 NaClValueEnumerator &VE) { | 1110 NaClValueEnumerator &VE) { |
1107 unsigned ValID = VE.getValueID(V); | 1111 unsigned ValID = VE.getValueID(V); |
1108 int64_t diff = ((int32_t)InstID - (int32_t)ValID); | 1112 int64_t diff = ((int32_t)InstID - (int32_t)ValID); |
1109 emitSignedInt64(Vals, diff); | 1113 emitSignedInt64(Vals, diff); |
1110 } | 1114 } |
1111 | 1115 |
1112 /// WriteInstruction - Emit an instruction to the specified stream. | 1116 /// WriteInstruction - Emit an instruction to the specified stream. |
1113 static void WriteInstruction(const Instruction &I, unsigned InstID, | 1117 static void WriteInstruction(const Instruction &I, unsigned InstID, |
1114 NaClValueEnumerator &VE, NaClBitstreamWriter &Strea
m, | 1118 NaClValueEnumerator &VE, |
| 1119 NaClBitstreamWriter &Stream, |
1115 SmallVector<unsigned, 64> &Vals) { | 1120 SmallVector<unsigned, 64> &Vals) { |
1116 unsigned Code = 0; | 1121 unsigned Code = 0; |
1117 unsigned AbbrevToUse = 0; | 1122 unsigned AbbrevToUse = 0; |
1118 VE.setInstructionID(&I); | 1123 VE.setInstructionID(&I); |
1119 switch (I.getOpcode()) { | 1124 switch (I.getOpcode()) { |
1120 default: | 1125 default: |
1121 if (Instruction::isCast(I.getOpcode())) { | 1126 if (Instruction::isCast(I.getOpcode())) { |
1122 Code = naclbitc::FUNC_CODE_INST_CAST; | 1127 Code = naclbitc::FUNC_CODE_INST_CAST; |
1123 if (!PushValueAndType(I.getOperand(0), InstID, Vals, VE)) | 1128 if (!PushValueAndType(I.getOperand(0), InstID, Vals, VE)) |
1124 AbbrevToUse = FUNCTION_INST_CAST_ABBREV; | 1129 AbbrevToUse = FUNCTION_INST_CAST_ABBREV; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 SI != SE; ++SI) { | 1486 SI != SE; ++SI) { |
1482 | 1487 |
1483 const ValueName &Name = *SI; | 1488 const ValueName &Name = *SI; |
1484 | 1489 |
1485 // Figure out the encoding to use for the name. | 1490 // Figure out the encoding to use for the name. |
1486 bool is7Bit = true; | 1491 bool is7Bit = true; |
1487 bool isChar6 = true; | 1492 bool isChar6 = true; |
1488 for (const char *C = Name.getKeyData(), *E = C+Name.getKeyLength(); | 1493 for (const char *C = Name.getKeyData(), *E = C+Name.getKeyLength(); |
1489 C != E; ++C) { | 1494 C != E; ++C) { |
1490 if (isChar6) | 1495 if (isChar6) |
1491 isChar6 = BitCodeAbbrevOp::isChar6(*C); | 1496 isChar6 = NaClBitCodeAbbrevOp::isChar6(*C); |
1492 if ((unsigned char)*C & 128) { | 1497 if ((unsigned char)*C & 128) { |
1493 is7Bit = false; | 1498 is7Bit = false; |
1494 break; // don't bother scanning the rest. | 1499 break; // don't bother scanning the rest. |
1495 } | 1500 } |
1496 } | 1501 } |
1497 | 1502 |
1498 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV; | 1503 unsigned AbbrevToUse = VST_ENTRY_8_ABBREV; |
1499 | 1504 |
1500 // VST_ENTRY: [valueid, namechar x N] | 1505 // VST_ENTRY: [valueid, namechar x N] |
1501 // VST_BBENTRY: [bbid, namechar x N] | 1506 // VST_BBENTRY: [bbid, namechar x N] |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 // Emit names for all the instructions etc. | 1595 // Emit names for all the instructions etc. |
1591 WriteValueSymbolTable(F.getValueSymbolTable(), VE, Stream); | 1596 WriteValueSymbolTable(F.getValueSymbolTable(), VE, Stream); |
1592 | 1597 |
1593 if (NeedsMetadataAttachment) | 1598 if (NeedsMetadataAttachment) |
1594 WriteMetadataAttachment(F, VE, Stream); | 1599 WriteMetadataAttachment(F, VE, Stream); |
1595 VE.purgeFunction(); | 1600 VE.purgeFunction(); |
1596 Stream.ExitBlock(); | 1601 Stream.ExitBlock(); |
1597 } | 1602 } |
1598 | 1603 |
1599 // Emit blockinfo, which defines the standard abbreviations etc. | 1604 // Emit blockinfo, which defines the standard abbreviations etc. |
1600 static void WriteBlockInfo(const NaClValueEnumerator &VE, NaClBitstreamWriter &S
tream) { | 1605 static void WriteBlockInfo(const NaClValueEnumerator &VE, |
| 1606 NaClBitstreamWriter &Stream) { |
1601 // We only want to emit block info records for blocks that have multiple | 1607 // We only want to emit block info records for blocks that have multiple |
1602 // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. | 1608 // instances: CONSTANTS_BLOCK, FUNCTION_BLOCK and VALUE_SYMTAB_BLOCK. |
1603 // Other blocks can define their abbrevs inline. | 1609 // Other blocks can define their abbrevs inline. |
1604 Stream.EnterBlockInfoBlock(2); | 1610 Stream.EnterBlockInfoBlock(2); |
1605 | 1611 |
1606 { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. | 1612 { // 8-bit fixed-width VST_ENTRY/VST_BBENTRY strings. |
1607 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1613 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1608 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); | 1614 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 3)); |
1609 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | 1615 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
1610 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 1616 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
1611 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); | 1617 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 8)); |
1612 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, | 1618 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, |
1613 Abbv) != VST_ENTRY_8_ABBREV) | 1619 Abbv) != VST_ENTRY_8_ABBREV) |
1614 llvm_unreachable("Unexpected abbrev ordering!"); | 1620 llvm_unreachable("Unexpected abbrev ordering!"); |
1615 } | 1621 } |
1616 | 1622 |
1617 { // 7-bit fixed width VST_ENTRY strings. | 1623 { // 7-bit fixed width VST_ENTRY strings. |
1618 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1624 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1619 Abbv->Add(BitCodeAbbrevOp(naclbitc::VST_CODE_ENTRY)); | 1625 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::VST_CODE_ENTRY)); |
1620 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | 1626 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
1621 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 1627 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
1622 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); | 1628 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); |
1623 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, | 1629 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, |
1624 Abbv) != VST_ENTRY_7_ABBREV) | 1630 Abbv) != VST_ENTRY_7_ABBREV) |
1625 llvm_unreachable("Unexpected abbrev ordering!"); | 1631 llvm_unreachable("Unexpected abbrev ordering!"); |
1626 } | 1632 } |
1627 { // 6-bit char6 VST_ENTRY strings. | 1633 { // 6-bit char6 VST_ENTRY strings. |
1628 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1634 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1629 Abbv->Add(BitCodeAbbrevOp(naclbitc::VST_CODE_ENTRY)); | 1635 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::VST_CODE_ENTRY)); |
1630 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | 1636 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
1631 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 1637 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
1632 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | 1638 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
1633 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, | 1639 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, |
1634 Abbv) != VST_ENTRY_6_ABBREV) | 1640 Abbv) != VST_ENTRY_6_ABBREV) |
1635 llvm_unreachable("Unexpected abbrev ordering!"); | 1641 llvm_unreachable("Unexpected abbrev ordering!"); |
1636 } | 1642 } |
1637 { // 6-bit char6 VST_BBENTRY strings. | 1643 { // 6-bit char6 VST_BBENTRY strings. |
1638 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1644 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1639 Abbv->Add(BitCodeAbbrevOp(naclbitc::VST_CODE_BBENTRY)); | 1645 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::VST_CODE_BBENTRY)); |
1640 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | 1646 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
1641 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 1647 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Array)); |
1642 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | 1648 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Char6)); |
1643 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, | 1649 if (Stream.EmitBlockInfoAbbrev(naclbitc::VALUE_SYMTAB_BLOCK_ID, |
1644 Abbv) != VST_BBENTRY_6_ABBREV) | 1650 Abbv) != VST_BBENTRY_6_ABBREV) |
1645 llvm_unreachable("Unexpected abbrev ordering!"); | 1651 llvm_unreachable("Unexpected abbrev ordering!"); |
1646 } | 1652 } |
1647 | 1653 |
1648 | 1654 |
1649 | 1655 |
1650 { // SETTYPE abbrev for CONSTANTS_BLOCK. | 1656 { // SETTYPE abbrev for CONSTANTS_BLOCK. |
1651 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1657 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1652 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_SETTYPE)); | 1658 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_SETTYPE)); |
1653 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, | 1659 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, |
1654 Log2_32_Ceil(VE.getTypes().size()+1))); | 1660 Log2_32_Ceil(VE.getTypes().size()+1))); |
1655 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1661 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
1656 Abbv) != CONSTANTS_SETTYPE_ABBREV) | 1662 Abbv) != CONSTANTS_SETTYPE_ABBREV) |
1657 llvm_unreachable("Unexpected abbrev ordering!"); | 1663 llvm_unreachable("Unexpected abbrev ordering!"); |
1658 } | 1664 } |
1659 | 1665 |
1660 { // INTEGER abbrev for CONSTANTS_BLOCK. | 1666 { // INTEGER abbrev for CONSTANTS_BLOCK. |
1661 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1667 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1662 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_INTEGER)); | 1668 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_INTEGER)); |
1663 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | 1669 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); |
1664 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1670 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
1665 Abbv) != CONSTANTS_INTEGER_ABBREV) | 1671 Abbv) != CONSTANTS_INTEGER_ABBREV) |
1666 llvm_unreachable("Unexpected abbrev ordering!"); | 1672 llvm_unreachable("Unexpected abbrev ordering!"); |
1667 } | 1673 } |
1668 | 1674 |
1669 { // CE_CAST abbrev for CONSTANTS_BLOCK. | 1675 { // CE_CAST abbrev for CONSTANTS_BLOCK. |
1670 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1676 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1671 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_CE_CAST)); | 1677 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_CE_CAST)); |
1672 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // cast opc | 1678 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // cast opc |
1673 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // typeid | 1679 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, // typeid |
1674 Log2_32_Ceil(VE.getTypes().size()+1))); | 1680 Log2_32_Ceil(VE.getTypes().size()+1))); |
1675 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // value id | 1681 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 8)); // value id |
1676 | 1682 |
1677 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1683 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
1678 Abbv) != CONSTANTS_CE_CAST_Abbrev) | 1684 Abbv) != CONSTANTS_CE_CAST_Abbrev) |
1679 llvm_unreachable("Unexpected abbrev ordering!"); | 1685 llvm_unreachable("Unexpected abbrev ordering!"); |
1680 } | 1686 } |
1681 { // NULL abbrev for CONSTANTS_BLOCK. | 1687 { // NULL abbrev for CONSTANTS_BLOCK. |
1682 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1688 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1683 Abbv->Add(BitCodeAbbrevOp(naclbitc::CST_CODE_NULL)); | 1689 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::CST_CODE_NULL)); |
1684 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, | 1690 if (Stream.EmitBlockInfoAbbrev(naclbitc::CONSTANTS_BLOCK_ID, |
1685 Abbv) != CONSTANTS_NULL_Abbrev) | 1691 Abbv) != CONSTANTS_NULL_Abbrev) |
1686 llvm_unreachable("Unexpected abbrev ordering!"); | 1692 llvm_unreachable("Unexpected abbrev ordering!"); |
1687 } | 1693 } |
1688 | 1694 |
1689 // FIXME: This should only use space for first class types! | 1695 // FIXME: This should only use space for first class types! |
1690 | 1696 |
1691 { // INST_LOAD abbrev for FUNCTION_BLOCK. | 1697 { // INST_LOAD abbrev for FUNCTION_BLOCK. |
1692 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1698 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1693 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_LOAD)); | 1699 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_LOAD)); |
1694 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Ptr | 1700 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // Ptr |
1695 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 4)); // Align | 1701 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 4)); // Align |
1696 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // volatile | 1702 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 1)); // volatile |
1697 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1703 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1698 Abbv) != FUNCTION_INST_LOAD_ABBREV) | 1704 Abbv) != FUNCTION_INST_LOAD_ABBREV) |
1699 llvm_unreachable("Unexpected abbrev ordering!"); | 1705 llvm_unreachable("Unexpected abbrev ordering!"); |
1700 } | 1706 } |
1701 { // INST_BINOP abbrev for FUNCTION_BLOCK. | 1707 { // INST_BINOP abbrev for FUNCTION_BLOCK. |
1702 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1708 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1703 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_BINOP)); | 1709 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_BINOP)); |
1704 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS | 1710 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // LHS |
1705 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS | 1711 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // RHS |
1706 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc | 1712 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc |
1707 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1713 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1708 Abbv) != FUNCTION_INST_BINOP_ABBREV) | 1714 Abbv) != FUNCTION_INST_BINOP_ABBREV) |
1709 llvm_unreachable("Unexpected abbrev ordering!"); | 1715 llvm_unreachable("Unexpected abbrev ordering!"); |
1710 } | 1716 } |
1711 { // INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK. | 1717 { // INST_BINOP_FLAGS abbrev for FUNCTION_BLOCK. |
1712 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1718 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1713 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_BINOP)); | 1719 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_BINOP)); |
1714 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHS | 1720 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // LHS |
1715 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // RHS | 1721 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // RHS |
1716 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc | 1722 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc |
1717 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); // flags | 1723 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 7)); // flags |
1718 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1724 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1719 Abbv) != FUNCTION_INST_BINOP_FLAGS_ABBREV) | 1725 Abbv) != FUNCTION_INST_BINOP_FLAGS_ABBREV) |
1720 llvm_unreachable("Unexpected abbrev ordering!"); | 1726 llvm_unreachable("Unexpected abbrev ordering!"); |
1721 } | 1727 } |
1722 { // INST_CAST abbrev for FUNCTION_BLOCK. | 1728 { // INST_CAST abbrev for FUNCTION_BLOCK. |
1723 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1729 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1724 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_CAST)); | 1730 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_CAST)); |
1725 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpVal | 1731 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // OpVal |
1726 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, // dest ty | 1732 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, // dest ty |
1727 Log2_32_Ceil(VE.getTypes().size()+1))); | 1733 Log2_32_Ceil(VE.getTypes().size()+1))); |
1728 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 4)); // opc | 1734 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, 4)); // opc |
1729 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1735 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1730 Abbv) != FUNCTION_INST_CAST_ABBREV) | 1736 Abbv) != FUNCTION_INST_CAST_ABBREV) |
1731 llvm_unreachable("Unexpected abbrev ordering!"); | 1737 llvm_unreachable("Unexpected abbrev ordering!"); |
1732 } | 1738 } |
1733 | 1739 |
1734 { // INST_RET abbrev for FUNCTION_BLOCK. | 1740 { // INST_RET abbrev for FUNCTION_BLOCK. |
1735 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1741 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1736 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); | 1742 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); |
1737 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1743 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1738 Abbv) != FUNCTION_INST_RET_VOID_ABBREV) | 1744 Abbv) != FUNCTION_INST_RET_VOID_ABBREV) |
1739 llvm_unreachable("Unexpected abbrev ordering!"); | 1745 llvm_unreachable("Unexpected abbrev ordering!"); |
1740 } | 1746 } |
1741 { // INST_RET abbrev for FUNCTION_BLOCK. | 1747 { // INST_RET abbrev for FUNCTION_BLOCK. |
1742 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1748 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1743 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); | 1749 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_RET)); |
1744 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ValID | 1750 Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::VBR, 6)); // ValID |
1745 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1751 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1746 Abbv) != FUNCTION_INST_RET_VAL_ABBREV) | 1752 Abbv) != FUNCTION_INST_RET_VAL_ABBREV) |
1747 llvm_unreachable("Unexpected abbrev ordering!"); | 1753 llvm_unreachable("Unexpected abbrev ordering!"); |
1748 } | 1754 } |
1749 { // INST_UNREACHABLE abbrev for FUNCTION_BLOCK. | 1755 { // INST_UNREACHABLE abbrev for FUNCTION_BLOCK. |
1750 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 1756 NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); |
1751 Abbv->Add(BitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_UNREACHABLE)); | 1757 Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::FUNC_CODE_INST_UNREACHABLE)); |
1752 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, | 1758 if (Stream.EmitBlockInfoAbbrev(naclbitc::FUNCTION_BLOCK_ID, |
1753 Abbv) != FUNCTION_INST_UNREACHABLE_ABBREV) | 1759 Abbv) != FUNCTION_INST_UNREACHABLE_ABBREV) |
1754 llvm_unreachable("Unexpected abbrev ordering!"); | 1760 llvm_unreachable("Unexpected abbrev ordering!"); |
1755 } | 1761 } |
1756 | 1762 |
1757 Stream.ExitBlock(); | 1763 Stream.ExitBlock(); |
1758 } | 1764 } |
1759 | 1765 |
1760 /// WriteModule - Emit the specified module to the bitstream. | 1766 /// WriteModule - Emit the specified module to the bitstream. |
1761 static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) { | 1767 static void WriteModule(const Module *M, NaClBitstreamWriter &Stream) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 // Emit the module. | 1914 // Emit the module. |
1909 WriteModule(M, Stream); | 1915 WriteModule(M, Stream); |
1910 } | 1916 } |
1911 | 1917 |
1912 if (TT.isOSDarwin()) | 1918 if (TT.isOSDarwin()) |
1913 EmitDarwinBCHeaderAndTrailer(Buffer, TT); | 1919 EmitDarwinBCHeaderAndTrailer(Buffer, TT); |
1914 | 1920 |
1915 // Write the generated bitstream to "Out". | 1921 // Write the generated bitstream to "Out". |
1916 Out.write((char*)&Buffer.front(), Buffer.size()); | 1922 Out.write((char*)&Buffer.front(), Buffer.size()); |
1917 } | 1923 } |
OLD | NEW |