From 5d5cc59cc77afe655b3707cb0e69e0827b444cad Mon Sep 17 00:00:00 2001 From: dim Date: Fri, 17 Sep 2010 15:48:55 +0000 Subject: Vendor import of llvm r114020 (from the release_28 branch): http://llvm.org/svn/llvm-project/llvm/branches/release_28@114020 Approved by: rpaulo (mentor) --- unittests/Analysis/ScalarEvolutionTest.cpp | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 unittests/Analysis/ScalarEvolutionTest.cpp (limited to 'unittests/Analysis/ScalarEvolutionTest.cpp') diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp new file mode 100644 index 0000000..b734160 --- /dev/null +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -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 +#include +#include +#include +#include +#include +#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(), false); + Function *F = cast(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(P0); + const SCEVMulExpr *M1 = cast(P1); + const SCEVMulExpr *M2 = cast(P2); + + EXPECT_EQ(cast(M0->getOperand(0))->getValue()->getZExtValue(), + 2u); + EXPECT_EQ(cast(M1->getOperand(0))->getValue()->getZExtValue(), + 2u); + EXPECT_EQ(cast(M2->getOperand(0))->getValue()->getZExtValue(), + 2u); + + // Before the RAUWs, these are all pointing to separate values. + EXPECT_EQ(cast(M0->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast(M1->getOperand(1))->getValue(), V1); + EXPECT_EQ(cast(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(M0->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast(M1->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast(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 -- cgit v1.1