Chromium Code Reviews| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 224 } |
| 225 | 225 |
| 226 /// WriteTypeTable - Write out the type table for a module. | 226 /// WriteTypeTable - Write out the type table for a module. |
| 227 static void WriteTypeTable(const NaClValueEnumerator &VE, | 227 static void WriteTypeTable(const NaClValueEnumerator &VE, |
| 228 NaClBitstreamWriter &Stream) { | 228 NaClBitstreamWriter &Stream) { |
| 229 const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); | 229 const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); |
| 230 | 230 |
| 231 Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */); | 231 Stream.EnterSubblock(bitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */); |
| 232 SmallVector<uint64_t, 64> TypeVals; | 232 SmallVector<uint64_t, 64> TypeVals; |
| 233 | 233 |
| 234 // Note: modify to use maximum number of bits if under cutoff. Otherwise, | |
| 235 // use VBR to take advantage that frequently referenced types have | |
| 236 // small IDs. | |
| 237 // | |
| 238 // Note: Cutoff chosen based on experiments of some bit code files with | |
| 239 // a large number of types. | |
|
jvoung (off chromium)
2013/05/02 16:35:40
What is a large number of types, and on which benc
Karl
2013/05/15 20:12:20
I thought this is still worth adding, in that whil
jvoung (off chromium)
2013/05/15 21:01:36
Yeah, it would be more useful for upstream users.
| |
| 234 uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); | 240 uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); |
| 241 static const uint64_t TypeVBRCutoff = 6; | |
| 242 uint64_t TypeIdNumBits = (NumBits <= TypeVBRCutoff ? NumBits : TypeVBRCutoff); | |
| 243 BitCodeAbbrevOp::Encoding TypeIdEncoding = | |
| 244 (NumBits <= TypeVBRCutoff | |
| 245 ? BitCodeAbbrevOp::Fixed : BitCodeAbbrevOp::VBR); | |
| 235 | 246 |
| 236 // Abbrev for TYPE_CODE_POINTER. | 247 // Abbrev for TYPE_CODE_POINTER. |
| 237 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | 248 BitCodeAbbrev *Abbv = new BitCodeAbbrev(); |
| 238 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_POINTER)); | 249 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_POINTER)); |
| 239 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 250 Abbv->Add(BitCodeAbbrevOp(TypeIdEncoding, TypeIdNumBits)); |
| 240 Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0 | 251 Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0 |
| 241 unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv); | 252 unsigned PtrAbbrev = Stream.EmitAbbrev(Abbv); |
| 242 | 253 |
| 243 // Abbrev for TYPE_CODE_FUNCTION. | 254 // Abbrev for TYPE_CODE_FUNCTION. |
| 244 Abbv = new BitCodeAbbrev(); | 255 Abbv = new BitCodeAbbrev(); |
| 245 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_FUNCTION)); | 256 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_FUNCTION)); |
| 246 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg | 257 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isvararg |
| 247 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 258 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 248 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 259 Abbv->Add(BitCodeAbbrevOp(TypeIdEncoding, TypeIdNumBits)); |
| 249 | |
| 250 unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv); | 260 unsigned FunctionAbbrev = Stream.EmitAbbrev(Abbv); |
| 251 | 261 |
| 252 // Abbrev for TYPE_CODE_STRUCT_ANON. | 262 // Abbrev for TYPE_CODE_STRUCT_ANON. |
| 253 Abbv = new BitCodeAbbrev(); | 263 Abbv = new BitCodeAbbrev(); |
| 254 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_ANON)); | 264 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_ANON)); |
| 255 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked | 265 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked |
| 256 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 266 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 257 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 267 Abbv->Add(BitCodeAbbrevOp(TypeIdEncoding, TypeIdNumBits)); |
| 258 | |
| 259 unsigned StructAnonAbbrev = Stream.EmitAbbrev(Abbv); | 268 unsigned StructAnonAbbrev = Stream.EmitAbbrev(Abbv); |
| 260 | 269 |
| 261 // Abbrev for TYPE_CODE_STRUCT_NAME. | 270 // Abbrev for TYPE_CODE_STRUCT_NAME. |
| 262 Abbv = new BitCodeAbbrev(); | 271 Abbv = new BitCodeAbbrev(); |
| 263 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_NAME)); | 272 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_NAME)); |
| 264 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 273 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 265 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | 274 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); |
| 266 unsigned StructNameAbbrev = Stream.EmitAbbrev(Abbv); | 275 unsigned StructNameAbbrev = Stream.EmitAbbrev(Abbv); |
| 267 | 276 |
| 268 // Abbrev for TYPE_CODE_STRUCT_NAMED. | 277 // Abbrev for TYPE_CODE_STRUCT_NAMED. |
| 269 Abbv = new BitCodeAbbrev(); | 278 Abbv = new BitCodeAbbrev(); |
| 270 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_NAMED)); | 279 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_STRUCT_NAMED)); |
| 271 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked | 280 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ispacked |
| 272 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | 281 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
| 273 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 282 Abbv->Add(BitCodeAbbrevOp(TypeIdEncoding, TypeIdNumBits)); |
| 274 | |
| 275 unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv); | 283 unsigned StructNamedAbbrev = Stream.EmitAbbrev(Abbv); |
| 276 | 284 |
| 277 // Abbrev for TYPE_CODE_ARRAY. | 285 // Abbrev for TYPE_CODE_ARRAY. |
| 278 Abbv = new BitCodeAbbrev(); | 286 Abbv = new BitCodeAbbrev(); |
| 279 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY)); | 287 Abbv->Add(BitCodeAbbrevOp(bitc::TYPE_CODE_ARRAY)); |
| 280 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size | 288 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // size |
| 281 Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); | 289 Abbv->Add(BitCodeAbbrevOp(TypeIdEncoding, TypeIdNumBits)); |
| 282 | |
| 283 unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv); | 290 unsigned ArrayAbbrev = Stream.EmitAbbrev(Abbv); |
| 284 | 291 |
| 285 // Emit an entry count so the reader can reserve space. | 292 // Emit an entry count so the reader can reserve space. |
| 286 TypeVals.push_back(TypeList.size()); | 293 TypeVals.push_back(TypeList.size()); |
| 287 Stream.EmitRecord(bitc::TYPE_CODE_NUMENTRY, TypeVals); | 294 Stream.EmitRecord(bitc::TYPE_CODE_NUMENTRY, TypeVals); |
| 288 TypeVals.clear(); | 295 TypeVals.clear(); |
| 289 | 296 |
| 290 // Loop over all of the types, emitting each in turn. | 297 // Loop over all of the types, emitting each in turn. |
| 291 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { | 298 for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { |
| 292 Type *T = TypeList[i]; | 299 Type *T = TypeList[i]; |
| (...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1908 // Emit the module. | 1915 // Emit the module. |
| 1909 WriteModule(M, Stream); | 1916 WriteModule(M, Stream); |
| 1910 } | 1917 } |
| 1911 | 1918 |
| 1912 if (TT.isOSDarwin()) | 1919 if (TT.isOSDarwin()) |
| 1913 EmitDarwinBCHeaderAndTrailer(Buffer, TT); | 1920 EmitDarwinBCHeaderAndTrailer(Buffer, TT); |
| 1914 | 1921 |
| 1915 // Write the generated bitstream to "Out". | 1922 // Write the generated bitstream to "Out". |
| 1916 Out.write((char*)&Buffer.front(), Buffer.size()); | 1923 Out.write((char*)&Buffer.front(), Buffer.size()); |
| 1917 } | 1924 } |
| OLD | NEW |