1 //===- SandboxVectorizerTest.cpp ------------------------------------------===// 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 9 #include "llvm/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.h" 10 #include "llvm/Analysis/AssumptionCache.h" 11 #include "llvm/Analysis/BasicAliasAnalysis.h" 12 #include "llvm/Analysis/LoopInfo.h" 13 #include "llvm/Analysis/ScalarEvolution.h" 14 #include "llvm/Analysis/TargetLibraryInfo.h" 15 #include "llvm/Analysis/TargetTransformInfo.h" 16 #include "llvm/AsmParser/Parser.h" 17 #include "llvm/IR/DataLayout.h" 18 #include "llvm/IR/Dominators.h" 19 #include "llvm/IR/PassInstrumentation.h" 20 #include "llvm/SandboxIR/Function.h" 21 #include "llvm/SandboxIR/Instruction.h" 22 #include "llvm/Support/SourceMgr.h" 23 #include "gmock/gmock.h" 24 #include "gtest/gtest.h" 25 26 using namespace llvm; 27 28 struct SandboxVectorizerTest : public testing::Test { 29 LLVMContext C; 30 std::unique_ptr<Module> M; 31 32 void parseIR(LLVMContext &C, const char *IR) { 33 SMDiagnostic Err; 34 M = parseAssemblyString(IR, Err, C); 35 if (!M) 36 Err.print("SandboxVectorizerTest", errs()); 37 } 38 }; 39 40 // Check that we can run the pass on the same function more than once without 41 // issues. This basically checks that Sandbox IR Context gets cleared after we 42 // run the function pass. 43 TEST_F(SandboxVectorizerTest, ContextCleared) { 44 parseIR(C, R"IR( 45 define void @foo() { 46 ret void 47 } 48 )IR"); 49 auto &LLVMF = *M->getFunction("foo"); 50 SandboxVectorizerPass SVecPass; 51 FunctionAnalysisManager AM; 52 AM.registerPass([] { return TargetIRAnalysis(); }); 53 AM.registerPass([] { return AAManager(); }); 54 AM.registerPass([] { return ScalarEvolutionAnalysis(); }); 55 AM.registerPass([] { return PassInstrumentationAnalysis(); }); 56 AM.registerPass([] { return TargetLibraryAnalysis(); }); 57 AM.registerPass([] { return AssumptionAnalysis(); }); 58 AM.registerPass([] { return DominatorTreeAnalysis(); }); 59 AM.registerPass([] { return LoopAnalysis(); }); 60 SVecPass.run(LLVMF, AM); 61 // This shouldn't crash. 62 SVecPass.run(LLVMF, AM); 63 } 64