Skip to content

Commit

Permalink
Add MemoryBuffer::getBufferKind() to report whether a memory buffer u…
Browse files Browse the repository at this point in the history
…ses malloc'ed or mmap'ed memory. This is for performance analysis.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130432 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Apr 28, 2011
1 parent 81ad03c commit 5d86759
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/llvm/Support/MemoryBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ class MemoryBuffer {
static error_code getFileOrSTDIN(const char *Filename,
OwningPtr<MemoryBuffer> &result,
int64_t FileSize = -1);


//===--------------------------------------------------------------------===//
// Provided for performance analysis.
//===--------------------------------------------------------------------===//

/// The kind of memory backing used to support the MemoryBuffer.
enum BufferKind {
MemoryBuffer_Malloc,
MemoryBuffer_MMap
};

/// Return information on the memory mechanism used to support the
/// MemoryBuffer.
virtual BufferKind getBufferKind() const = 0;
};

} // end namespace llvm
Expand Down
8 changes: 8 additions & 0 deletions lib/Support/MemoryBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class MemoryBufferMem : public MemoryBuffer {
// The name is stored after the class itself.
return reinterpret_cast<const char*>(this + 1);
}

virtual BufferKind getBufferKind() const {
return MemoryBuffer_Malloc;
}
};
}

Expand Down Expand Up @@ -191,6 +195,10 @@ class MemoryBufferMMapFile : public MemoryBufferMem {
sys::Path::UnMapFilePages(reinterpret_cast<const char*>(RealStart),
RealSize);
}

virtual BufferKind getBufferKind() const {
return MemoryBuffer_MMap;
}
};
}

Expand Down

0 comments on commit 5d86759

Please sign in to comment.