[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / llvm / unittests / Transforms / Vectorize / VPlanTestBase.h
blob06e091da9054e31e625e4a92aeee602d16362c5e
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/AssumptionCache.h"
18 #include "llvm/Analysis/BasicAliasAnalysis.h"
19 #include "llvm/Analysis/LoopInfo.h"
20 #include "llvm/Analysis/TargetLibraryInfo.h"
21 #include "llvm/AsmParser/Parser.h"
22 #include "llvm/IR/Dominators.h"
23 #include "llvm/IR/Verifier.h"
24 #include "llvm/Support/SourceMgr.h"
25 #include "gtest/gtest.h"
27 namespace llvm {
29 /// Helper class to create a module from an assembly string and VPlans for a
30 /// given loop entry block.
31 class VPlanTestBase : public testing::Test {
32 protected:
33 TargetLibraryInfoImpl TLII;
34 TargetLibraryInfo TLI;
35 DataLayout DL;
37 std::unique_ptr<LLVMContext> Ctx;
38 std::unique_ptr<Module> M;
39 std::unique_ptr<LoopInfo> LI;
40 std::unique_ptr<DominatorTree> DT;
41 std::unique_ptr<AssumptionCache> AC;
42 std::unique_ptr<ScalarEvolution> SE;
44 VPlanTestBase()
45 : TLII(), TLI(TLII),
46 DL("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-"
47 "f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:"
48 "16:32:64-S128"),
49 Ctx(new LLVMContext) {}
51 Module &parseModule(const char *ModuleString) {
52 SMDiagnostic Err;
53 M = parseAssemblyString(ModuleString, Err, *Ctx);
54 EXPECT_TRUE(M);
55 return *M;
58 void doAnalysis(Function &F) {
59 DT.reset(new DominatorTree(F));
60 LI.reset(new LoopInfo(*DT));
61 AC.reset(new AssumptionCache(F));
62 SE.reset(new ScalarEvolution(F, TLI, *AC, *DT, *LI));
65 VPlanPtr buildHCFG(BasicBlock *LoopHeader) {
66 Function &F = *LoopHeader->getParent();
67 assert(!verifyFunction(F) && "input function must be valid");
68 doAnalysis(F);
70 Loop *L = LI->getLoopFor(LoopHeader);
71 PredicatedScalarEvolution PSE(*SE, *L);
72 auto Plan = VPlan::createInitialVPlan(IntegerType::get(*Ctx, 64), PSE, true,
73 false, L);
74 VPlanHCFGBuilder HCFGBuilder(L, LI.get(), *Plan);
75 HCFGBuilder.buildHierarchicalCFG();
76 return Plan;
79 /// Build the VPlan plain CFG for the loop starting from \p LoopHeader.
80 VPlanPtr buildPlainCFG(BasicBlock *LoopHeader) {
81 Function &F = *LoopHeader->getParent();
82 assert(!verifyFunction(F) && "input function must be valid");
83 doAnalysis(F);
85 Loop *L = LI->getLoopFor(LoopHeader);
86 PredicatedScalarEvolution PSE(*SE, *L);
87 auto Plan = VPlan::createInitialVPlan(IntegerType::get(*Ctx, 64), PSE, true,
88 false, L);
89 VPlanHCFGBuilder HCFGBuilder(L, LI.get(), *Plan);
90 HCFGBuilder.buildPlainCFG();
91 return Plan;
95 } // namespace llvm
97 #endif // LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H