GlobalsModRefTest.cpp 1.6 KB

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