xref: /llvm-project/llvm/unittests/Analysis/GlobalsModRefTest.cpp (revision 747f27d97d230b0b3e318dd9d3815d27d1bb0652)
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 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/Analysis/GlobalsModRef.h"
10 #include "llvm/ADT/Triple.h"
11 #include "llvm/Analysis/CallGraph.h"
12 #include "llvm/Analysis/TargetLibraryInfo.h"
13 #include "llvm/AsmParser/Parser.h"
14 #include "llvm/Support/SourceMgr.h"
15 #include "gtest/gtest.h"
16 
17 using namespace llvm;
18 
19 TEST(GlobalsModRef, OptNone) {
20   StringRef Assembly = R"(
21     define void @f1() optnone {
22       ret void
23     }
24     define void @f2() optnone readnone {
25       ret void
26     }
27     define void @f3() optnone readonly {
28       ret void
29     }
30   )";
31 
32   LLVMContext Context;
33   SMDiagnostic Error;
34   auto M = parseAssemblyString(Assembly, Error, Context);
35   ASSERT_TRUE(M) << "Bad assembly?";
36 
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());
46 
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);
52 
53   auto AAR = GlobalsAAResult::analyzeModule(*M, GetTLI, CG);
54 
55   EXPECT_EQ(MemoryEffects::unknown(), AAR.getMemoryEffects(&F1));
56   EXPECT_EQ(MemoryEffects::none(), AAR.getMemoryEffects(&F2));
57   EXPECT_EQ(MemoryEffects::readOnly(), AAR.getMemoryEffects(&F3));
58 }
59