Changeset View
Changeset View
Standalone View
Standalone View
lib/Bitcode/Writer/BitcodeWriter.cpp
Show First 20 Lines • Show All 2,832 Lines • ▼ Show 20 Lines | static void WriteModStrings(const FunctionInfoIndex &I, | ||||
Stream.EnterSubblock(bitc::MODULE_STRTAB_BLOCK_ID, 3); | Stream.EnterSubblock(bitc::MODULE_STRTAB_BLOCK_ID, 3); | ||||
// TODO: See which abbrev sizes we actually need to emit | // TODO: See which abbrev sizes we actually need to emit | ||||
// 8-bit fixed-width MST_ENTRY strings. | // 8-bit fixed-width MST_ENTRY strings. | ||||
BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | BitCodeAbbrev *Abbv = new BitCodeAbbrev(); | ||||
Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY)); | Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | |||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 8)); | ||||
unsigned Abbrev8Bit = Stream.EmitAbbrev(Abbv); | unsigned Abbrev8Bit = Stream.EmitAbbrev(Abbv); | ||||
// 7-bit fixed width MST_ENTRY strings. | // 7-bit fixed width MST_ENTRY strings. | ||||
Abbv = new BitCodeAbbrev(); | Abbv = new BitCodeAbbrev(); | ||||
Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY)); | Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | |||||
tejohnson: What is the added VBR8 here and in the 6-bit case below? I don't see anything else being… | |||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); | ||||
unsigned Abbrev7Bit = Stream.EmitAbbrev(Abbv); | unsigned Abbrev7Bit = Stream.EmitAbbrev(Abbv); | ||||
// 6-bit char6 MST_ENTRY strings. | // 6-bit char6 MST_ENTRY strings. | ||||
Abbv = new BitCodeAbbrev(); | Abbv = new BitCodeAbbrev(); | ||||
Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY)); | Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_ENTRY)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); | |||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); | ||||
unsigned Abbrev6Bit = Stream.EmitAbbrev(Abbv); | unsigned Abbrev6Bit = Stream.EmitAbbrev(Abbv); | ||||
SmallVector<unsigned, 64> NameVals; | SmallVector<unsigned, 64> NameVals; | ||||
for (const StringMapEntry<uint64_t> &MPSE : I.modulePaths()) { | for (const auto &MPSE : I.modulePaths()) { | ||||
"Optionally emitted after..." tejohnson: "Optionally emitted after..." | |||||
StringEncoding Bits = | StringEncoding Bits = | ||||
getStringEncoding(MPSE.getKey().data(), MPSE.getKey().size()); | getStringEncoding(MPSE.getKey().data(), MPSE.getKey().size()); | ||||
unsigned AbbrevToUse = Abbrev8Bit; | unsigned AbbrevToUse = Abbrev8Bit; | ||||
if (Bits == SE_Char6) | if (Bits == SE_Char6) | ||||
AbbrevToUse = Abbrev6Bit; | AbbrevToUse = Abbrev6Bit; | ||||
else if (Bits == SE_Fixed7) | else if (Bits == SE_Fixed7) | ||||
AbbrevToUse = Abbrev7Bit; | AbbrevToUse = Abbrev7Bit; | ||||
NameVals.push_back(MPSE.getValue()); | NameVals.push_back(MPSE.getValue().first); | ||||
NameVals.push_back(MPSE.getValue().second); | |||||
for (const auto P : MPSE.getKey()) | for (const auto P : MPSE.getKey()) | ||||
NameVals.push_back((unsigned char)P); | NameVals.push_back((unsigned char)P); | ||||
// Emit the finished record. | // Emit the finished record. | ||||
Stream.EmitRecord(bitc::MST_CODE_ENTRY, NameVals, AbbrevToUse); | Stream.EmitRecord(bitc::MST_CODE_ENTRY, NameVals, AbbrevToUse); | ||||
NameVals.clear(); | NameVals.clear(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | static void WriteIdentificationBlock(const Module *M, BitstreamWriter &Stream) { | ||||
Abbv->Add(BitCodeAbbrevOp(bitc::IDENTIFICATION_CODE_EPOCH)); | Abbv->Add(BitCodeAbbrevOp(bitc::IDENTIFICATION_CODE_EPOCH)); | ||||
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); | Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); | ||||
auto EpochAbbrev = Stream.EmitAbbrev(Abbv); | auto EpochAbbrev = Stream.EmitAbbrev(Abbv); | ||||
SmallVector<unsigned, 1> Vals = {bitc::BITCODE_CURRENT_EPOCH}; | SmallVector<unsigned, 1> Vals = {bitc::BITCODE_CURRENT_EPOCH}; | ||||
Stream.EmitRecord(bitc::IDENTIFICATION_CODE_EPOCH, Vals, EpochAbbrev); | Stream.EmitRecord(bitc::IDENTIFICATION_CODE_EPOCH, Vals, EpochAbbrev); | ||||
Stream.ExitBlock(); | Stream.ExitBlock(); | ||||
} | } | ||||
static void writeModuleHash(BitstreamWriter &Stream) { | |||||
// Emit the module's hash. | |||||
// MODULE_CODE_HASH: [unsigned] | |||||
5*i32? tejohnson: 5*i32? | |||||
auto SHA1 = Stream.getCurrentHash(); | |||||
unsigned Hash = hash_combine_range(&*SHA1.begin(), &*SHA1.end()); | |||||
rafaelUnsubmitted This produces different results in 32 and 64 bit machines, no? rafael: This produces different results in 32 and 64 bit machines, no? | |||||
mehdi_aminiAuthorUnsubmitted Uh, dunno, is it a property of hash_combine_range? mehdi_amini: Uh, dunno, is it a property of hash_combine_range? | |||||
// Emit the finished record. | |||||
Stream.EmitRecord(bitc::MODULE_CODE_HASH, makeArrayRef(Hash)); | |||||
} | |||||
/// WriteModule - Emit the specified module to the bitstream. | /// WriteModule - Emit the specified module to the bitstream. | ||||
static void WriteModule(const Module *M, BitstreamWriter &Stream, | static void WriteModule(const Module *M, BitstreamWriter &Stream, | ||||
bool ShouldPreserveUseListOrder, | bool ShouldPreserveUseListOrder, | ||||
uint64_t BitcodeStartBit, bool EmitSummaryIndex) { | uint64_t BitcodeStartBit, bool EmitSummaryIndex) { | ||||
Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3); | Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3); | ||||
if (EmitSummaryIndex) | |||||
Please make this conditional so it isn't generating a hash if we aren't using a module cache. tejohnson: Please make this conditional so it isn't generating a hash if we aren't using a module cache. | |||||
Stream.enableHash(true); | |||||
SmallVector<unsigned, 1> Vals; | SmallVector<unsigned, 1> Vals; | ||||
unsigned CurVersion = 1; | unsigned CurVersion = 1; | ||||
Vals.push_back(CurVersion); | Vals.push_back(CurVersion); | ||||
Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals); | Stream.EmitRecord(bitc::MODULE_CODE_VERSION, Vals); | ||||
// Analyze the module, enumerating globals, functions, etc. | // Analyze the module, enumerating globals, functions, etc. | ||||
ValueEnumerator VE(*M, ShouldPreserveUseListOrder); | ValueEnumerator VE(*M, ShouldPreserveUseListOrder); | ||||
Show All 39 Lines | static void WriteModule(const Module *M, BitstreamWriter &Stream, | ||||
// Need to write after the above call to WriteFunction which populates | // Need to write after the above call to WriteFunction which populates | ||||
// the summary information in the index. | // the summary information in the index. | ||||
if (EmitSummaryIndex) | if (EmitSummaryIndex) | ||||
WritePerModuleGlobalValueSummary(FunctionIndex, M, VE, Stream); | WritePerModuleGlobalValueSummary(FunctionIndex, M, VE, Stream); | ||||
WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream, | WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream, | ||||
VSTOffsetPlaceholder, BitcodeStartBit, &FunctionIndex); | VSTOffsetPlaceholder, BitcodeStartBit, &FunctionIndex); | ||||
if (EmitSummaryIndex) { | |||||
ditto. tejohnson: ditto. | |||||
writeModuleHash(Stream); | |||||
Stream.enableHash(false); | |||||
} | |||||
Stream.ExitBlock(); | Stream.ExitBlock(); | ||||
} | } | ||||
/// EmitDarwinBCHeader - If generating a bc file on darwin, we have to emit a | /// EmitDarwinBCHeader - If generating a bc file on darwin, we have to emit a | ||||
/// header and trailer to make it compatible with the system archiver. To do | /// header and trailer to make it compatible with the system archiver. To do | ||||
/// this we emit the following header, and then emit a trailer that pads the | /// this we emit the following header, and then emit a trailer that pads the | ||||
/// file out to be a multiple of 16 bytes. | /// file out to be a multiple of 16 bytes. | ||||
/// | /// | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |
What is the added VBR8 here and in the 6-bit case below? I don't see anything else being written. And it isn't in the 8-bit case above.