1 //===- ModuleSummaryIndexTest.cpp - ModuleSummaryIndex Unit Tests-============//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/ModuleSummaryIndex.h"
10 #include "llvm/AsmParser/Parser.h"
11 #include "llvm/Support/SourceMgr.h"
12 #include "gtest/gtest.h"
18 static std::unique_ptr
<ModuleSummaryIndex
> makeLLVMIndex(const char *Summary
) {
20 std::unique_ptr
<ModuleSummaryIndex
> Index
=
21 parseSummaryIndexAssemblyString(Summary
, Err
);
23 Err
.print("ModuleSummaryIndexTest", errs());
27 TEST(ModuleSummaryIndexTest
, MemProfSummaryPrinting
) {
28 std::unique_ptr
<ModuleSummaryIndex
> Index
= makeLLVMIndex(R
"Summary(
29 ^0 = module: (path: "test
.o
", hash: (0, 0, 0, 0, 0))
30 ^1 = gv: (guid: 23, summaries: (function: (module: ^0, flags: (linkage: external), insts: 2, allocs: ((versions: (none), memProf: ((type: notcold, stackIds: (1, 2, 3, 4)), (type: cold, stackIds: (1, 2, 3, 5))))))))
31 ^2 = gv: (guid: 25, summaries: (function: (module: ^0, flags: (linkage: external), insts: 22, calls: ((callee: ^1)), callsites: ((callee: ^1, clones: (0), stackIds: (3, 4)), (callee: ^1, clones: (0), stackIds: (3, 5))))))
35 raw_string_ostream
OS(Data
);
37 ASSERT_NE(Index
, nullptr);
38 auto *CallsiteSummary
=
39 cast
<FunctionSummary
>(Index
->getGlobalValueSummary(/*guid=*/25));
40 for (auto &CI
: CallsiteSummary
->callsites())
44 cast
<FunctionSummary
>(Index
->getGlobalValueSummary(/*guid=*/23));
45 for (auto &AI
: AllocSummary
->allocs())
49 Callee: 23 Clones: 0 StackIds: 2, 3
50 Callee: 23 Clones: 0 StackIds: 2, 4
52 AllocType 1 StackIds: 0, 1, 2, 3
53 AllocType 2 StackIds: 0, 1, 2, 4
56 } // end anonymous namespace