1 //===- llvm/unittest/Transforms/Vectorize/VPlanTestBase.h -----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// \file 10 /// This file defines a VPlanTestBase class, which provides helpers to parse 11 /// a LLVM IR string and create VPlans given a loop entry block. 12 //===----------------------------------------------------------------------===// 13 #ifndef LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H 14 #define LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H 15 16 #include "../lib/Transforms/Vectorize/VPlan.h" 17 #include "../lib/Transforms/Vectorize/VPlanHCFGBuilder.h" 18 #include "llvm/Analysis/LoopInfo.h" 19 #include "llvm/AsmParser/Parser.h" 20 #include "llvm/IR/Dominators.h" 21 #include "llvm/Support/SourceMgr.h" 22 #include "gtest/gtest.h" 23 24 namespace llvm { 25 26 /// Helper class to create a module from an assembly string and VPlans for a 27 /// given loop entry block. 28 class VPlanTestBase : public testing::Test { 29 protected: 30 std::unique_ptr<LLVMContext> Ctx; 31 std::unique_ptr<Module> M; 32 std::unique_ptr<LoopInfo> LI; 33 std::unique_ptr<DominatorTree> DT; 34 35 VPlanTestBase() : Ctx(new LLVMContext) {} 36 37 Module &parseModule(const char *ModuleString) { 38 SMDiagnostic Err; 39 M = parseAssemblyString(ModuleString, Err, *Ctx); 40 EXPECT_TRUE(M); 41 return *M; 42 } 43 44 void doAnalysis(Function &F) { 45 DT.reset(new DominatorTree(F)); 46 LI.reset(new LoopInfo(*DT)); 47 } 48 49 VPlanPtr buildHCFG(BasicBlock *LoopHeader) { 50 doAnalysis(*LoopHeader->getParent()); 51 52 auto Plan = llvm::make_unique<VPlan>(); 53 VPlanHCFGBuilder HCFGBuilder(LI->getLoopFor(LoopHeader), LI.get()); 54 HCFGBuilder.buildHierarchicalCFG(*Plan.get()); 55 return Plan; 56 } 57 }; 58 59 } // namespace llvm 60 61 #endif // LLVM_UNITTESTS_TRANSFORMS_VECTORIZE_VPLANTESTBASE_H 62