Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1544)

Side by Side Diff: lib/Bitcode/NaCl/Analysis/NaClCompress.cpp

Issue 1122423005: Add (unsupported experimental) feature allowing byte aligned bitcode. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===-- NaClCompress.cpp - Bitcode (abbrev) compression -----------------===// 1 //===-- NaClCompress.cpp - Bitcode (abbrev) compression -----------------===//
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 // Analyzes the data in memory buffer, and determines what 10 // Analyzes the data in memory buffer, and determines what
(...skipping 1140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 MemoryBuffer *MemBuf, 1151 MemoryBuffer *MemBuf,
1152 raw_ostream &Output, 1152 raw_ostream &Output,
1153 BlockAbbrevsMapType &BlockAbbrevsMap) { 1153 BlockAbbrevsMapType &BlockAbbrevsMap) {
1154 // TODO(kschimpf): The current code only extracts abbreviations 1154 // TODO(kschimpf): The current code only extracts abbreviations
1155 // defined in the bitcode file. This code needs to be updated to 1155 // defined in the bitcode file. This code needs to be updated to
1156 // collect data distributions and figure out better (global) 1156 // collect data distributions and figure out better (global)
1157 // abbreviations to use. 1157 // abbreviations to use.
1158 1158
1159 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 1159 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
1160 const unsigned char *EndBufPtr = BufPtr+MemBuf->getBufferSize(); 1160 const unsigned char *EndBufPtr = BufPtr+MemBuf->getBufferSize();
1161 const unsigned char *HeaderPtr = BufPtr;
1161 1162
1162 // First read header and verify it is good. 1163 // First read header and verify it is good.
1163 NaClBitcodeHeader Header; 1164 NaClBitcodeHeader Header;
1164 if (Header.Read(BufPtr, EndBufPtr) || !Header.IsSupported()) 1165 if (Header.Read(HeaderPtr, EndBufPtr) || !Header.IsSupported())
jvoung (off chromium) 2015/05/07 18:11:17 Should this check of Read vs IsSupported be split
Karl 2015/05/07 22:18:54 Good point. Changing.
1165 return Error("Invalid PNaCl bitcode header"); 1166 return Error("Invalid PNaCl bitcode header");
1166 1167
1167 // Create a bitstream reader to read the bitcode file. 1168 // Create a bitstream reader to read the bitcode file.
1168 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 1169 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
1169 NaClBitstreamCursor Stream(StreamFile); 1170 NaClBitstreamCursor Stream(StreamFile);
1170 1171
1171 // Parse the the bitcode file. 1172 // Parse the the bitcode file.
1172 NaClAnalyzeParser Parser(Flags, Stream, BlockAbbrevsMap); 1173 NaClAnalyzeParser Parser(Flags, Stream, BlockAbbrevsMap);
1173 while (!Stream.AtEndOfStream()) { 1174 while (!Stream.AtEndOfStream()) {
1174 if (Parser.Parse()) return true; 1175 if (Parser.Parse()) return true;
1175 } 1176 }
1176 1177
1177 if (Flags.ShowAbbreviationFrequencies) 1178 if (Flags.ShowAbbreviationFrequencies)
1178 displayAbbreviationFrequencies(Output, Parser.BlockDist, BlockAbbrevsMap); 1179 displayAbbreviationFrequencies(Output, Parser.BlockDist, BlockAbbrevsMap);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 return Parser.ParseThisBlock(); 1375 return Parser.ParseThisBlock();
1375 } 1376 }
1376 1377
1377 // Reads the bitcode in MemBuf, using the abbreviations in AbbrevsMap, 1378 // Reads the bitcode in MemBuf, using the abbreviations in AbbrevsMap,
1378 // and queues the selected abbrevations for each record into 1379 // and queues the selected abbrevations for each record into
1379 // AbbrevsQueueMap. 1380 // AbbrevsQueueMap.
1380 static bool chooseAbbrevs(MemoryBuffer *MemBuf, BlockAbbrevsMapType &AbbrevsMap, 1381 static bool chooseAbbrevs(MemoryBuffer *MemBuf, BlockAbbrevsMapType &AbbrevsMap,
1381 BlockAbbrevsQueueMap &AbbrevsQueueMap) { 1382 BlockAbbrevsQueueMap &AbbrevsQueueMap) {
1382 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 1383 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
1383 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); 1384 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
1385 const unsigned char *HeaderPtr = BufPtr;
1384 1386
1385 // Read header. No verification is needed since AnalyzeBitcode has 1387 // Read header. No verification is needed since AnalyzeBitcode has
1386 // already checked it. 1388 // already checked it.
1387 NaClBitcodeHeader Header; 1389 NaClBitcodeHeader Header;
1388 if (Header.Read(BufPtr, EndBufPtr)) 1390 if (Header.Read(HeaderPtr, EndBufPtr))
1389 return Error("Invalid PNaCl bitcode header"); 1391 return Error("Invalid PNaCl bitcode header");
1390 1392
1391 // Create the bitcode reader. 1393 // Create the bitcode reader.
1392 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 1394 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
1393 NaClBitstreamCursor Stream(StreamFile); 1395 NaClBitstreamCursor Stream(StreamFile);
1394 1396
1395 // Set up the parser. 1397 // Set up the parser.
1396 NaClAssignAbbrevsParser Parser(Stream, AbbrevsMap, AbbrevsQueueMap); 1398 NaClAssignAbbrevsParser Parser(Stream, AbbrevsMap, AbbrevsQueueMap);
1397 1399
1398 // Parse the bitcode and choose abbreviations for records. 1400 // Parse the bitcode and choose abbreviations for records.
1399 while (!Stream.AtEndOfStream()) { 1401 while (!Stream.AtEndOfStream()) {
1400 if (Parser.Parse()) { 1402 if (Parser.Parse()) {
1401 installFrequentlyUsedAbbrevs(AbbrevsMap, AbbrevsQueueMap); 1403 installFrequentlyUsedAbbrevs(AbbrevsMap, AbbrevsQueueMap);
1402 return true; 1404 return true;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 // Read in bitcode, and write it back out using the abbreviations in 1574 // Read in bitcode, and write it back out using the abbreviations in
1573 // BlockAbbrevsMap, from memory buffer MemBuf containing the input 1575 // BlockAbbrevsMap, from memory buffer MemBuf containing the input
1574 // bitcode file. The bitcode is copied to Output. 1576 // bitcode file. The bitcode is copied to Output.
1575 static bool copyBitcode(const NaClBitcodeCompressor::CompressFlags &Flags, 1577 static bool copyBitcode(const NaClBitcodeCompressor::CompressFlags &Flags,
1576 MemoryBuffer *MemBuf, raw_ostream &Output, 1578 MemoryBuffer *MemBuf, raw_ostream &Output,
1577 BlockAbbrevsMapType &BlockAbbrevsMap, 1579 BlockAbbrevsMapType &BlockAbbrevsMap,
1578 BlockAbbrevsQueueMap &AbbrevsQueueMap) { 1580 BlockAbbrevsQueueMap &AbbrevsQueueMap) {
1579 1581
1580 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 1582 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
1581 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); 1583 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
1584 const unsigned char *HeaderPtr = BufPtr;
1582 1585
1583 // Read header. No verification is needed since AnalyzeBitcode has 1586 // Read header. No verification is needed since AnalyzeBitcode has
1584 // already checked it. 1587 // already checked it.
1585 NaClBitcodeHeader Header; 1588 NaClBitcodeHeader Header;
1586 if (Header.Read(BufPtr, EndBufPtr)) 1589 if (Header.Read(HeaderPtr, EndBufPtr))
1587 return Error("Invalid PNaCl bitcode header"); 1590 return Error("Invalid PNaCl bitcode header");
1588 1591
1589 // Create the bitcode reader. 1592 // Create the bitcode reader.
1590 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 1593 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
1591 NaClBitstreamCursor Stream(StreamFile); 1594 NaClBitstreamCursor Stream(StreamFile);
1592 1595
1593 // Create the bitcode writer. 1596 // Create the bitcode writer.
1594 SmallVector<char, 0> OutputBuffer; 1597 SmallVector<char, 0> OutputBuffer;
1595 OutputBuffer.reserve(256 * 1024); 1598 OutputBuffer.reserve(256 * 1024);
1596 NaClBitstreamWriter StreamWriter(OutputBuffer); 1599 NaClBitstreamWriter StreamWriter(OutputBuffer);
1597 1600
1598 // Emit the file header. 1601 // Emit the file header.
1599 NaClWriteHeader(Header, StreamWriter); 1602 NaClWriteHeader(Header, StreamWriter);
1600 1603
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 BlockAbbrevsQueueMap AbbrevsQueueMap; 1646 BlockAbbrevsQueueMap AbbrevsQueueMap;
1644 bool Result = true; 1647 bool Result = true;
1645 if (chooseAbbrevs(MemBuf, BlockAbbrevsMap, AbbrevsQueueMap)) 1648 if (chooseAbbrevs(MemBuf, BlockAbbrevsMap, AbbrevsQueueMap))
1646 Result = false; 1649 Result = false;
1647 else if (copyBitcode(Flags, MemBuf, BitcodeOutput, BlockAbbrevsMap, 1650 else if (copyBitcode(Flags, MemBuf, BitcodeOutput, BlockAbbrevsMap,
1648 AbbrevsQueueMap)) 1651 AbbrevsQueueMap))
1649 Result = false; 1652 Result = false;
1650 DeleteContainerSeconds(AbbrevsQueueMap); 1653 DeleteContainerSeconds(AbbrevsQueueMap);
1651 return Result; 1654 return Result;
1652 } 1655 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698