[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / unittests / Transforms / Vectorize / VPlanTestBase.h
blobd0bf3cf1a65fbdcd09fbfd5eec1f1efc2952866b
1 //===- llvm/unittest/Transforms/Vectorize/VPlanTestBase.h -----------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file defines a VPlanTestBase class, which provides helpers to parse
10 /// a LLVM IR string and create VPlans given a loop entry block.
11 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H
13 #define LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H
15 #include "../lib/Transforms/Vectorize/VPlan.h"
16 #include "../lib/Transforms/Vectorize/VPlanHCFGBuilder.h"
17 #include "llvm/Analysis/LoopInfo.h"
18 #include "llvm/AsmParser/Parser.h"
19 #include "llvm/IR/Dominators.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include "gtest/gtest.h"
23 namespace llvm {
25 /// Helper class to create a module from an assembly string and VPlans for a
26 /// given loop entry block.
27 class VPlanTestBase : public testing::Test {
28 protected:
29 std::unique_ptr<LLVMContext> Ctx;
30 std::unique_ptr<Module> M;
31 std::unique_ptr<LoopInfo> LI;
32 std::unique_ptr<DominatorTree> DT;
34 VPlanTestBase() : Ctx(new LLVMContext) {}
36 Module &parseModule(const char *ModuleString) {
37 SMDiagnostic Err;
38 M = parseAssemblyString(ModuleString, Err, *Ctx);
39 EXPECT_TRUE(M);
40 return *M;
43 void doAnalysis(Function &F) {
44 DT.reset(new DominatorTree(F));
45 LI.reset(new LoopInfo(*DT));
48 VPlanPtr buildHCFG(BasicBlock *LoopHeader) {
49 doAnalysis(*LoopHeader->getParent());
51 auto Plan = std::make_unique<VPlan>();
52 VPlanHCFGBuilder HCFGBuilder(LI->getLoopFor(LoopHeader), LI.get(), *Plan);
53 HCFGBuilder.buildHierarchicalCFG();
54 return Plan;
57 /// Build the VPlan plain CFG for the loop starting from \p LoopHeader.
58 VPlanPtr buildPlainCFG(BasicBlock *LoopHeader) {
59 doAnalysis(*LoopHeader->getParent());
61 auto Plan = std::make_unique<VPlan>();
62 VPlanHCFGBuilder HCFGBuilder(LI->getLoopFor(LoopHeader), LI.get(), *Plan);
63 VPRegionBlock *TopRegion = HCFGBuilder.buildPlainCFG();
64 Plan->setEntry(TopRegion);
65 return Plan;
69 } // namespace llvm
71 #endif // LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H