diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-09-27 21:39:46 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-09-27 21:39:46 +0000 |
commit | 4dd68242f106f047f80a5e0fdd96e19cb0ac5eed (patch) | |
tree | 5bdbe64ddf596882b9b9b16b9c0252e70241aa6b /unittests/Transforms/Utils | |
parent | 06e4052699c481fda1df8d96a26e42733c36eb66 (diff) |
New unit test for the cloning module, which so far only covers cloning of
instructions' optimization flags.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82934 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Transforms/Utils')
-rw-r--r-- | unittests/Transforms/Utils/Cloning.cpp | 87 | ||||
-rw-r--r-- | unittests/Transforms/Utils/Makefile | 15 |
2 files changed, 102 insertions, 0 deletions
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp new file mode 100644 index 0000000000..7c93f6f583 --- /dev/null +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -0,0 +1,87 @@ +//===- Cloning.cpp - Unit tests for the Cloner ----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "llvm/Argument.h" +#include "llvm/Instructions.h" + +using namespace llvm; + +TEST(CloneInstruction, OverflowBits) { + LLVMContext context; + Value *V = new Argument(Type::getInt32Ty(context)); + + BinaryOperator *Add = BinaryOperator::Create(Instruction::Add, V, V); + BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V); + BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V); + + EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap()); + EXPECT_FALSE(Add->clone()->hasNoSignedWrap()); + EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap()); + EXPECT_FALSE(Sub->clone()->hasNoSignedWrap()); + EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap()); + EXPECT_FALSE(Mul->clone()->hasNoSignedWrap()); + + Add->setHasNoUnsignedWrap(); + Sub->setHasNoUnsignedWrap(); + Mul->setHasNoUnsignedWrap(); + + EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap()); + EXPECT_FALSE(Add->clone()->hasNoSignedWrap()); + EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap()); + EXPECT_FALSE(Sub->clone()->hasNoSignedWrap()); + EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap()); + EXPECT_FALSE(Mul->clone()->hasNoSignedWrap()); + + Add->setHasNoSignedWrap(); + Sub->setHasNoSignedWrap(); + Mul->setHasNoSignedWrap(); + + EXPECT_TRUE(Add->clone()->hasNoUnsignedWrap()); + EXPECT_TRUE(Add->clone()->hasNoSignedWrap()); + EXPECT_TRUE(Sub->clone()->hasNoUnsignedWrap()); + EXPECT_TRUE(Sub->clone()->hasNoSignedWrap()); + EXPECT_TRUE(Mul->clone()->hasNoUnsignedWrap()); + EXPECT_TRUE(Mul->clone()->hasNoSignedWrap()); + + Add->setHasNoUnsignedWrap(false); + Sub->setHasNoUnsignedWrap(false); + Mul->setHasNoUnsignedWrap(false); + + EXPECT_FALSE(Add->clone()->hasNoUnsignedWrap()); + EXPECT_TRUE(Add->clone()->hasNoSignedWrap()); + EXPECT_FALSE(Sub->clone()->hasNoUnsignedWrap()); + EXPECT_TRUE(Sub->clone()->hasNoSignedWrap()); + EXPECT_FALSE(Mul->clone()->hasNoUnsignedWrap()); + EXPECT_TRUE(Mul->clone()->hasNoSignedWrap()); +} + +TEST(CloneInstruction, Inbounds) { + LLVMContext context; + Value *V = new Argument(Type::getInt32Ty(context)->getPointerTo()); + Constant *Z = Constant::getNullValue(Type::getInt32Ty(context)); + std::vector<Value *> ops; + ops.push_back(Z); + GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end()); + EXPECT_FALSE(GEP->clone()->isInBounds()); + + GEP->setIsInBounds(); + EXPECT_TRUE(GEP->clone()->isInBounds()); +} + +TEST(CloneInstruction, Exact) { + LLVMContext context; + Value *V = new Argument(Type::getInt32Ty(context)); + + BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V); + EXPECT_FALSE(SDiv->clone()->isExact()); + + SDiv->setIsExact(true); + EXPECT_TRUE(SDiv->clone()->isExact()); +} diff --git a/unittests/Transforms/Utils/Makefile b/unittests/Transforms/Utils/Makefile new file mode 100644 index 0000000000..fdf4be0e0e --- /dev/null +++ b/unittests/Transforms/Utils/Makefile @@ -0,0 +1,15 @@ +##===- unittests/Transforms/Utils/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 = Utils +LINK_COMPONENTS := core support transformutils + +include $(LEVEL)/Makefile.config +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest |