[llvm-commits] [llvm] r82934 - in /llvm/trunk/unittests: Makefile Transforms/ Transforms/Makefile Transforms/Utils/ Transforms/Utils/Cloning.cpp Transforms/Utils/Makefile

Nick Lewycky nicholas at mxc.ca
Sun Sep 27 14:39:46 PDT 2009


Author: nicholas
Date: Sun Sep 27 16:39:46 2009
New Revision: 82934

URL: http://llvm.org/viewvc/llvm-project?rev=82934&view=rev
Log:
New unit test for the cloning module, which so far only covers cloning of
instructions' optimization flags.

Added:
    llvm/trunk/unittests/Transforms/   (with props)
    llvm/trunk/unittests/Transforms/Makefile
    llvm/trunk/unittests/Transforms/Utils/   (with props)
    llvm/trunk/unittests/Transforms/Utils/Cloning.cpp
    llvm/trunk/unittests/Transforms/Utils/Makefile
Modified:
    llvm/trunk/unittests/Makefile

Modified: llvm/trunk/unittests/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Makefile?rev=82934&r1=82933&r2=82934&view=diff

==============================================================================
--- llvm/trunk/unittests/Makefile (original)
+++ llvm/trunk/unittests/Makefile Sun Sep 27 16:39:46 2009
@@ -9,7 +9,7 @@
 
 LEVEL = ..
 
-PARALLEL_DIRS = ADT ExecutionEngine Support VMCore
+PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore
 
 include $(LEVEL)/Makefile.common
 

Propchange: llvm/trunk/unittests/Transforms/

------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 27 16:39:46 2009
@@ -0,0 +1,5 @@
+Debug
+Debug+Checks
+Release
+Release-Asserts
+*Tests

Added: llvm/trunk/unittests/Transforms/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Makefile?rev=82934&view=auto

==============================================================================
--- llvm/trunk/unittests/Transforms/Makefile (added)
+++ llvm/trunk/unittests/Transforms/Makefile Sun Sep 27 16:39:46 2009
@@ -0,0 +1,17 @@
+##===- unittests/Transforms/Makefile -----------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+
+PARALLEL_DIRS = Utils
+
+include $(LEVEL)/Makefile.common
+
+clean::
+	$(Verb) $(RM) -f *Tests

Propchange: llvm/trunk/unittests/Transforms/Utils/

------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 27 16:39:46 2009
@@ -0,0 +1,5 @@
+Debug
+Debug+Checks
+Release
+Release-Asserts
+*Tests

Added: llvm/trunk/unittests/Transforms/Utils/Cloning.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Cloning.cpp?rev=82934&view=auto

==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Cloning.cpp (added)
+++ llvm/trunk/unittests/Transforms/Utils/Cloning.cpp Sun Sep 27 16:39:46 2009
@@ -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());
+}

Added: llvm/trunk/unittests/Transforms/Utils/Makefile
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Makefile?rev=82934&view=auto

==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Makefile (added)
+++ llvm/trunk/unittests/Transforms/Utils/Makefile Sun Sep 27 16:39:46 2009
@@ -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





More information about the llvm-commits mailing list