blob: 323edc2cc1759e4054222562028fdd281f4c0291 [file] [log] [blame]
Andrew Top61a84952019-04-30 15:07:33 -07001//===--- GlobalsModRefTest.cpp - Mixed TBAA unit tests --------------------===//
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
10#include "llvm/Analysis/GlobalsModRef.h"
11#include "llvm/AsmParser/Parser.h"
12#include "llvm/Support/SourceMgr.h"
13#include "gtest/gtest.h"
14
15using namespace llvm;
16
17TEST(GlobalsModRef, OptNone) {
18 StringRef Assembly = R"(
19 define void @f1() optnone {
20 ret void
21 }
22 define void @f2() optnone readnone {
23 ret void
24 }
25 define void @f3() optnone readonly {
26 ret void
27 }
28 )";
29
30 LLVMContext Context;
31 SMDiagnostic Error;
32 auto M = parseAssemblyString(Assembly, Error, Context);
33 ASSERT_TRUE(M) << "Bad assembly?";
34
35 const auto &funcs = M->functions();
36 auto I = funcs.begin();
37 ASSERT_NE(I, funcs.end());
38 const Function &F1 = *I;
39 ASSERT_NE(++I, funcs.end());
40 const Function &F2 = *I;
41 ASSERT_NE(++I, funcs.end());
42 const Function &F3 = *I;
43 EXPECT_EQ(++I, funcs.end());
44
45 Triple Trip(M->getTargetTriple());
46 TargetLibraryInfoImpl TLII(Trip);
47 TargetLibraryInfo TLI(TLII);
48 llvm::CallGraph CG(*M);
49
50 auto AAR = GlobalsAAResult::analyzeModule(*M, TLI, CG);
51
52 EXPECT_EQ(FMRB_UnknownModRefBehavior, AAR.getModRefBehavior(&F1));
53 EXPECT_EQ(FMRB_DoesNotAccessMemory, AAR.getModRefBehavior(&F2));
54 EXPECT_EQ(FMRB_OnlyReadsMemory, AAR.getModRefBehavior(&F3));
55}