summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Compressor.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-01-29 17:05:56 +0000
committerChris Lattner <sabre@nondot.org>2005-01-29 17:05:56 +0000
commitbb4384ba71b4ce5a28a76ea354ab54136c71e1c4 (patch)
treea3f64578ac586a387735622304fe3655578651a4 /llvm/lib/Support/Compressor.cpp
parent173340640a7828138dda167d813d1f87ed358157 (diff)
downloadbcm5719-llvm-bb4384ba71b4ce5a28a76ea354ab54136c71e1c4.tar.gz
bcm5719-llvm-bb4384ba71b4ce5a28a76ea354ab54136c71e1c4.zip
After reading in a bc file, trim the resultant buffer down to what we
really need. This reduces 4M of memory consumption reading 176.gcc. llvm-svn: 19916
Diffstat (limited to 'llvm/lib/Support/Compressor.cpp')
-rw-r--r--llvm/lib/Support/Compressor.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Support/Compressor.cpp b/llvm/lib/Support/Compressor.cpp
index 43e85495a1b..167b26b53f4 100644
--- a/llvm/lib/Support/Compressor.cpp
+++ b/llvm/lib/Support/Compressor.cpp
@@ -119,7 +119,7 @@ namespace {
struct BufferContext {
char* buff;
unsigned size;
- BufferContext(unsigned compressedSize ) {
+ BufferContext(unsigned compressedSize) {
// Null to indicate malloc of a new block
buff = 0;
@@ -128,12 +128,21 @@ struct BufferContext {
// in the callback for an initial allocation of 4x compressedSize. This
// calculation is based on the typical compression ratio of bzip2 on LLVM
// bytecode files which typically ranges in the 50%-75% range. Since we
- // tyipcally get at least 50%, doubling is insufficient. By using a 4x
+ // typically get at least 50%, doubling is insufficient. By using a 4x
// multiplier on the first allocation, we minimize the impact of having to
// copy the buffer on reallocation.
size = compressedSize*2;
}
+ /// trimTo - Reduce the size of the buffer down to the specified amount. This
+ /// is useful after have read in the bytecode file to discard extra unused
+ /// memory.
+ ///
+ void trimTo(size_t NewSize) {
+ buff = (char*)::realloc(buff, NewSize);
+ size = NewSize;
+ }
+
/// This function handles allocation of the buffer used for decompression of
/// compressed bytecode files. It is called by Compressor::decompress which is
/// called by BytecodeReader::ParseBytecode.
@@ -333,6 +342,7 @@ uint64_t
Compressor::compressToNewBuffer(const char* in, unsigned size, char*&out) {
BufferContext bc(size);
uint64_t result = compress(in,size,BufferContext::callback,(void*)&bc);
+ bc.trimTo(result);
out = bc.buff;
return result;
}
OpenPOWER on IntegriCloud