llvm/llvm/unittests/ProfileData/InstrProfTest.cpp

//===- unittest/ProfileData/InstrProfTest.cpp -------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#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) {}
} // end namespace llvm

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) {}

// Profile data is copied from general.proftext
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() {}

// Populate all of the fields of MIB.
MemInfoBlock makeFullMIB() {}

// Populate those fields returned by getHotColdSchema.
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) {}

// callee1 to callee6 are from vtable1 to vtable6 respectively.
static const char callee1[] =;
static const char callee2[] =;
static const char callee3[] =;
static const char callee4[] =;
static const char callee5[] =;
static const char callee6[] =;
// callee7 and callee8 are not from any vtables.
static const char callee7[] =;
static const char callee8[] =;
// 'callee' is primarily used to create multiple-element vtables.
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[] =;

// Returns the address of callee with a numbered suffix in vtable.
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) {}

// This test tests that when there are too many values for a given site, the
// merged results are properly truncated.
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) {}

// Testing symtab creator interface used by indexed profile reader.
TEST(SymtabTest, instr_prof_symtab_test) {}

// Test that we get an error when creating a bogus symtab.
TEST(SymtabTest, instr_prof_bogus_symtab_empty_func_name) {}

// Testing symtab creator interface used by value profile transformer.
TEST(SymtabTest, instr_prof_symtab_module_test) {}

// Testing symtab serialization and creator/deserialization interface
// used by coverage map reader, and raw profile reader.
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; // 4GB

  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

} // end anonymous namespace