summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ProfileData/SampleProfTest.cpp
diff options
context:
space:
mode:
authorWei Mi <wmi@google.com>2018-09-14 20:52:59 +0000
committerWei Mi <wmi@google.com>2018-09-14 20:52:59 +0000
commit6a14325dffb7a0607e5b3c75d93a837cadad54b4 (patch)
treeb66e8dff99504155918123b84a96f9577a905c10 /llvm/unittests/ProfileData/SampleProfTest.cpp
parent11511ab5cf306c7c688917bdd69e47dac7292756 (diff)
downloadbcm5719-llvm-6a14325dffb7a0607e5b3c75d93a837cadad54b4.tar.gz
bcm5719-llvm-6a14325dffb7a0607e5b3c75d93a837cadad54b4.zip
[SampleFDO] Add FunctionOffsetTable in compact binary format profile.
The patch saves a function offset table which maps function name index to the offset of its function profile to the start of the binary profile. By using the function offset table, for those function profiles which will not be used when compiling a module, the profile reader does't have to read them. For profile size around 10~20M, it saves ~10% compile time. Differential Revision: https://reviews.llvm.org/D51863 llvm-svn: 342283
Diffstat (limited to 'llvm/unittests/ProfileData/SampleProfTest.cpp')
-rw-r--r--llvm/unittests/ProfileData/SampleProfTest.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp
index 3ebfd0e500f..6c669445a2b 100644
--- a/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -36,14 +36,17 @@ static ::testing::AssertionResult NoError(std::error_code EC) {
namespace {
struct SampleProfTest : ::testing::Test {
- std::string Data;
LLVMContext Context;
+ std::string Profile;
std::unique_ptr<raw_ostream> OS;
std::unique_ptr<SampleProfileWriter> Writer;
std::unique_ptr<SampleProfileReader> Reader;
+ std::error_code EC;
SampleProfTest()
- : Data(), OS(new raw_string_ostream(Data)), Writer(), Reader() {}
+ : Profile("profile"),
+ OS(new raw_fd_ostream(Profile, EC, sys::fs::F_None)), Writer(),
+ Reader() {}
void createWriter(SampleProfileFormat Format) {
auto WriterOrErr = SampleProfileWriter::create(OS, Format);
@@ -51,10 +54,11 @@ struct SampleProfTest : ::testing::Test {
Writer = std::move(WriterOrErr.get());
}
- void readProfile(std::unique_ptr<MemoryBuffer> &Profile) {
+ void readProfile(const Module &M) {
auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
ASSERT_TRUE(NoError(ReaderOrErr.getError()));
Reader = std::move(ReaderOrErr.get());
+ Reader->collectFuncsToUse(M);
}
void testRoundTrip(SampleProfileFormat Format) {
@@ -83,6 +87,12 @@ struct SampleProfTest : ::testing::Test {
BarSamples.addCalledTargetSamples(1, 0, MconstructName, 1000);
BarSamples.addCalledTargetSamples(1, 0, StringviewName, 437);
+ Module M("my_module", Context);
+ FunctionType *fn_type =
+ FunctionType::get(Type::getVoidTy(Context), {}, false);
+ M.getOrInsertFunction(FooName, fn_type);
+ M.getOrInsertFunction(BarName, fn_type);
+
StringMap<FunctionSamples> Profiles;
Profiles[FooName] = std::move(FooSamples);
Profiles[BarName] = std::move(BarSamples);
@@ -93,8 +103,7 @@ struct SampleProfTest : ::testing::Test {
Writer->getOutputStream().flush();
- auto Profile = MemoryBuffer::getMemBufferCopy(Data);
- readProfile(Profile);
+ readProfile(M);
EC = Reader->read();
ASSERT_TRUE(NoError(EC));
@@ -164,7 +173,6 @@ struct SampleProfTest : ::testing::Test {
delete PS;
// Test that summary can be attached to and read back from module.
- Module M("my_module", Context);
M.setProfileSummary(MD);
MD = M.getProfileSummary();
ASSERT_TRUE(MD);
OpenPOWER on IntegriCloud