From 0baa4809a8de135a6a7abe9cd78a86f208c99164 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 15 Jul 2012 23:26:50 +0000 Subject: Move llvm/Support/MDBuilder.h to llvm/MDBuilder.h, to live with IRBuilder, DIBuilder, etc. This is the proper layering as MDBuilder can't be used (or implemented) without the Core Metadata representation. Patches to Clang and Dragonegg coming up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160237 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/CMakeLists.txt | 1 - unittests/Support/MDBuilderTest.cpp | 107 ---------------------------------- unittests/VMCore/CMakeLists.txt | 1 + unittests/VMCore/InstructionsTest.cpp | 2 +- unittests/VMCore/MDBuilderTest.cpp | 107 ++++++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 109 deletions(-) delete mode 100644 unittests/Support/MDBuilderTest.cpp create mode 100644 unittests/VMCore/MDBuilderTest.cpp (limited to 'unittests') diff --git a/unittests/Support/CMakeLists.txt b/unittests/Support/CMakeLists.txt index 6053994..674da35 100644 --- a/unittests/Support/CMakeLists.txt +++ b/unittests/Support/CMakeLists.txt @@ -17,7 +17,6 @@ add_llvm_unittest(SupportTests LeakDetectorTest.cpp ManagedStatic.cpp MathExtrasTest.cpp - MDBuilderTest.cpp Path.cpp raw_ostream_test.cpp RegexTest.cpp diff --git a/unittests/Support/MDBuilderTest.cpp b/unittests/Support/MDBuilderTest.cpp deleted file mode 100644 index af3f434..0000000 --- a/unittests/Support/MDBuilderTest.cpp +++ /dev/null @@ -1,107 +0,0 @@ -//===- llvm/unittests/Support/MDBuilderTest.cpp - MDBuilder 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/IRBuilder.h" -#include "llvm/Operator.h" -#include "llvm/Support/MDBuilder.h" - -#include "gtest/gtest.h" - -using namespace llvm; - -namespace { - -class MDBuilderTest : public testing::Test { -protected: - LLVMContext Context; -}; - -TEST_F(MDBuilderTest, createString) { - MDBuilder MDHelper(Context); - MDString *Str0 = MDHelper.createString(""); - MDString *Str1 = MDHelper.createString("string"); - EXPECT_EQ(Str0->getString(), StringRef("")); - EXPECT_EQ(Str1->getString(), StringRef("string")); -} -TEST_F(MDBuilderTest, createFPMath) { - MDBuilder MDHelper(Context); - MDNode *MD0 = MDHelper.createFPMath(0.0); - MDNode *MD1 = MDHelper.createFPMath(1.0); - EXPECT_EQ(MD0, (MDNode *)0); - EXPECT_NE(MD1, (MDNode *)0); - EXPECT_EQ(MD1->getNumOperands(), 1U); - Value *Op = MD1->getOperand(0); - EXPECT_TRUE(isa(Op)); - EXPECT_TRUE(Op->getType()->isFloatingPointTy()); - ConstantFP *Val = cast(Op); - EXPECT_TRUE(Val->isExactlyValue(1.0)); -} -TEST_F(MDBuilderTest, createRangeMetadata) { - MDBuilder MDHelper(Context); - APInt A(8, 1), B(8, 2); - MDNode *R0 = MDHelper.createRange(A, A); - MDNode *R1 = MDHelper.createRange(A, B); - EXPECT_EQ(R0, (MDNode *)0); - EXPECT_NE(R1, (MDNode *)0); - EXPECT_EQ(R1->getNumOperands(), 2U); - EXPECT_TRUE(isa(R1->getOperand(0))); - EXPECT_TRUE(isa(R1->getOperand(1))); - ConstantInt *C0 = cast(R1->getOperand(0)); - ConstantInt *C1 = cast(R1->getOperand(1)); - EXPECT_EQ(C0->getValue(), A); - EXPECT_EQ(C1->getValue(), B); -} -TEST_F(MDBuilderTest, createAnonymousTBAARoot) { - MDBuilder MDHelper(Context); - MDNode *R0 = MDHelper.createAnonymousTBAARoot(); - MDNode *R1 = MDHelper.createAnonymousTBAARoot(); - EXPECT_NE(R0, R1); - EXPECT_GE(R0->getNumOperands(), 1U); - EXPECT_GE(R1->getNumOperands(), 1U); - EXPECT_EQ(R0->getOperand(0), R0); - EXPECT_EQ(R1->getOperand(0), R1); - EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0); - EXPECT_TRUE(R1->getNumOperands() == 1 || R1->getOperand(1) == 0); -} -TEST_F(MDBuilderTest, createTBAARoot) { - MDBuilder MDHelper(Context); - MDNode *R0 = MDHelper.createTBAARoot("Root"); - MDNode *R1 = MDHelper.createTBAARoot("Root"); - EXPECT_EQ(R0, R1); - EXPECT_GE(R0->getNumOperands(), 1U); - EXPECT_TRUE(isa(R0->getOperand(0))); - EXPECT_EQ(cast(R0->getOperand(0))->getString(), "Root"); - EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0); -} -TEST_F(MDBuilderTest, createTBAANode) { - MDBuilder MDHelper(Context); - MDNode *R = MDHelper.createTBAARoot("Root"); - MDNode *N0 = MDHelper.createTBAANode("Node", R); - MDNode *N1 = MDHelper.createTBAANode("edoN", R); - MDNode *N2 = MDHelper.createTBAANode("Node", R, true); - MDNode *N3 = MDHelper.createTBAANode("Node", R); - EXPECT_EQ(N0, N3); - EXPECT_NE(N0, N1); - EXPECT_NE(N0, N2); - EXPECT_GE(N0->getNumOperands(), 2U); - EXPECT_GE(N1->getNumOperands(), 2U); - EXPECT_GE(N2->getNumOperands(), 3U); - EXPECT_TRUE(isa(N0->getOperand(0))); - EXPECT_TRUE(isa(N1->getOperand(0))); - EXPECT_TRUE(isa(N2->getOperand(0))); - EXPECT_EQ(cast(N0->getOperand(0))->getString(), "Node"); - EXPECT_EQ(cast(N1->getOperand(0))->getString(), "edoN"); - EXPECT_EQ(cast(N2->getOperand(0))->getString(), "Node"); - EXPECT_EQ(N0->getOperand(1), R); - EXPECT_EQ(N1->getOperand(1), R); - EXPECT_EQ(N2->getOperand(1), R); - EXPECT_TRUE(isa(N2->getOperand(2))); - EXPECT_EQ(cast(N2->getOperand(2))->getZExtValue(), 1U); -} -} diff --git a/unittests/VMCore/CMakeLists.txt b/unittests/VMCore/CMakeLists.txt index 5a87605..79ee22c 100644 --- a/unittests/VMCore/CMakeLists.txt +++ b/unittests/VMCore/CMakeLists.txt @@ -8,6 +8,7 @@ set(VMCoreSources ConstantsTest.cpp DominatorTreeTest.cpp InstructionsTest.cpp + MDBuilderTest.cpp MetadataTest.cpp PassManagerTest.cpp ValueMapTest.cpp diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp index a8902d9..72cdc8b 100644 --- a/unittests/VMCore/InstructionsTest.cpp +++ b/unittests/VMCore/InstructionsTest.cpp @@ -13,10 +13,10 @@ #include "llvm/IRBuilder.h" #include "llvm/Instructions.h" #include "llvm/LLVMContext.h" +#include "llvm/MDBuilder.h" #include "llvm/Operator.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/ValueTracking.h" -#include "llvm/Support/MDBuilder.h" #include "llvm/Target/TargetData.h" #include "gtest/gtest.h" diff --git a/unittests/VMCore/MDBuilderTest.cpp b/unittests/VMCore/MDBuilderTest.cpp new file mode 100644 index 0000000..847039b --- /dev/null +++ b/unittests/VMCore/MDBuilderTest.cpp @@ -0,0 +1,107 @@ +//===- llvm/unittests/MDBuilderTest.cpp - MDBuilder 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/IRBuilder.h" +#include "llvm/MDBuilder.h" +#include "llvm/Operator.h" + +#include "gtest/gtest.h" + +using namespace llvm; + +namespace { + +class MDBuilderTest : public testing::Test { +protected: + LLVMContext Context; +}; + +TEST_F(MDBuilderTest, createString) { + MDBuilder MDHelper(Context); + MDString *Str0 = MDHelper.createString(""); + MDString *Str1 = MDHelper.createString("string"); + EXPECT_EQ(Str0->getString(), StringRef("")); + EXPECT_EQ(Str1->getString(), StringRef("string")); +} +TEST_F(MDBuilderTest, createFPMath) { + MDBuilder MDHelper(Context); + MDNode *MD0 = MDHelper.createFPMath(0.0); + MDNode *MD1 = MDHelper.createFPMath(1.0); + EXPECT_EQ(MD0, (MDNode *)0); + EXPECT_NE(MD1, (MDNode *)0); + EXPECT_EQ(MD1->getNumOperands(), 1U); + Value *Op = MD1->getOperand(0); + EXPECT_TRUE(isa(Op)); + EXPECT_TRUE(Op->getType()->isFloatingPointTy()); + ConstantFP *Val = cast(Op); + EXPECT_TRUE(Val->isExactlyValue(1.0)); +} +TEST_F(MDBuilderTest, createRangeMetadata) { + MDBuilder MDHelper(Context); + APInt A(8, 1), B(8, 2); + MDNode *R0 = MDHelper.createRange(A, A); + MDNode *R1 = MDHelper.createRange(A, B); + EXPECT_EQ(R0, (MDNode *)0); + EXPECT_NE(R1, (MDNode *)0); + EXPECT_EQ(R1->getNumOperands(), 2U); + EXPECT_TRUE(isa(R1->getOperand(0))); + EXPECT_TRUE(isa(R1->getOperand(1))); + ConstantInt *C0 = cast(R1->getOperand(0)); + ConstantInt *C1 = cast(R1->getOperand(1)); + EXPECT_EQ(C0->getValue(), A); + EXPECT_EQ(C1->getValue(), B); +} +TEST_F(MDBuilderTest, createAnonymousTBAARoot) { + MDBuilder MDHelper(Context); + MDNode *R0 = MDHelper.createAnonymousTBAARoot(); + MDNode *R1 = MDHelper.createAnonymousTBAARoot(); + EXPECT_NE(R0, R1); + EXPECT_GE(R0->getNumOperands(), 1U); + EXPECT_GE(R1->getNumOperands(), 1U); + EXPECT_EQ(R0->getOperand(0), R0); + EXPECT_EQ(R1->getOperand(0), R1); + EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0); + EXPECT_TRUE(R1->getNumOperands() == 1 || R1->getOperand(1) == 0); +} +TEST_F(MDBuilderTest, createTBAARoot) { + MDBuilder MDHelper(Context); + MDNode *R0 = MDHelper.createTBAARoot("Root"); + MDNode *R1 = MDHelper.createTBAARoot("Root"); + EXPECT_EQ(R0, R1); + EXPECT_GE(R0->getNumOperands(), 1U); + EXPECT_TRUE(isa(R0->getOperand(0))); + EXPECT_EQ(cast(R0->getOperand(0))->getString(), "Root"); + EXPECT_TRUE(R0->getNumOperands() == 1 || R0->getOperand(1) == 0); +} +TEST_F(MDBuilderTest, createTBAANode) { + MDBuilder MDHelper(Context); + MDNode *R = MDHelper.createTBAARoot("Root"); + MDNode *N0 = MDHelper.createTBAANode("Node", R); + MDNode *N1 = MDHelper.createTBAANode("edoN", R); + MDNode *N2 = MDHelper.createTBAANode("Node", R, true); + MDNode *N3 = MDHelper.createTBAANode("Node", R); + EXPECT_EQ(N0, N3); + EXPECT_NE(N0, N1); + EXPECT_NE(N0, N2); + EXPECT_GE(N0->getNumOperands(), 2U); + EXPECT_GE(N1->getNumOperands(), 2U); + EXPECT_GE(N2->getNumOperands(), 3U); + EXPECT_TRUE(isa(N0->getOperand(0))); + EXPECT_TRUE(isa(N1->getOperand(0))); + EXPECT_TRUE(isa(N2->getOperand(0))); + EXPECT_EQ(cast(N0->getOperand(0))->getString(), "Node"); + EXPECT_EQ(cast(N1->getOperand(0))->getString(), "edoN"); + EXPECT_EQ(cast(N2->getOperand(0))->getString(), "Node"); + EXPECT_EQ(N0->getOperand(1), R); + EXPECT_EQ(N1->getOperand(1), R); + EXPECT_EQ(N2->getOperand(1), R); + EXPECT_TRUE(isa(N2->getOperand(2))); + EXPECT_EQ(cast(N2->getOperand(2))->getZExtValue(), 1U); +} +} -- cgit v1.1