1 //===- InlineCostTest.cpp - test for InlineCost ---------------------------===//
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/Analysis/InlineCost.h"
10 #include "llvm/Analysis/AssumptionCache.h"
11 #include "llvm/Analysis/TargetTransformInfo.h"
12 #include "llvm/AsmParser/Parser.h"
13 #include "llvm/IR/Instructions.h"
14 #include "llvm/IR/LLVMContext.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/Support/SourceMgr.h"
17 #include "gtest/gtest.h"
21 // Tests that we can retrieve the CostFeatures without an error
22 TEST(InlineCostTest
, CostFeatures
) {
25 const auto *const IR
= R
"IR(
31 %2 = call i32 @f(i32 0)
38 std::unique_ptr
<Module
> M
= parseAssemblyString(IR
, Err
, C
);
41 auto *G
= M
->getFunction("g");
44 // find the call to f in g
45 CallBase
*CB
= nullptr;
48 if ((CB
= dyn_cast
<CallBase
>(&I
)))
54 ModuleAnalysisManager MAM
;
55 FunctionAnalysisManager FAM
;
56 FAM
.registerPass([&] { return TargetIRAnalysis(); });
57 FAM
.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM
); });
58 FAM
.registerPass([&] { return AssumptionAnalysis(); });
59 MAM
.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM
); });
61 MAM
.registerPass([&] { return PassInstrumentationAnalysis(); });
62 FAM
.registerPass([&] { return PassInstrumentationAnalysis(); });
64 ModulePassManager MPM
;
67 auto GetAssumptionCache
= [&](Function
&F
) -> AssumptionCache
& {
68 return FAM
.getResult
<AssumptionAnalysis
>(F
);
70 auto &TIR
= FAM
.getResult
<TargetIRAnalysis
>(*G
);
73 llvm::getInliningCostFeatures(*CB
, TIR
, GetAssumptionCache
);
75 // Check that the optional is not empty
76 ASSERT_TRUE(Features
);