aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/Analysis
diff options
context:
space:
mode:
authorPirama Arumuga Nainar <pirama@google.com>2015-05-06 11:46:36 -0700
committerPirama Arumuga Nainar <pirama@google.com>2015-05-18 10:52:30 -0700
commit2c3e0051c31c3f5b2328b447eadf1cf9c4427442 (patch)
treec0104029af14e9f47c2ef58ca60e6137691f3c9b /unittests/Analysis
parente1bc145815f4334641be19f1c45ecf85d25b6e5a (diff)
downloadexternal_llvm-2c3e0051c31c3f5b2328b447eadf1cf9c4427442.zip
external_llvm-2c3e0051c31c3f5b2328b447eadf1cf9c4427442.tar.gz
external_llvm-2c3e0051c31c3f5b2328b447eadf1cf9c4427442.tar.bz2
Update aosp/master LLVM for rebase to r235153
Change-Id: I9bf53792f9fc30570e81a8d80d296c681d005ea7 (cherry picked from commit 0c7f116bb6950ef819323d855415b2f2b0aad987)
Diffstat (limited to 'unittests/Analysis')
-rw-r--r--unittests/Analysis/AliasAnalysisTest.cpp94
-rw-r--r--unittests/Analysis/CFGTest.cpp4
-rw-r--r--unittests/Analysis/CMakeLists.txt1
-rw-r--r--unittests/Analysis/ScalarEvolutionTest.cpp2
4 files changed, 98 insertions, 3 deletions
diff --git a/unittests/Analysis/AliasAnalysisTest.cpp b/unittests/Analysis/AliasAnalysisTest.cpp
new file mode 100644
index 0000000..1ba396c
--- /dev/null
+++ b/unittests/Analysis/AliasAnalysisTest.cpp
@@ -0,0 +1,94 @@
+//===--- AliasAnalysisTest.cpp - Mixed TBAA unit tests --------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/AliasAnalysis.h"
+#include "llvm/Analysis/Passes.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/Support/CommandLine.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+class AliasAnalysisTest : public testing::Test {
+protected:
+ AliasAnalysisTest() : M("AliasAnalysisTBAATest", C) {}
+
+ // This is going to check that calling getModRefInfo without a location, and
+ // with a default location, first, doesn't crash, and second, gives the right
+ // answer.
+ void CheckModRef(Instruction *I, AliasAnalysis::ModRefResult Result) {
+ static char ID;
+ class CheckModRefTestPass : public FunctionPass {
+ public:
+ CheckModRefTestPass(Instruction *I, AliasAnalysis::ModRefResult Result)
+ : FunctionPass(ID), ExpectResult(Result), I(I) {}
+ static int initialize() {
+ PassInfo *PI = new PassInfo("CheckModRef testing pass", "", &ID,
+ nullptr, true, true);
+ PassRegistry::getPassRegistry()->registerPass(*PI, false);
+ initializeAliasAnalysisAnalysisGroup(*PassRegistry::getPassRegistry());
+ initializeBasicAliasAnalysisPass(*PassRegistry::getPassRegistry());
+ return 0;
+ }
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ AU.addRequiredTransitive<AliasAnalysis>();
+ }
+ bool runOnFunction(Function &) override {
+ AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
+ EXPECT_EQ(AA.getModRefInfo(I, AliasAnalysis::Location()), ExpectResult);
+ EXPECT_EQ(AA.getModRefInfo(I), ExpectResult);
+ return false;
+ }
+ AliasAnalysis::ModRefResult ExpectResult;
+ Instruction *I;
+ };
+ static int initialize = CheckModRefTestPass::initialize();
+ (void)initialize;
+ CheckModRefTestPass *P = new CheckModRefTestPass(I, Result);
+ legacy::PassManager PM;
+ PM.add(createBasicAliasAnalysisPass());
+ PM.add(P);
+ PM.run(M);
+ }
+
+ LLVMContext C;
+ Module M;
+};
+
+TEST_F(AliasAnalysisTest, getModRefInfo) {
+ // Setup function.
+ FunctionType *FTy =
+ FunctionType::get(Type::getVoidTy(C), std::vector<Type *>(), false);
+ auto *F = cast<Function>(M.getOrInsertFunction("f", FTy));
+ auto *BB = BasicBlock::Create(C, "entry", F);
+ auto IntType = Type::getInt32Ty(C);
+ auto PtrType = Type::getInt32PtrTy(C);
+ auto *Value = ConstantInt::get(IntType, 42);
+ auto *Addr = ConstantPointerNull::get(PtrType);
+
+ auto *Store1 = new StoreInst(Value, Addr, BB);
+ auto *Load1 = new LoadInst(Addr, "load", BB);
+ auto *Add1 = BinaryOperator::CreateAdd(Value, Value, "add", BB);
+
+ ReturnInst::Create(C, nullptr, BB);
+
+ // Check basic results
+ CheckModRef(Store1, AliasAnalysis::ModRefResult::Mod);
+ CheckModRef(Load1, AliasAnalysis::ModRefResult::Ref);
+ CheckModRef(Add1, AliasAnalysis::ModRefResult::NoModRef);
+}
+
+} // end anonymous namspace
+} // end llvm namespace
diff --git a/unittests/Analysis/CFGTest.cpp b/unittests/Analysis/CFGTest.cpp
index 4b4ebb6..b29c168 100644
--- a/unittests/Analysis/CFGTest.cpp
+++ b/unittests/Analysis/CFGTest.cpp
@@ -78,13 +78,13 @@ protected:
return 0;
}
- void getAnalysisUsage(AnalysisUsage &AU) const {
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<DominatorTreeWrapperPass>();
}
- bool runOnFunction(Function &F) {
+ bool runOnFunction(Function &F) override {
if (!F.hasName() || F.getName() != "test")
return false;
diff --git a/unittests/Analysis/CMakeLists.txt b/unittests/Analysis/CMakeLists.txt
index baf0c28..35a6d92 100644
--- a/unittests/Analysis/CMakeLists.txt
+++ b/unittests/Analysis/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_unittest(AnalysisTests
+ AliasAnalysisTest.cpp
CallGraphTest.cpp
CFGTest.cpp
LazyCallGraphTest.cpp
diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp
index 876a264..6ce7ff4 100644
--- a/unittests/Analysis/ScalarEvolutionTest.cpp
+++ b/unittests/Analysis/ScalarEvolutionTest.cpp
@@ -25,7 +25,7 @@ namespace {
class ScalarEvolutionsTest : public testing::Test {
protected:
ScalarEvolutionsTest() : M("", Context), SE(*new ScalarEvolution) {}
- ~ScalarEvolutionsTest() {
+ ~ScalarEvolutionsTest() override {
// Manually clean up, since we allocated new SCEV objects after the
// pass was finished.
SE.releaseMemory();