#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/ProfileData/InstrProfWriter.h"
#include "llvm/ProfileData/MemProf.h"
#include "llvm/ProfileData/MemProfData.inc"
#include "llvm/Support/Compression.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
#include <cstdarg>
#include <optional>
usingnamespacellvm;
EndsWith;
IsSubsetOf;
SizeIs;
UnorderedElementsAre;
[[nodiscard]] static ::testing::AssertionResult
ErrorEquals(instrprof_error Expected, Error E) { … }
namespace llvm {
bool operator==(const TemporalProfTraceTy &lhs,
const TemporalProfTraceTy &rhs) { … }
}
namespace {
struct InstrProfTest : ::testing::Test { … };
struct SparseInstrProfTest : public InstrProfTest { … };
struct InstrProfReaderWriterTest
: public InstrProfTest,
public ::testing::WithParamInterface<
std::tuple<bool, uint64_t, llvm::endianness>> { … };
struct MaybeSparseInstrProfTest : public InstrProfTest,
public ::testing::WithParamInterface<bool> { … };
TEST_P(MaybeSparseInstrProfTest, write_and_read_empty_profile) { … }
static const auto Err = …;
TEST_P(MaybeSparseInstrProfTest, write_and_read_one_function) { … }
TEST_P(MaybeSparseInstrProfTest, get_instr_prof_record) { … }
TEST_P(MaybeSparseInstrProfTest, get_function_counts) { … }
TEST_F(InstrProfTest, get_profile_summary) { … }
TEST_F(InstrProfTest, test_writer_merge) { … }
TEST_F(InstrProfTest, test_merge_temporal_prof_traces_truncated) { … }
TEST_F(InstrProfTest, test_merge_traces_from_writer) { … }
TEST_F(InstrProfTest, test_merge_traces_sampled) { … }
IndexedMemProfRecord;
MemInfoBlock;
FrameIdMapTy;
CallStackIdMapTy;
static FrameIdMapTy getFrameMapping() { … }
static CallStackIdMapTy getCallStackMapping() { … }
MemInfoBlock makeFullMIB() { … }
MemInfoBlock makePartialMIB() { … }
IndexedMemProfRecord makeRecord(
std::initializer_list<std::initializer_list<::llvm::memprof::FrameId>>
AllocFrames,
std::initializer_list<std::initializer_list<::llvm::memprof::FrameId>>
CallSiteFrames,
const MemInfoBlock &Block = makeFullMIB()) { … }
IndexedMemProfRecord
makeRecordV2(std::initializer_list<::llvm::memprof::CallStackId> AllocFrames,
std::initializer_list<::llvm::memprof::CallStackId> CallSiteFrames,
const MemInfoBlock &Block, const memprof::MemProfSchema &Schema) { … }
MATCHER_P(EqualsRecord, Want, "") { … }
TEST_F(InstrProfTest, test_memprof_v0) { … }
TEST_F(InstrProfTest, test_memprof_v2_full_schema) { … }
TEST_F(InstrProfTest, test_memprof_v2_partial_schema) { … }
TEST_F(InstrProfTest, test_memprof_getrecord_error) { … }
TEST_F(InstrProfTest, test_memprof_merge) { … }
TEST_F(InstrProfTest, test_irpgo_function_name) { … }
TEST_F(InstrProfTest, test_pgo_function_name) { … }
TEST_F(InstrProfTest, test_irpgo_read_deprecated_names) { … }
static const char callee1[] = …;
static const char callee2[] = …;
static const char callee3[] = …;
static const char callee4[] = …;
static const char callee5[] = …;
static const char callee6[] = …;
static const char callee7[] = …;
static const char callee8[] = …;
static const char callee[] = …;
static const uint64_t vtable1[] = …;
static const uint64_t vtable2[] = …;
static const uint64_t vtable3[] = …;
static const uint64_t vtable4[] = …;
static const uint64_t vtable5[] = …;
static const uint64_t vtable6[] = …;
static uint64_t getCalleeAddress(const uint64_t *vtableAddr) { … }
TEST_P(InstrProfReaderWriterTest, icall_and_vtable_data_read_write) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(MaybeSparseInstrProfTest, annotate_vp_data) { … }
TEST_P(MaybeSparseInstrProfTest, icall_and_vtable_data_merge) { … }
struct ValueProfileMergeEdgeCaseTest
: public InstrProfTest,
public ::testing::WithParamInterface<std::tuple<bool, uint32_t>> { … };
TEST_P(ValueProfileMergeEdgeCaseTest, value_profile_data_merge_saturation) { … }
TEST_P(ValueProfileMergeEdgeCaseTest, value_profile_data_merge_site_trunc) { … }
INSTANTIATE_TEST_SUITE_P(…);
static void addValueProfData(InstrProfRecord &Record) { … }
TEST(ValueProfileReadWriteTest, value_prof_data_read_write) { … }
TEST(ValueProfileReadWriteTest, symtab_mapping) { … }
TEST_P(MaybeSparseInstrProfTest, get_max_function_count) { … }
TEST_P(MaybeSparseInstrProfTest, get_weighted_function_counts) { … }
TEST(SymtabTest, instr_prof_symtab_test) { … }
TEST(SymtabTest, instr_prof_bogus_symtab_empty_func_name) { … }
TEST(SymtabTest, instr_prof_symtab_module_test) { … }
TEST(SymtabTest, instr_prof_symtab_compression_test) { … }
TEST_P(MaybeSparseInstrProfTest, remapping_test) { … }
TEST_F(SparseInstrProfTest, preserve_no_records) { … }
INSTANTIATE_TEST_SUITE_P(…);
#if defined(_LP64) && defined(EXPENSIVE_CHECKS)
TEST(ProfileReaderTest, ReadsLargeFiles) {
const size_t LargeSize = 1ULL << 32;
auto RawProfile = WritableMemoryBuffer::getNewUninitMemBuffer(LargeSize);
if (!RawProfile)
GTEST_SKIP();
auto RawProfileReaderOrErr = InstrProfReader::create(std::move(RawProfile));
ASSERT_TRUE(
std::get<0>(InstrProfError::take(RawProfileReaderOrErr.takeError())) ==
instrprof_error::unrecognized_format);
auto IndexedProfile = WritableMemoryBuffer::getNewUninitMemBuffer(LargeSize);
if (!IndexedProfile)
GTEST_SKIP();
auto IndexedReaderOrErr =
IndexedInstrProfReader::create(std::move(IndexedProfile), nullptr);
ASSERT_TRUE(
std::get<0>(InstrProfError::take(IndexedReaderOrErr.takeError())) ==
instrprof_error::bad_magic);
}
#endif
}