Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / unittests / Analysis / GlobalsModRefTest.cpp
blob096df299461af74aadb4594e9e4a8dd4ee11ada2
1 //===--- GlobalsModRefTest.cpp - Mixed TBAA unit tests --------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/GlobalsModRef.h"
10 #include "llvm/Analysis/CallGraph.h"
11 #include "llvm/Analysis/TargetLibraryInfo.h"
12 #include "llvm/AsmParser/Parser.h"
13 #include "llvm/Support/SourceMgr.h"
14 #include "llvm/TargetParser/Triple.h"
15 #include "gtest/gtest.h"
17 using namespace llvm;
19 TEST(GlobalsModRef, OptNone) {
20 StringRef Assembly = R"(
21 define void @f1() optnone {
22 ret void
24 define void @f2() optnone readnone {
25 ret void
27 define void @f3() optnone readonly {
28 ret void
30 )";
32 LLVMContext Context;
33 SMDiagnostic Error;
34 auto M = parseAssemblyString(Assembly, Error, Context);
35 ASSERT_TRUE(M) << "Bad assembly?";
37 const auto &funcs = M->functions();
38 auto I = funcs.begin();
39 ASSERT_NE(I, funcs.end());
40 const Function &F1 = *I;
41 ASSERT_NE(++I, funcs.end());
42 const Function &F2 = *I;
43 ASSERT_NE(++I, funcs.end());
44 const Function &F3 = *I;
45 EXPECT_EQ(++I, funcs.end());
47 Triple Trip(M->getTargetTriple());
48 TargetLibraryInfoImpl TLII(Trip);
49 TargetLibraryInfo TLI(TLII);
50 auto GetTLI = [&TLI](Function &F) -> TargetLibraryInfo & { return TLI; };
51 llvm::CallGraph CG(*M);
53 auto AAR = GlobalsAAResult::analyzeModule(*M, GetTLI, CG);
55 EXPECT_EQ(MemoryEffects::unknown(), AAR.getMemoryEffects(&F1));
56 EXPECT_EQ(MemoryEffects::none(), AAR.getMemoryEffects(&F2));
57 EXPECT_EQ(MemoryEffects::readOnly(), AAR.getMemoryEffects(&F3));