diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-01-07 15:35:46 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-01-07 15:35:46 +0000 |
commit | c779e96158cbac4c62df8e2053ab6a933eba5868 (patch) | |
tree | 0ec9e70170d75216c6f0ed5c994a0a0ba1fac2b3 /unittests/VMCore | |
parent | 3251e81d793a293b78f4914be6093b405c24fc2a (diff) |
Rename the VMCore unittest tree to IR. Somehow was missed when doing the
library rename.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171747 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/VMCore')
-rw-r--r-- | unittests/VMCore/CMakeLists.txt | 36 | ||||
-rw-r--r-- | unittests/VMCore/ConstantsTest.cpp | 228 | ||||
-rw-r--r-- | unittests/VMCore/DominatorTreeTest.cpp | 195 | ||||
-rw-r--r-- | unittests/VMCore/IRBuilderTest.cpp | 184 | ||||
-rw-r--r-- | unittests/VMCore/InstructionsTest.cpp | 284 | ||||
-rw-r--r-- | unittests/VMCore/MDBuilderTest.cpp | 106 | ||||
-rw-r--r-- | unittests/VMCore/Makefile | 15 | ||||
-rw-r--r-- | unittests/VMCore/MetadataTest.cpp | 152 | ||||
-rw-r--r-- | unittests/VMCore/PassManagerTest.cpp | 552 | ||||
-rw-r--r-- | unittests/VMCore/TypeBuilderTest.cpp | 253 | ||||
-rw-r--r-- | unittests/VMCore/TypesTest.cpp | 30 | ||||
-rw-r--r-- | unittests/VMCore/ValueMapTest.cpp | 294 | ||||
-rw-r--r-- | unittests/VMCore/VerifierTest.cpp | 64 | ||||
-rw-r--r-- | unittests/VMCore/WaymarkTest.cpp | 54 |
14 files changed, 0 insertions, 2447 deletions
diff --git a/unittests/VMCore/CMakeLists.txt b/unittests/VMCore/CMakeLists.txt deleted file mode 100644 index 8d8bb3bb4d..0000000000 --- a/unittests/VMCore/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -set(LLVM_LINK_COMPONENTS - asmparser - core - ipa - ) - -set(VMCoreSources - ConstantsTest.cpp - DominatorTreeTest.cpp - IRBuilderTest.cpp - InstructionsTest.cpp - MDBuilderTest.cpp - MetadataTest.cpp - PassManagerTest.cpp - TypeBuilderTest.cpp - TypesTest.cpp - ValueMapTest.cpp - VerifierTest.cpp - WaymarkTest.cpp - ) - -# MSVC9 and 8 cannot compile ValueMapTest.cpp due to their bug. -# See issue#331418 in Visual Studio. -if(MSVC AND MSVC_VERSION LESS 1600) - list(REMOVE_ITEM VMCoreSources ValueMapTest.cpp) -endif() - -# HACK: Declare a couple of source files as optionally compiled to satisfy the -# missing-file-checker in LLVM's weird CMake build. -set(LLVM_OPTIONAL_SOURCES - ValueMapTest.cpp - ) - -add_llvm_unittest(VMCoreTests - ${VMCoreSources} - ) diff --git a/unittests/VMCore/ConstantsTest.cpp b/unittests/VMCore/ConstantsTest.cpp deleted file mode 100644 index 01ab5f2638..0000000000 --- a/unittests/VMCore/ConstantsTest.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===- llvm/unittest/VMCore/ConstantsTest.cpp - Constants 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/IR/Constants.h" -#include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/InstrTypes.h" -#include "llvm/IR/Instruction.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Module.h" -#include "gtest/gtest.h" - -namespace llvm { -namespace { - -TEST(ConstantsTest, Integer_i1) { - IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1); - Constant* One = ConstantInt::get(Int1, 1, true); - Constant* Zero = ConstantInt::get(Int1, 0); - Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true); - EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1)); - Constant* Undef = UndefValue::get(Int1); - - // Input: @b = constant i1 add(i1 1 , i1 1) - // Output: @b = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getAdd(One, One)); - - // @c = constant i1 add(i1 -1, i1 1) - // @c = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, One)); - - // @d = constant i1 add(i1 -1, i1 -1) - // @d = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getAdd(NegOne, NegOne)); - - // @e = constant i1 sub(i1 -1, i1 1) - // @e = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSub(NegOne, One)); - - // @f = constant i1 sub(i1 1 , i1 -1) - // @f = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSub(One, NegOne)); - - // @g = constant i1 sub(i1 1 , i1 1) - // @g = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSub(One, One)); - - // @h = constant i1 shl(i1 1 , i1 1) ; undefined - // @h = constant i1 undef - EXPECT_EQ(Undef, ConstantExpr::getShl(One, One)); - - // @i = constant i1 shl(i1 1 , i1 0) - // @i = constant i1 true - EXPECT_EQ(One, ConstantExpr::getShl(One, Zero)); - - // @j = constant i1 lshr(i1 1, i1 1) ; undefined - // @j = constant i1 undef - EXPECT_EQ(Undef, ConstantExpr::getLShr(One, One)); - - // @m = constant i1 ashr(i1 1, i1 1) ; undefined - // @m = constant i1 undef - EXPECT_EQ(Undef, ConstantExpr::getAShr(One, One)); - - // @n = constant i1 mul(i1 -1, i1 1) - // @n = constant i1 true - EXPECT_EQ(One, ConstantExpr::getMul(NegOne, One)); - - // @o = constant i1 sdiv(i1 -1, i1 1) ; overflow - // @o = constant i1 true - EXPECT_EQ(One, ConstantExpr::getSDiv(NegOne, One)); - - // @p = constant i1 sdiv(i1 1 , i1 -1); overflow - // @p = constant i1 true - EXPECT_EQ(One, ConstantExpr::getSDiv(One, NegOne)); - - // @q = constant i1 udiv(i1 -1, i1 1) - // @q = constant i1 true - EXPECT_EQ(One, ConstantExpr::getUDiv(NegOne, One)); - - // @r = constant i1 udiv(i1 1, i1 -1) - // @r = constant i1 true - EXPECT_EQ(One, ConstantExpr::getUDiv(One, NegOne)); - - // @s = constant i1 srem(i1 -1, i1 1) ; overflow - // @s = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSRem(NegOne, One)); - - // @t = constant i1 urem(i1 -1, i1 1) - // @t = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getURem(NegOne, One)); - - // @u = constant i1 srem(i1 1, i1 -1) ; overflow - // @u = constant i1 false - EXPECT_EQ(Zero, ConstantExpr::getSRem(One, NegOne)); -} - -TEST(ConstantsTest, IntSigns) { - IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext()); - EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue()); - EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue()); - EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue()); - EXPECT_EQ(-50, ConstantInt::get(Int8Ty, 206)->getSExtValue()); - EXPECT_EQ(-50, ConstantInt::getSigned(Int8Ty, -50)->getSExtValue()); - EXPECT_EQ(206U, ConstantInt::getSigned(Int8Ty, -50)->getZExtValue()); - - // Overflow is handled by truncation. - EXPECT_EQ(0x3b, ConstantInt::get(Int8Ty, 0x13b)->getSExtValue()); -} - -TEST(ConstantsTest, FP128Test) { - Type *FP128Ty = Type::getFP128Ty(getGlobalContext()); - - IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128); - Constant *Zero128 = Constant::getNullValue(Int128Ty); - Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty); - EXPECT_TRUE(isa<ConstantFP>(X)); -} - -#define CHECK(x, y) { \ - std::string __s; \ - raw_string_ostream __o(__s); \ - cast<ConstantExpr>(x)->getAsInstruction()->print(__o); \ - __o.flush(); \ - EXPECT_EQ(std::string(" <badref> = " y), __s); \ - } - -TEST(ConstantsTest, AsInstructionsTest) { - Module *M = new Module("MyModule", getGlobalContext()); - - Type *Int64Ty = Type::getInt64Ty(getGlobalContext()); - Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); - Type *Int16Ty = Type::getInt16Ty(getGlobalContext()); - Type *Int1Ty = Type::getInt1Ty(getGlobalContext()); - Type *FloatTy = Type::getFloatTy(getGlobalContext()); - Type *DoubleTy = Type::getDoubleTy(getGlobalContext()); - - Constant *Global = M->getOrInsertGlobal("dummy", - PointerType::getUnqual(Int32Ty)); - Constant *Global2 = M->getOrInsertGlobal("dummy2", - PointerType::getUnqual(Int32Ty)); - - Constant *P0 = ConstantExpr::getPtrToInt(Global, Int32Ty); - Constant *P1 = ConstantExpr::getUIToFP(P0, FloatTy); - Constant *P2 = ConstantExpr::getUIToFP(P0, DoubleTy); - Constant *P3 = ConstantExpr::getTrunc(P0, Int1Ty); - Constant *P4 = ConstantExpr::getPtrToInt(Global2, Int32Ty); - Constant *P5 = ConstantExpr::getUIToFP(P4, FloatTy); - Constant *P6 = ConstantExpr::getBitCast(P4, VectorType::get(Int16Ty, 2)); - - Constant *One = ConstantInt::get(Int32Ty, 1); - - #define P0STR "ptrtoint (i32** @dummy to i32)" - #define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)" - #define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)" - #define P3STR "ptrtoint (i32** @dummy to i1)" - #define P4STR "ptrtoint (i32** @dummy2 to i32)" - #define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)" - #define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)" - - CHECK(ConstantExpr::getNeg(P0), "sub i32 0, " P0STR); - CHECK(ConstantExpr::getFNeg(P1), "fsub float -0.000000e+00, " P1STR); - CHECK(ConstantExpr::getNot(P0), "xor i32 " P0STR ", -1"); - CHECK(ConstantExpr::getAdd(P0, P0), "add i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getAdd(P0, P0, false, true), "add nsw i32 " P0STR ", " - P0STR); - CHECK(ConstantExpr::getAdd(P0, P0, true, true), "add nuw nsw i32 " P0STR ", " - P0STR); - CHECK(ConstantExpr::getFAdd(P1, P1), "fadd float " P1STR ", " P1STR); - CHECK(ConstantExpr::getSub(P0, P0), "sub i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getFSub(P1, P1), "fsub float " P1STR ", " P1STR); - CHECK(ConstantExpr::getMul(P0, P0), "mul i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getFMul(P1, P1), "fmul float " P1STR ", " P1STR); - CHECK(ConstantExpr::getUDiv(P0, P0), "udiv i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getSDiv(P0, P0), "sdiv i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getFDiv(P1, P1), "fdiv float " P1STR ", " P1STR); - CHECK(ConstantExpr::getURem(P0, P0), "urem i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getSRem(P0, P0), "srem i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getFRem(P1, P1), "frem float " P1STR ", " P1STR); - CHECK(ConstantExpr::getAnd(P0, P0), "and i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getOr(P0, P0), "or i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getXor(P0, P0), "xor i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getShl(P0, P0), "shl i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getShl(P0, P0, true), "shl nuw i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getShl(P0, P0, false, true), "shl nsw i32 " P0STR ", " - P0STR); - CHECK(ConstantExpr::getLShr(P0, P0, false), "lshr i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getLShr(P0, P0, true), "lshr exact i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getAShr(P0, P0, false), "ashr i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getAShr(P0, P0, true), "ashr exact i32 " P0STR ", " P0STR); - - CHECK(ConstantExpr::getSExt(P0, Int64Ty), "sext i32 " P0STR " to i64"); - CHECK(ConstantExpr::getZExt(P0, Int64Ty), "zext i32 " P0STR " to i64"); - CHECK(ConstantExpr::getFPTrunc(P2, FloatTy), "fptrunc double " P2STR - " to float"); - CHECK(ConstantExpr::getFPExtend(P1, DoubleTy), "fpext float " P1STR - " to double"); - - CHECK(ConstantExpr::getExactUDiv(P0, P0), "udiv exact i32 " P0STR ", " P0STR); - - CHECK(ConstantExpr::getSelect(P3, P0, P4), "select i1 " P3STR ", i32 " P0STR - ", i32 " P4STR); - CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), "icmp eq i32 " P0STR - ", " P4STR); - CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), "fcmp ult float " - P1STR ", " P5STR); - - std::vector<Constant*> V; - V.push_back(One); - // FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP, - // not a normal one! - //CHECK(ConstantExpr::getGetElementPtr(Global, V, false), - // "getelementptr i32** @dummy, i32 1"); - CHECK(ConstantExpr::getInBoundsGetElementPtr(Global, V), - "getelementptr inbounds i32** @dummy, i32 1"); - - CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> " - P6STR ", i32 1"); -} - -#undef CHECK - -} // end anonymous namespace -} // end namespace llvm diff --git a/unittests/VMCore/DominatorTreeTest.cpp b/unittests/VMCore/DominatorTreeTest.cpp deleted file mode 100644 index 3a527adbc0..0000000000 --- a/unittests/VMCore/DominatorTreeTest.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include "llvm/Analysis/Dominators.h" -#include "llvm/Assembly/Parser.h" -#include "llvm/IR/Instructions.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Module.h" -#include "llvm/PassManager.h" -#include "llvm/Support/SourceMgr.h" -#include "gtest/gtest.h" - -using namespace llvm; - -namespace llvm { - void initializeDPassPass(PassRegistry&); - - namespace { - struct DPass : public FunctionPass { - static char ID; - virtual bool runOnFunction(Function &F) { - DominatorTree *DT = &getAnalysis<DominatorTree>(); - Function::iterator FI = F.begin(); - - BasicBlock *BB0 = FI++; - BasicBlock::iterator BBI = BB0->begin(); - Instruction *Y1 = BBI++; - Instruction *Y2 = BBI++; - Instruction *Y3 = BBI++; - - BasicBlock *BB1 = FI++; - BBI = BB1->begin(); - Instruction *Y4 = BBI++; - - BasicBlock *BB2 = FI++; - BBI = BB2->begin(); - Instruction *Y5 = BBI++; - - BasicBlock *BB3 = FI++; - BBI = BB3->begin(); - Instruction *Y6 = BBI++; - Instruction *Y7 = BBI++; - - BasicBlock *BB4 = FI++; - BBI = BB4->begin(); - Instruction *Y8 = BBI++; - Instruction *Y9 = BBI++; - - // Reachability - EXPECT_TRUE(DT->isReachableFromEntry(BB0)); - EXPECT_TRUE(DT->isReachableFromEntry(BB1)); - EXPECT_TRUE(DT->isReachableFromEntry(BB2)); - EXPECT_FALSE(DT->isReachableFromEntry(BB3)); - EXPECT_TRUE(DT->isReachableFromEntry(BB4)); - - // BB dominance - EXPECT_TRUE(DT->dominates(BB0, BB0)); - EXPECT_TRUE(DT->dominates(BB0, BB1)); - EXPECT_TRUE(DT->dominates(BB0, BB2)); - EXPECT_TRUE(DT->dominates(BB0, BB3)); - EXPECT_TRUE(DT->dominates(BB0, BB4)); - - EXPECT_FALSE(DT->dominates(BB1, BB0)); - EXPECT_TRUE(DT->dominates(BB1, BB1)); - EXPECT_FALSE(DT->dominates(BB1, BB2)); - EXPECT_TRUE(DT->dominates(BB1, BB3)); - EXPECT_FALSE(DT->dominates(BB1, BB4)); - - EXPECT_FALSE(DT->dominates(BB2, BB0)); - EXPECT_FALSE(DT->dominates(BB2, BB1)); - EXPECT_TRUE(DT->dominates(BB2, BB2)); - EXPECT_TRUE(DT->dominates(BB2, BB3)); - EXPECT_FALSE(DT->dominates(BB2, BB4)); - - EXPECT_FALSE(DT->dominates(BB3, BB0)); - EXPECT_FALSE(DT->dominates(BB3, BB1)); - EXPECT_FALSE(DT->dominates(BB3, BB2)); - EXPECT_TRUE(DT->dominates(BB3, BB3)); - EXPECT_FALSE(DT->dominates(BB3, BB4)); - - // BB proper dominance - EXPECT_FALSE(DT->properlyDominates(BB0, BB0)); - EXPECT_TRUE(DT->properlyDominates(BB0, BB1)); - EXPECT_TRUE(DT->properlyDominates(BB0, BB2)); - EXPECT_TRUE(DT->properlyDominates(BB0, BB3)); - - EXPECT_FALSE(DT->properlyDominates(BB1, BB0)); - EXPECT_FALSE(DT->properlyDominates(BB1, BB1)); - EXPECT_FALSE(DT->properlyDominates(BB1, BB2)); - EXPECT_TRUE(DT->properlyDominates(BB1, BB3)); - - EXPECT_FALSE(DT->properlyDominates(BB2, BB0)); - EXPECT_FALSE(DT->properlyDominates(BB2, BB1)); - EXPECT_FALSE(DT->properlyDominates(BB2, BB2)); - EXPECT_TRUE(DT->properlyDominates(BB2, BB3)); - - EXPECT_FALSE(DT->properlyDominates(BB3, BB0)); - EXPECT_FALSE(DT->properlyDominates(BB3, BB1)); - EXPECT_FALSE(DT->properlyDominates(BB3, BB2)); - EXPECT_FALSE(DT->properlyDominates(BB3, BB3)); - - // Instruction dominance in the same reachable BB - EXPECT_FALSE(DT->dominates(Y1, Y1)); - EXPECT_TRUE(DT->dominates(Y1, Y2)); - EXPECT_FALSE(DT->dominates(Y2, Y1)); - EXPECT_FALSE(DT->dominates(Y2, Y2)); - - // Instruction dominance in the same unreachable BB - EXPECT_TRUE(DT->dominates(Y6, Y6)); - EXPECT_TRUE(DT->dominates(Y6, Y7)); - EXPECT_TRUE(DT->dominates(Y7, Y6)); - EXPECT_TRUE(DT->dominates(Y7, Y7)); - - // Invoke - EXPECT_TRUE(DT->dominates(Y3, Y4)); - EXPECT_FALSE(DT->dominates(Y3, Y5)); - - // Phi - EXPECT_TRUE(DT->dominates(Y2, Y9)); - EXPECT_FALSE(DT->dominates(Y3, Y9)); - EXPECT_FALSE(DT->dominates(Y8, Y9)); - - // Anything dominates unreachable - EXPECT_TRUE(DT->dominates(Y1, Y6)); - EXPECT_TRUE(DT->dominates(Y3, Y6)); - - // Unreachable doesn't dominate reachable - EXPECT_FALSE(DT->dominates(Y6, Y1)); - - // Instruction, BB dominance - EXPECT_FALSE(DT->dominates(Y1, BB0)); - EXPECT_TRUE(DT->dominates(Y1, BB1)); - EXPECT_TRUE(DT->dominates(Y1, BB2)); - EXPECT_TRUE(DT->dominates(Y1, BB3)); - EXPECT_TRUE(DT->dominates(Y1, BB4)); - - EXPECT_FALSE(DT->dominates(Y3, BB0)); - EXPECT_TRUE(DT->dominates(Y3, BB1)); - EXPECT_FALSE(DT->dominates(Y3, BB2)); - EXPECT_TRUE(DT->dominates(Y3, BB3)); - EXPECT_FALSE(DT->dominates(Y3, BB4)); - - EXPECT_TRUE(DT->dominates(Y6, BB3)); - - return false; - } - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired<DominatorTree>(); - } - DPass() : FunctionPass(ID) { - initializeDPassPass(*PassRegistry::getPassRegistry()); - } - }; - char DPass::ID = 0; - - - Module* makeLLVMModule(DPass *P) { - const char *ModuleStrig = - "declare i32 @g()\n" \ - "define void @f(i32 %x) {\n" \ - "bb0:\n" \ - " %y1 = add i32 %x, 1\n" \ - " %y2 = add i32 %x, 1\n" \ - " %y3 = invoke i32 @g() to label %bb1 unwind label %bb2\n" \ - "bb1:\n" \ - " %y4 = add i32 %x, 1\n" \ - " br label %bb4\n" \ - "bb2:\n" \ - " %y5 = landingpad i32 personality i32 ()* @g\n" \ - " cleanup\n" \ - " br label %bb4\n" \ - "bb3:\n" \ - " %y6 = add i32 %x, 1\n" \ - " %y7 = add i32 %x, 1\n" \ - " ret void\n" \ - "bb4:\n" \ - " %y8 = phi i32 [0, %bb2], [%y4, %bb1]\n" - " %y9 = phi i32 [0, %bb2], [%y4, %bb1]\n" - " ret void\n" \ - "}\n"; - LLVMContext &C = getGlobalContext(); - SMDiagnostic Err; - return ParseAssemblyString(ModuleStrig, NULL, Err, C); - } - - TEST(DominatorTree, Unreachable) { - DPass *P = new DPass(); - Module *M = makeLLVMModule(P); - PassManager Passes; - Passes.add(P); - Passes.run(*M); - } - } -} - -INITIALIZE_PASS_BEGIN(DPass, "dpass", "dpass", false, false) -INITIALIZE_PASS_DEPENDENCY(DominatorTree) -INITIALIZE_PASS_END(DPass, "dpass", "dpass", false, false) diff --git a/unittests/VMCore/IRBuilderTest.cpp b/unittests/VMCore/IRBuilderTest.cpp deleted file mode 100644 index a9df2f6911..0000000000 --- a/unittests/VMCore/IRBuilderTest.cpp +++ /dev/null @@ -1,184 +0,0 @@ -//===- llvm/unittest/VMCore/IRBuilderTest.cpp - IRBuilder tests -----------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/IR/IRBuilder.h" -#include "llvm/ADT/OwningPtr.h" -#include "llvm/IR/BasicBlock.h" -#include "llvm/IR/DataLayout.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/MDBuilder.h" -#include "llvm/IR/Module.h" -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -class IRBuilderTest : public testing::Test { -protected: - virtual void SetUp() { - M.reset(new Module("MyModule", getGlobalContext())); - FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()), - /*isVarArg=*/false); - F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); - BB = BasicBlock::Create(getGlobalContext(), "", F); - GV = new GlobalVariable(Type::getFloatTy(getGlobalContext()), true, - GlobalValue::ExternalLinkage); - } - - virtual void TearDown() { - BB = 0; - M.reset(); - } - - OwningPtr<Module> M; - Function *F; - BasicBlock *BB; - GlobalVariable *GV; -}; - -TEST_F(IRBuilderTest, Lifetime) { - IRBuilder<> Builder(BB); - AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty()); - AllocaInst *Var2 = Builder.CreateAlloca(Builder.getInt32Ty()); - AllocaInst *Var3 = Builder.CreateAlloca(Builder.getInt8Ty(), - Builder.getInt32(123)); - - CallInst *Start1 = Builder.CreateLifetimeStart(Var1); - CallInst *Start2 = Builder.CreateLifetimeStart(Var2); - CallInst *Start3 = Builder.CreateLifetimeStart(Var3, Builder.getInt64(100)); - - EXPECT_EQ(Start1->getArgOperand(0), Builder.getInt64(-1)); - EXPECT_EQ(Start2->getArgOperand(0), Builder.getInt64(-1)); - EXPECT_EQ(Start3->getArgOperand(0), Builder.getInt64(100)); - - EXPECT_EQ(Start1->getArgOperand(1), Var1); - EXPECT_NE(Start2->getArgOperand(1), Var2); - EXPECT_EQ(Start3->getArgOperand(1), Var3); - - Value *End1 = Builder.CreateLifetimeEnd(Var1); - Builder.CreateLifetimeEnd(Var2); - Builder.CreateLifetimeEnd(Var3); - - IntrinsicInst *II_Start1 = dyn_cast<IntrinsicInst>(Start1); - IntrinsicInst *II_End1 = dyn_cast<IntrinsicInst>(End1); - ASSERT_TRUE(II_Start1 != NULL); - EXPECT_EQ(II_Start1->getIntrinsicID(), Intrinsic::lifetime_start); - ASSERT_TRUE(II_End1 != NULL); - EXPECT_EQ(II_End1->getIntrinsicID(), Intrinsic::lifetime_end); -} - -TEST_F(IRBuilderTest, CreateCondBr) { - IRBuilder<> Builder(BB); - BasicBlock *TBB = BasicBlock::Create(getGlobalContext(), "", F); - BasicBlock *FBB = BasicBlock::Create(getGlobalContext(), "", F); - - BranchInst *BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB); - TerminatorInst *TI = BB->getTerminator(); - EXPECT_EQ(BI, TI); - EXPECT_EQ(2u, TI->getNumSuccessors()); - EXPECT_EQ(TBB, TI->getSuccessor(0)); - EXPECT_EQ(FBB, TI->getSuccessor(1)); - - BI->eraseFromParent(); - MDNode *Weights = MDBuilder(getGlobalContext()).createBranchWeights(42, 13); - BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB, Weights); - TI = BB->getTerminator(); - EXPECT_EQ(BI, TI); - EXPECT_EQ(2u, TI->getNumSuccessors()); - EXPECT_EQ(TBB, TI->getSuccessor(0)); - EXPECT_EQ(FBB, TI->getSuccessor(1)); - EXPECT_EQ(Weights, TI->getMetadata(LLVMContext::MD_prof)); -} - -TEST_F(IRBuilderTest, LandingPadName) { - IRBuilder<> Builder(BB); - LandingPadInst *LP = Builder.CreateLandingPad(Builder.getInt32Ty(), - Builder.getInt32(0), 0, "LP"); - EXPECT_EQ(LP->getName(), "LP"); -} - -TEST_F(IRBuilderTest, GetIntTy) { - IRBuilder<> Builder(BB); - IntegerType *Ty1 = Builder.getInt1Ty(); - EXPECT_EQ(Ty1, IntegerType::get(getGlobalContext(), 1)); - - DataLayout* DL = new DataLayout(M.get()); - IntegerType *IntPtrTy = Builder.getIntPtrTy(DL); - unsigned IntPtrBitSize = DL->getPointerSizeInBits(0); - EXPECT_EQ(IntPtrTy, IntegerType::get(getGlobalContext(), IntPtrBitSize)); -} - -TEST_F(IRBuilderTest, FastMathFlags) { - IRBuilder<> Builder(BB); - Value *F; - Instruction *FDiv, *FAdd; - - F = Builder.CreateLoad(GV); - F = Builder.CreateFAdd(F, F); - - EXPECT_FALSE(Builder.getFastMathFlags().any()); - ASSERT_TRUE(isa<Instruction>(F)); - FAdd = cast<Instruction>(F); - EXPECT_FALSE(FAdd->hasNoNaNs()); - - FastMathFlags FMF; - Builder.SetFastMathFlags(FMF); - - F = Builder.CreateFAdd(F, F); - EXPECT_FALSE(Builder.getFastMathFlags().any()); - - FMF.setUnsafeAlgebra(); - Builder.SetFastMathFlags(FMF); - - F = Builder.CreateFAdd(F, F); - EXPECT_TRUE(Builder.getFastMathFlags().any()); - ASSERT_TRUE(isa<Instruction>(F)); - FAdd = cast<Instruction>(F); - EXPECT_TRUE(FAdd->hasNoNaNs()); - - F = Builder.CreateFDiv(F, F); - EXPECT_TRUE(Builder.getFastMathFlags().any()); - EXPECT_TRUE(Builder.getFastMathFlags().UnsafeAlgebra); - ASSERT_TRUE(isa<Instruction>(F)); - FDiv = cast<Instruction>(F); - EXPECT_TRUE(FDiv->hasAllowReciprocal()); - - Builder.clearFastMathFlags(); - - F = Builder.CreateFDiv(F, F); - ASSERT_TRUE(isa<Instruction>(F)); - FDiv = cast<Instruction>(F); - EXPECT_FALSE(FDiv->hasAllowReciprocal()); - - FMF.clear(); - FMF.setAllowReciprocal(); - Builder.SetFastMathFlags(FMF); - - F = Builder.CreateFDiv(F, F); - EXPECT_TRUE(Builder.getFastMathFlags().any()); - EXPECT_TRUE(Builder.getFastMathFlags().AllowReciprocal); - ASSERT_TRUE(isa<Instruction>(F)); - FDiv = cast<Instruction>(F); - EXPECT_TRUE(FDiv->hasAllowReciprocal()); - - Builder.clearFastMathFlags(); - - F = Builder.CreateFDiv(F, F); - ASSERT_TRUE(isa<Instruction>(F)); - FDiv = cast<Instruction>(F); - EXPECT_FALSE(FDiv->getFastMathFlags().any()); - FDiv->copyFastMathFlags(FAdd); - EXPECT_TRUE(FDiv->hasNoNaNs()); - -} - -} diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp deleted file mode 100644 index 6559b1d0ee..0000000000 --- a/unittests/VMCore/InstructionsTest.cpp +++ /dev/null @@ -1,284 +0,0 @@ -//===- llvm/unittest/VMCore/InstructionsTest.cpp - Instructions 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/IR/Instructions.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/Analysis/ValueTracking.h" -#include "llvm/IR/BasicBlock.h" -#include "llvm/IR/Constants.h" -#include "llvm/IR/DataLayout.h" -#include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/IRBuilder.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/MDBuilder.h" -#include "llvm/IR/Operator.h" -#include "gtest/gtest.h" - -namespace llvm { -namespace { - -TEST(InstructionsTest, ReturnInst) { - LLVMContext &C(getGlobalContext()); - - // test for PR6589 - const ReturnInst* r0 = ReturnInst::Create(C); - EXPECT_EQ(r0->getNumOperands(), 0U); - EXPECT_EQ(r0->op_begin(), r0->op_end()); - - IntegerType* Int1 = IntegerType::get(C, 1); - Constant* One = ConstantInt::get(Int1, 1, true); - const ReturnInst* r1 = ReturnInst::Create(C, One); - EXPECT_EQ(1U, r1->getNumOperands()); - User::const_op_iterator b(r1->op_begin()); - EXPECT_NE(r1->op_end(), b); - EXPECT_EQ(One, *b); - EXPECT_EQ(One, r1->getOperand(0)); - ++b; - EXPECT_EQ(r1->op_end(), b); - - // clean up - delete r0; - delete r1; -} - -TEST(InstructionsTest, BranchInst) { - LLVMContext &C(getGlobalContext()); - - // Make a BasicBlocks - BasicBlock* bb0 = BasicBlock::Create(C); - BasicBlock* bb1 = BasicBlock::Create(C); - - // Mandatory BranchInst - const BranchInst* b0 = BranchInst::Create(bb0); - - EXPECT_TRUE(b0->isUnconditional()); - EXPECT_FALSE(b0->isConditional()); - EXPECT_EQ(1U, b0->getNumSuccessors()); - - // check num operands - EXPECT_EQ(1U, b0->getNumOperands()); - - EXPECT_NE(b0->op_begin(), b0->op_end()); - EXPECT_EQ(b0->op_end(), llvm::next(b0->op_begin())); - - EXPECT_EQ(b0->op_end(), llvm::next(b0->op_begin())); - - IntegerType* Int1 = IntegerType::get(C, 1); - Constant* One = ConstantInt::get(Int1, 1, true); - - // Conditional BranchInst - BranchInst* b1 = BranchInst::Create(bb0, bb1, One); - - EXPECT_FALSE(b1->isUnconditional()); - EXPECT_TRUE(b1->isConditional()); - EXPECT_EQ(2U, b1->getNumSuccessors()); - - // check num operands - EXPECT_EQ(3U, b1->getNumOperands()); - - User::const_op_iterator b(b1->op_begin()); - - // check COND - EXPECT_NE(b, b1->op_end()); - EXPECT_EQ(One, *b); - EXPECT_EQ(One, b1->getOperand(0)); - EXPECT_EQ(One, b1->getCondition()); - ++b; - - // check ELSE - EXPECT_EQ(bb1, *b); - EXPECT_EQ(bb1, b1->getOperand(1)); - EXPECT_EQ(bb1, b1->getSuccessor(1)); - ++b; - - // check THEN - EXPECT_EQ(bb0, *b); - EXPECT_EQ(bb0, b1->getOperand(2)); - EXPECT_EQ(bb0, b1->getSuccessor(0)); - ++b; - - EXPECT_EQ(b1->op_end(), b); - - // clean up - delete b0; - delete b1; - - delete bb0; - delete bb1; -} - -TEST(InstructionsTest, CastInst) { - LLVMContext &C(getGlobalContext()); - - Type* Int8Ty = Type::getInt8Ty(C); - Type* Int64Ty = Type::getInt64Ty(C); - Type* V8x8Ty = VectorType::get(Int8Ty, 8); - Type* V8x64Ty = VectorType::get(Int64Ty, 8); - Type* X86MMXTy = Type::getX86_MMXTy(C); - - const Constant* c8 = Constant::getNullValue(V8x8Ty); - const Constant* c64 = Constant::getNullValue(V8x64Ty); - - EXPECT_TRUE(CastInst::isCastable(V8x8Ty, X86MMXTy)); - EXPECT_TRUE(CastInst::isCastable(X86MMXTy, V8x8Ty)); - EXPECT_FALSE(CastInst::isCastable(Int64Ty, X86MMXTy)); - EXPECT_TRUE(CastInst::isCastable(V8x64Ty, V8x8Ty)); - EXPECT_TRUE(CastInst::isCastable(V8x8Ty, V8x64Ty)); - EXPECT_EQ(CastInst::Trunc, CastInst::getCastOpcode(c64, true, V8x8Ty, true)); - EXPECT_EQ(CastInst::SExt, CastInst::getCastOpcode(c8, true, V8x64Ty, true)); -} - - - -TEST(InstructionsTest, VectorGep) { - LLVMContext &C(getGlobalContext()); - - // Type Definitions - PointerType *Ptri8Ty = PointerType::get(IntegerType::get(C, 8), 0); - PointerType *Ptri32Ty = PointerType::get(IntegerType::get(C, 8), 0); - - VectorType *V2xi8PTy = VectorType::get(Ptri8Ty, 2); - VectorType *V2xi32PTy = VectorType::get(Ptri32Ty, 2); - - // Test different aspects of the vector-of-pointers type - // and GEPs which use this type. - ConstantInt *Ci32a = ConstantInt::get(C, APInt(32, 1492)); - ConstantInt *Ci32b = ConstantInt::get(C, APInt(32, 1948)); - std::vector<Constant*> ConstVa(2, Ci32a); - std::vector<Constant*> ConstVb(2, Ci32b); - Constant *C2xi32a = ConstantVector::get(ConstVa); - Constant *C2xi32b = ConstantVector::get(ConstVb); - - CastInst *PtrVecA = new IntToPtrInst(C2xi32a, V2xi32PTy); - CastInst *PtrVecB = new IntToPtrInst(C2xi32b, V2xi32PTy); - - ICmpInst *ICmp0 = new ICmpInst(ICmpInst::ICMP_SGT, PtrVecA, PtrVecB); - ICmpInst *ICmp1 = new ICmpInst(ICmpInst::ICMP_ULT, PtrVecA, PtrVecB); - EXPECT_NE(ICmp0, ICmp1); // suppress warning. - - GetElementPtrInst *Gep0 = GetElementPtrInst::Create(PtrVecA, C2xi32a); - GetElementPtrInst *Gep1 = GetElementPtrInst::Create(PtrVecA, C2xi32b); - GetElementPtrInst *Gep2 = GetElementPtrInst::Create(PtrVecB, C2xi32a); - GetElementPtrInst *Gep3 = GetElementPtrInst::Create(PtrVecB, C2xi32b); - - CastInst *BTC0 = new BitCastInst(Gep0, V2xi8PTy); - CastInst *BTC1 = new BitCastInst(Gep1, V2xi8PTy); - CastInst *BTC2 = new BitCastInst(Gep2, V2xi8PTy); - CastInst *BTC3 = new BitCastInst(Gep3, V2xi8PTy); - - Value *S0 = BTC0->stripPointerCasts(); - Value *S1 = BTC1->stripPointerCasts(); - Value *S2 = BTC2->stripPointerCasts(); - Value *S3 = BTC3->stripPointerCasts(); - - EXPECT_NE(S0, Gep0); - EXPECT_NE(S1, Gep1); - EXPECT_NE(S2, Gep2); - EXPECT_NE(S3, Gep3); - - int64_t Offset; - DataLayout TD("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3" - "2:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80" - ":128:128-n8:16:32:64-S128"); - // Make sure we don't crash - GetPointerBaseWithConstantOffset(Gep0, Offset, TD); - GetPointerBaseWithConstantOffset(Gep1, Offset, TD); - GetPointerBaseWithConstantOffset(Gep2, Offset, TD); - GetPointerBaseWithConstantOffset(Gep3, Offset, TD); - - // Gep of Geps - GetElementPtrInst *GepII0 = GetElementPtrInst::Create(Gep0, C2xi32b); - GetElementPtrInst *GepII1 = GetElementPtrInst::Create(Gep1, C2xi32a); - GetElementPtrInst *GepII2 = GetElementPtrInst::Create(Gep2, C2xi32b); - GetElementPtrInst *GepII3 = GetElementPtrInst::Create(Gep3, C2xi32a); - - EXPECT_EQ(GepII0->getNumIndices(), 1u); - EXPECT_EQ(GepII1->getNumIndices(), 1u); - EXPECT_EQ(GepII2->getNumIndices(), 1u); - EXPECT_EQ(GepII3->getNumIndices(), 1u); - - EXPECT_FALSE(GepII0->hasAllZeroIndices()); - EXPECT_FALSE(GepII1->hasAllZeroIndices()); - EXPECT_FALSE(GepII2->hasAllZeroIndices()); - EXPECT_FALSE(GepII3->hasAllZeroIndices()); - - delete GepII0; - delete GepII1; - delete GepII2; - delete GepII3; - - delete BTC0; - delete BTC1; - delete BTC2; - delete BTC3; - - delete Gep0; - delete Gep1; - delete Gep2; - delete Gep3; - - delete ICmp0; - delete ICmp1; - delete PtrVecA; - delete PtrVecB; -} - -TEST(InstructionsTest, FPMathOperator) { - LLVMContext &Context = getGlobalContext(); - IRBuilder<> Builder(Context); - MDBuilder MDHelper(Context); - Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0); - MDNode *MD1 = MDHelper.createFPMath(1.0); - Value *V1 = Builder.CreateFAdd(I, I, "", MD1); - EXPECT_TRUE(isa<FPMathOperator>(V1)); |