[llvm-branch-commits] [llvm-branch] r130768 - in /llvm/branches/Apple/Morbo/unittests: Analysis/ Analysis/Makefile Analysis/ScalarEvolutionTest.cpp Makefile
Dan Gohman
gohman at apple.com
Tue May 3 10:43:06 PDT 2011
Author: djg
Date: Tue May 3 12:43:06 2011
New Revision: 130768
URL: http://llvm.org/viewvc/llvm-project?rev=130768&view=rev
Log:
Commit the unittest which I accidentally partially
omitted in r130208.
Added:
llvm/branches/Apple/Morbo/unittests/Analysis/
llvm/branches/Apple/Morbo/unittests/Analysis/Makefile
llvm/branches/Apple/Morbo/unittests/Analysis/ScalarEvolutionTest.cpp
Modified:
llvm/branches/Apple/Morbo/unittests/Makefile
Added: llvm/branches/Apple/Morbo/unittests/Analysis/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/unittests/Analysis/Makefile?rev=130768&view=auto
==============================================================================
--- llvm/branches/Apple/Morbo/unittests/Analysis/Makefile (added)
+++ llvm/branches/Apple/Morbo/unittests/Analysis/Makefile Tue May 3 12:43:06 2011
@@ -0,0 +1,15 @@
+##===- unittests/Analysis/Makefile -------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+TESTNAME = Analysis
+LINK_COMPONENTS := core support target analysis ipa
+
+include $(LEVEL)/Makefile.config
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
Added: llvm/branches/Apple/Morbo/unittests/Analysis/ScalarEvolutionTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/unittests/Analysis/ScalarEvolutionTest.cpp?rev=130768&view=auto
==============================================================================
--- llvm/branches/Apple/Morbo/unittests/Analysis/ScalarEvolutionTest.cpp (added)
+++ llvm/branches/Apple/Morbo/unittests/Analysis/ScalarEvolutionTest.cpp Tue May 3 12:43:06 2011
@@ -0,0 +1,82 @@
+//===- ScalarEvolutionsTest.cpp - ScalarEvolution 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/ScalarEvolutionExpressions.h>
+#include <llvm/GlobalVariable.h>
+#include <llvm/Constants.h>
+#include <llvm/LLVMContext.h>
+#include <llvm/Module.h>
+#include <llvm/PassManager.h>
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+TEST(ScalarEvolutionsTest, SCEVUnknownRAUW) {
+ LLVMContext Context;
+ Module M("world", Context);
+
+ const FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context),
+ std::vector<const Type *>(), false);
+ Function *F = cast<Function>(M.getOrInsertFunction("f", FTy));
+ BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
+ ReturnInst::Create(Context, 0, BB);
+
+ const Type *Ty = Type::getInt1Ty(Context);
+ Constant *Init = Constant::getNullValue(Ty);
+ Value *V0 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V0");
+ Value *V1 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V1");
+ Value *V2 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V2");
+
+ // Create a ScalarEvolution and "run" it so that it gets initialized.
+ PassManager PM;
+ ScalarEvolution &SE = *new ScalarEvolution();
+ PM.add(&SE);
+ PM.run(M);
+
+ const SCEV *S0 = SE.getSCEV(V0);
+ const SCEV *S1 = SE.getSCEV(V1);
+ const SCEV *S2 = SE.getSCEV(V2);
+
+ const SCEV *P0 = SE.getAddExpr(S0, S0);
+ const SCEV *P1 = SE.getAddExpr(S1, S1);
+ const SCEV *P2 = SE.getAddExpr(S2, S2);
+
+ const SCEVMulExpr *M0 = cast<SCEVMulExpr>(P0);
+ const SCEVMulExpr *M1 = cast<SCEVMulExpr>(P1);
+ const SCEVMulExpr *M2 = cast<SCEVMulExpr>(P2);
+
+ EXPECT_EQ(cast<SCEVConstant>(M0->getOperand(0))->getValue()->getZExtValue(),
+ 2u);
+ EXPECT_EQ(cast<SCEVConstant>(M1->getOperand(0))->getValue()->getZExtValue(),
+ 2u);
+ EXPECT_EQ(cast<SCEVConstant>(M2->getOperand(0))->getValue()->getZExtValue(),
+ 2u);
+
+ // Before the RAUWs, these are all pointing to separate values.
+ EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0);
+ EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V1);
+ EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V2);
+
+ // Do some RAUWs.
+ V2->replaceAllUsesWith(V1);
+ V1->replaceAllUsesWith(V0);
+
+ // After the RAUWs, these should all be pointing to V0.
+ EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0);
+ EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V0);
+ EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V0);
+
+ // Manually clean up, since we allocated new SCEV objects after the
+ // pass was finished.
+ SE.releaseMemory();
+}
+
+} // end anonymous namespace
+} // end namespace llvm
Modified: llvm/branches/Apple/Morbo/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/unittests/Makefile?rev=130768&r1=130767&r2=130768&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/unittests/Makefile (original)
+++ llvm/branches/Apple/Morbo/unittests/Makefile Tue May 3 12:43:06 2011
@@ -9,7 +9,7 @@
LEVEL = ..
-PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore
+PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore Analysis
include $(LEVEL)/Makefile.common
More information about the llvm-branch-commits
mailing list