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

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 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 1161
1162 // First read header and verify it is good. 1162 // First read header and verify it is good.
1163 NaClBitcodeHeader Header; 1163 NaClBitcodeHeader Header;
1164 if (Header.Read(BufPtr, EndBufPtr) || !Header.IsSupported()) 1164 if (Header.Read(BufPtr, EndBufPtr))
1165 return Error("Invalid PNaCl bitcode header"); 1165 return Error("Invalid PNaCl bitcode header");
1166 if (!Header.IsSupported()) {
1167 errs() << Header.Unsupported();
1168 if (!Header.IsReadable())
1169 return Error("Invalid PNaCl bitcode header");
1170 }
1166 1171
1167 // Create a bitstream reader to read the bitcode file. 1172 // Create a bitstream reader to read the bitcode file.
1168 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 1173 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
1169 NaClBitstreamCursor Stream(StreamFile); 1174 NaClBitstreamCursor Stream(StreamFile);
1170 1175
1171 // Parse the the bitcode file. 1176 // Parse the the bitcode file.
1172 NaClAnalyzeParser Parser(Flags, Stream, BlockAbbrevsMap); 1177 NaClAnalyzeParser Parser(Flags, Stream, BlockAbbrevsMap);
1173 while (!Stream.AtEndOfStream()) { 1178 while (!Stream.AtEndOfStream()) {
1174 if (Parser.Parse()) return true; 1179 if (Parser.Parse()) return true;
1175 } 1180 }
1176 1181
1177 if (Flags.ShowAbbreviationFrequencies) 1182 if (Flags.ShowAbbreviationFrequencies)
1178 displayAbbreviationFrequencies(Output, Parser.BlockDist, BlockAbbrevsMap); 1183 displayAbbreviationFrequencies(Output, Parser.BlockDist, BlockAbbrevsMap);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 1387 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
1383 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); 1388 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
1384 1389
1385 // Read header. No verification is needed since AnalyzeBitcode has 1390 // Read header. No verification is needed since AnalyzeBitcode has
1386 // already checked it. 1391 // already checked it.
1387 NaClBitcodeHeader Header; 1392 NaClBitcodeHeader Header;
1388 if (Header.Read(BufPtr, EndBufPtr)) 1393 if (Header.Read(BufPtr, EndBufPtr))
1389 return Error("Invalid PNaCl bitcode header"); 1394 return Error("Invalid PNaCl bitcode header");
1390 1395
1391 // Create the bitcode reader. 1396 // Create the bitcode reader.
1392 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 1397 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
1393 NaClBitstreamCursor Stream(StreamFile); 1398 NaClBitstreamCursor Stream(StreamFile);
1394 1399
1395 // Set up the parser. 1400 // Set up the parser.
1396 NaClAssignAbbrevsParser Parser(Stream, AbbrevsMap, AbbrevsQueueMap); 1401 NaClAssignAbbrevsParser Parser(Stream, AbbrevsMap, AbbrevsQueueMap);
1397 1402
1398 // Parse the bitcode and choose abbreviations for records. 1403 // Parse the bitcode and choose abbreviations for records.
1399 while (!Stream.AtEndOfStream()) { 1404 while (!Stream.AtEndOfStream()) {
1400 if (Parser.Parse()) { 1405 if (Parser.Parse()) {
1401 installFrequentlyUsedAbbrevs(AbbrevsMap, AbbrevsQueueMap); 1406 installFrequentlyUsedAbbrevs(AbbrevsMap, AbbrevsQueueMap);
1402 return true; 1407 return true;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 1585 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
1581 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); 1586 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
1582 1587
1583 // Read header. No verification is needed since AnalyzeBitcode has 1588 // Read header. No verification is needed since AnalyzeBitcode has
1584 // already checked it. 1589 // already checked it.
1585 NaClBitcodeHeader Header; 1590 NaClBitcodeHeader Header;
1586 if (Header.Read(BufPtr, EndBufPtr)) 1591 if (Header.Read(BufPtr, EndBufPtr))
1587 return Error("Invalid PNaCl bitcode header"); 1592 return Error("Invalid PNaCl bitcode header");
1588 1593
1589 // Create the bitcode reader. 1594 // Create the bitcode reader.
1590 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 1595 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
1591 NaClBitstreamCursor Stream(StreamFile); 1596 NaClBitstreamCursor Stream(StreamFile);
1592 1597
1593 // Create the bitcode writer. 1598 // Create the bitcode writer.
1594 SmallVector<char, 0> OutputBuffer; 1599 SmallVector<char, 0> OutputBuffer;
1595 OutputBuffer.reserve(256 * 1024); 1600 OutputBuffer.reserve(256 * 1024);
1596 NaClBitstreamWriter StreamWriter(OutputBuffer); 1601 NaClBitstreamWriter StreamWriter(OutputBuffer);
1597 1602
1598 // Emit the file header. 1603 // Emit the file header.
1599 NaClWriteHeader(Header, StreamWriter); 1604 NaClWriteHeader(Header, StreamWriter);
1600 1605
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 BlockAbbrevsQueueMap AbbrevsQueueMap; 1648 BlockAbbrevsQueueMap AbbrevsQueueMap;
1644 bool Result = true; 1649 bool Result = true;
1645 if (chooseAbbrevs(MemBuf, BlockAbbrevsMap, AbbrevsQueueMap)) 1650 if (chooseAbbrevs(MemBuf, BlockAbbrevsMap, AbbrevsQueueMap))
1646 Result = false; 1651 Result = false;
1647 else if (copyBitcode(Flags, MemBuf, BitcodeOutput, BlockAbbrevsMap, 1652 else if (copyBitcode(Flags, MemBuf, BitcodeOutput, BlockAbbrevsMap,
1648 AbbrevsQueueMap)) 1653 AbbrevsQueueMap))
1649 Result = false; 1654 Result = false;
1650 DeleteContainerSeconds(AbbrevsQueueMap); 1655 DeleteContainerSeconds(AbbrevsQueueMap);
1651 return Result; 1656 return Result;
1652 } 1657 }
OLDNEW
« no previous file with comments | « lib/Bitcode/NaCl/Analysis/NaClBitcodeAnalyzer.cpp ('k') | lib/Bitcode/NaCl/Analysis/NaClObjDump.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698