aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/Transforms
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2015-03-23 12:10:34 -0700
committerStephen Hines <srhines@google.com>2015-03-23 12:10:34 -0700
commitebe69fe11e48d322045d5949c83283927a0d790b (patch)
treec92f1907a6b8006628a4b01615f38264d29834ea /unittests/Transforms
parentb7d2e72b02a4cb8034f32f8247a2558d2434e121 (diff)
downloadexternal_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.zip
external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.gz
external_llvm-ebe69fe11e48d322045d5949c83283927a0d790b.tar.bz2
Update aosp/master LLVM for rebase to r230699.
Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9
Diffstat (limited to 'unittests/Transforms')
-rw-r--r--unittests/Transforms/CMakeLists.txt2
-rw-r--r--unittests/Transforms/DebugIR/CMakeLists.txt9
-rw-r--r--unittests/Transforms/DebugIR/DebugIR.cpp308
-rw-r--r--unittests/Transforms/IPO/CMakeLists.txt9
-rw-r--r--unittests/Transforms/IPO/LowerBitSets.cpp95
-rw-r--r--unittests/Transforms/IPO/Makefile (renamed from unittests/Transforms/DebugIR/Makefile)6
-rw-r--r--unittests/Transforms/Makefile2
-rw-r--r--unittests/Transforms/Utils/Cloning.cpp5
8 files changed, 111 insertions, 325 deletions
diff --git a/unittests/Transforms/CMakeLists.txt b/unittests/Transforms/CMakeLists.txt
index 8ec56f1..5d3b29c 100644
--- a/unittests/Transforms/CMakeLists.txt
+++ b/unittests/Transforms/CMakeLists.txt
@@ -1,2 +1,2 @@
-add_subdirectory(DebugIR)
+add_subdirectory(IPO)
add_subdirectory(Utils)
diff --git a/unittests/Transforms/DebugIR/CMakeLists.txt b/unittests/Transforms/DebugIR/CMakeLists.txt
deleted file mode 100644
index 88734d2..0000000
--- a/unittests/Transforms/DebugIR/CMakeLists.txt
+++ /dev/null
@@ -1,9 +0,0 @@
-set(LLVM_LINK_COMPONENTS
- Core
- Instrumentation
- Support
- )
-
-add_llvm_unittest(DebugIRTests
- DebugIR.cpp
- )
diff --git a/unittests/Transforms/DebugIR/DebugIR.cpp b/unittests/Transforms/DebugIR/DebugIR.cpp
deleted file mode 100644
index 41df147..0000000
--- a/unittests/Transforms/DebugIR/DebugIR.cpp
+++ /dev/null
@@ -1,308 +0,0 @@
-//===- DebugIR.cpp - Unit tests for the DebugIR pass ----------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// The tests in this file verify the DebugIR pass that generates debug metadata
-// for LLVM IR.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/Triple.h"
-#include "../lib/Transforms/Instrumentation/DebugIR.h"
-#include "llvm/Config/config.h"
-#include "llvm/IR/DIBuilder.h"
-#include "llvm/IR/DebugInfo.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Support/Errc.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Host.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Transforms/Instrumentation.h"
-
-// These tests do not depend on MCJIT, but we use the TrivialModuleBuilder
-// helper class to construct some trivial Modules.
-#include "../unittests/ExecutionEngine/MCJIT/MCJITTestBase.h"
-
-#include <string>
-
-#include "gtest/gtest.h"
-
-#if defined(LLVM_ON_WIN32)
-#include <direct.h>
-#define getcwd_impl _getcwd
-#elif defined (HAVE_GETCWD)
-#include <unistd.h>
-#define getcwd_impl getcwd
-#endif // LLVM_ON_WIN32
-
-using namespace llvm;
-using namespace std;
-
-namespace {
-
-/// Insert a mock CUDescriptor with the specified producer
-void insertCUDescriptor(Module *M, StringRef File, StringRef Dir,
- StringRef Producer) {
- DIBuilder B(*M);
- B.createCompileUnit(dwarf::DW_LANG_C99, File, Dir, Producer, false, "", 0);
- B.finalize();
-}
-
-/// Attempts to remove file at Path and returns true if it existed, or false if
-/// it did not.
-bool removeIfExists(StringRef Path) {
- // This is an approximation, on error we don't know in general if the file
- // existed or not.
- std::error_code EC = sys::fs::remove(Path, false);
- return EC != llvm::errc::no_such_file_or_directory;
-}
-
-char * current_dir() {
-#if defined(LLVM_ON_WIN32) || defined(HAVE_GETCWD)
- // calling getcwd (or _getcwd() on windows) with a null buffer makes it
- // allocate a sufficiently sized buffer to store the current working dir.
- return getcwd_impl(nullptr, 0);
-#else
- return 0;
-#endif
-}
-
-class TestDebugIR : public ::testing::Test, public TrivialModuleBuilder {
-protected:
- TestDebugIR()
- : TrivialModuleBuilder(sys::getProcessTriple())
- , cwd(current_dir()) {}
-
- ~TestDebugIR() { free(cwd); }
-
- /// Returns a concatenated path string consisting of Dir and Filename
- string getPath(const string &Dir, const string &Filename) {
- SmallVector<char, 8> Path;
- sys::path::append(Path, Dir, Filename);
- Path.resize(Dir.size() + Filename.size() + 2);
- Path[Dir.size() + Filename.size() + 1] = '\0';
- return string(Path.data());
- }
-
- LLVMContext Context;
- char *cwd;
- std::unique_ptr<Module> M;
- std::unique_ptr<DebugIR> D;
-};
-
-// Test empty named Module that is not supposed to be output to disk.
-TEST_F(TestDebugIR, EmptyNamedModuleNoWrite) {
- string Dir = "MadeUpDirectory";
- string File = "empty_module.ll";
- string Path(getPath(Dir, File));
-
- M.reset(createEmptyModule(Path));
-
- // constructing DebugIR with no args should not result in any file generated.
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass()));
- D->runOnModule(*M);
-
- // verify DebugIR did not generate a file
- ASSERT_FALSE(removeIfExists(Path)) << "Unexpected file " << Path;
-}
-
-// Test a non-empty unnamed module that is output to an autogenerated file name.
-TEST_F(TestDebugIR, NonEmptyUnnamedModuleWriteToAutogeneratedFile) {
- M.reset(createEmptyModule());
- insertAddFunction(M.get());
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass(true, true)));
-
- string Path;
- D->runOnModule(*M, Path);
-
- // verify DebugIR generated a file, and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-}
-
-// Test not specifying a name in the module -- DebugIR should generate a name
-// and write the file contents.
-TEST_F(TestDebugIR, EmptyModuleWriteAnonymousFile) {
- M.reset(createEmptyModule());
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass(false, false)));
-
- string Path;
- D->runOnModule(*M, Path);
-
- // verify DebugIR generated a file and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-}
-
-#ifdef HAVE_GETCWD // These tests require get_current_dir_name()
-
-// Test empty named Module that is to be output to path specified at Module
-// construction.
-TEST_F(TestDebugIR, EmptyNamedModuleWriteFile) {
- string Filename("NamedFile1");
- string ExpectedPath(getPath(cwd, Filename));
-
- M.reset(createEmptyModule(ExpectedPath));
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass(true, true)));
-
- string Path;
- D->runOnModule(*M, Path);
-
- // verify DebugIR was able to correctly parse the file name from module ID
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR generated a file, and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-}
-
-// Test an empty unnamed module generates an output file whose path is specified
-// at DebugIR construction.
-TEST_F(TestDebugIR, EmptyUnnamedModuleWriteNamedFile) {
- string Filename("NamedFile2");
-
- M.reset(createEmptyModule());
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass(
- false, false, StringRef(cwd), StringRef(Filename))));
- string Path;
- D->runOnModule(*M, Path);
-
- string ExpectedPath(getPath(cwd, Filename));
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR generated a file, and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-}
-
-// Test an empty named module generates an output file at the path specified
-// during DebugIR construction.
-TEST_F(TestDebugIR, EmptyNamedModuleWriteNamedFile) {
- string Filename("NamedFile3");
-
- string UnexpectedPath(getPath(cwd, "UnexpectedFilename"));
- M.reset(createEmptyModule(UnexpectedPath));
-
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass(
- false, false, StringRef(cwd), StringRef(Filename))));
- string Path;
- D->runOnModule(*M, Path);
-
- string ExpectedPath(getPath(cwd, Filename));
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR generated a file, and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-
- // verify DebugIR did not generate a file at the path specified at Module
- // construction.
- ASSERT_FALSE(removeIfExists(UnexpectedPath)) << "Unexpected file " << Path;
-}
-
-// Test a non-empty named module that is not supposed to be output to disk
-TEST_F(TestDebugIR, NonEmptyNamedModuleNoWrite) {
- string Filename("NamedFile4");
- string ExpectedPath(getPath(cwd, Filename));
-
- M.reset(createEmptyModule(ExpectedPath));
- insertAddFunction(M.get());
-
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass()));
-
- string Path;
- D->runOnModule(*M, Path);
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR did not generate a file
- ASSERT_FALSE(removeIfExists(Path)) << "Unexpected file " << Path;
-}
-
-// Test a non-empty named module that is output to disk.
-TEST_F(TestDebugIR, NonEmptyNamedModuleWriteFile) {
- string Filename("NamedFile5");
- string ExpectedPath(getPath(cwd, Filename));
-
- M.reset(createEmptyModule(ExpectedPath));
- insertAddFunction(M.get());
-
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass(true, true)));
-
- string Path;
- D->runOnModule(*M, Path);
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR generated a file, and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-}
-
-// Test a non-empty unnamed module is output to a path specified at DebugIR
-// construction.
-TEST_F(TestDebugIR, NonEmptyUnnamedModuleWriteToNamedFile) {
- string Filename("NamedFile6");
-
- M.reset(createEmptyModule());
- insertAddFunction(M.get());
-
- D.reset(static_cast<DebugIR *>(
- llvm::createDebugIRPass(true, true, cwd, Filename)));
- string Path;
- D->runOnModule(*M, Path);
-
- string ExpectedPath(getPath(cwd, Filename));
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR generated a file, and clean it up
- ASSERT_TRUE(removeIfExists(Path)) << "Missing expected file at " << Path;
-}
-
-// Test that information inside existing debug metadata is retained
-TEST_F(TestDebugIR, ExistingMetadataRetained) {
- string Filename("NamedFile7");
- string ExpectedPath(getPath(cwd, Filename));
-
- M.reset(createEmptyModule(ExpectedPath));
- insertAddFunction(M.get());
-
- StringRef Producer("TestProducer");
- insertCUDescriptor(M.get(), Filename, cwd, Producer);
-
- DebugInfoFinder Finder;
- Finder.processModule(*M);
- ASSERT_EQ((unsigned)1, Finder.compile_unit_count());
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass()));
-
- string Path;
- D->runOnModule(*M, Path);
- ASSERT_EQ(ExpectedPath, Path);
-
- // verify DebugIR did not generate a file
- ASSERT_FALSE(removeIfExists(Path)) << "Unexpected file " << Path;
-
- DICompileUnit CU(*Finder.compile_units().begin());
-
- // Verify original CU information is retained
- ASSERT_EQ(Filename, CU.getFilename());
- ASSERT_EQ(cwd, CU.getDirectory());
- ASSERT_EQ(Producer, CU.getProducer());
-}
-
-#endif // HAVE_GETCWD
-
-#ifdef GTEST_HAS_DEATH_TEST
-
-// Test a non-empty unnamed module that is not supposed to be output to disk
-// NOTE: this test is expected to die with LLVM_ERROR, and such depends on
-// google test's "death test" mode.
-TEST_F(TestDebugIR, NonEmptyUnnamedModuleNoWrite) {
- M.reset(createEmptyModule(StringRef()));
- insertAddFunction(M.get());
- D.reset(static_cast<DebugIR *>(llvm::createDebugIRPass()));
-
- // No name in module or on DebugIR construction ==> DebugIR should assert
- EXPECT_DEATH(D->runOnModule(*M),
- "DebugIR unable to determine file name in input.");
-}
-
-#endif // GTEST_HAS_DEATH_TEST
-}
diff --git a/unittests/Transforms/IPO/CMakeLists.txt b/unittests/Transforms/IPO/CMakeLists.txt
new file mode 100644
index 0000000..58b71b2
--- /dev/null
+++ b/unittests/Transforms/IPO/CMakeLists.txt
@@ -0,0 +1,9 @@
+set(LLVM_LINK_COMPONENTS
+ Core
+ Support
+ IPO
+ )
+
+add_llvm_unittest(IPOTests
+ LowerBitSets.cpp
+ )
diff --git a/unittests/Transforms/IPO/LowerBitSets.cpp b/unittests/Transforms/IPO/LowerBitSets.cpp
new file mode 100644
index 0000000..26a4252
--- /dev/null
+++ b/unittests/Transforms/IPO/LowerBitSets.cpp
@@ -0,0 +1,95 @@
+//===- LowerBitSets.cpp - Unit tests for bitset lowering ------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/IPO/LowerBitSets.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+TEST(LowerBitSets, BitSetBuilder) {
+ struct {
+ std::vector<uint64_t> Offsets;
+ std::vector<uint8_t> Bits;
+ uint64_t ByteOffset;
+ uint64_t BitSize;
+ unsigned AlignLog2;
+ bool IsSingleOffset;
+ bool IsAllOnes;
+ } BSBTests[] = {
+ {{}, {0}, 0, 1, 0, false, false},
+ {{0}, {1}, 0, 1, 0, true, true},
+ {{4}, {1}, 4, 1, 0, true, true},
+ {{37}, {1}, 37, 1, 0, true, true},
+ {{0, 1}, {3}, 0, 2, 0, false, true},
+ {{0, 4}, {3}, 0, 2, 2, false, true},
+ {{0, uint64_t(1) << 33}, {3}, 0, 2, 33, false, true},
+ {{3, 7}, {3}, 3, 2, 2, false, true},
+ {{0, 1, 7}, {131}, 0, 8, 0, false, false},
+ {{0, 2, 14}, {131}, 0, 8, 1, false, false},
+ {{0, 1, 8}, {3, 1}, 0, 9, 0, false, false},
+ {{0, 2, 16}, {3, 1}, 0, 9, 1, false, false},
+ {{0, 1, 2, 3, 4, 5, 6, 7}, {255}, 0, 8, 0, false, true},
+ {{0, 1, 2, 3, 4, 5, 6, 7, 8}, {255, 1}, 0, 9, 0, false, true},
+ };
+
+ for (auto &&T : BSBTests) {
+ BitSetBuilder BSB;
+ for (auto Offset : T.Offsets)
+ BSB.addOffset(Offset);
+
+ BitSetInfo BSI = BSB.build();
+
+ EXPECT_EQ(T.Bits, BSI.Bits);
+ EXPECT_EQ(T.ByteOffset, BSI.ByteOffset);
+ EXPECT_EQ(T.BitSize, BSI.BitSize);
+ EXPECT_EQ(T.AlignLog2, BSI.AlignLog2);
+ EXPECT_EQ(T.IsSingleOffset, BSI.isSingleOffset());
+ EXPECT_EQ(T.IsAllOnes, BSI.isAllOnes());
+
+ for (auto Offset : T.Offsets)
+ EXPECT_TRUE(BSI.containsGlobalOffset(Offset));
+
+ auto I = T.Offsets.begin();
+ for (uint64_t NonOffset = 0; NonOffset != 256; ++NonOffset) {
+ if (I != T.Offsets.end() && *I == NonOffset) {
+ ++I;
+ continue;
+ }
+
+ EXPECT_FALSE(BSI.containsGlobalOffset(NonOffset));
+ }
+ }
+}
+
+TEST(LowerBitSets, GlobalLayoutBuilder) {
+ struct {
+ uint64_t NumObjects;
+ std::vector<std::set<uint64_t>> Fragments;
+ std::vector<uint64_t> WantLayout;
+ } GLBTests[] = {
+ {0, {}, {}},
+ {4, {{0, 1}, {2, 3}}, {0, 1, 2, 3}},
+ {3, {{0, 1}, {1, 2}}, {0, 1, 2}},
+ {4, {{0, 1}, {1, 2}, {2, 3}}, {0, 1, 2, 3}},
+ {4, {{0, 1}, {2, 3}, {1, 2}}, {0, 1, 2, 3}},
+ {6, {{2, 5}, {0, 1, 2, 3, 4, 5}}, {0, 1, 2, 5, 3, 4}},
+ };
+
+ for (auto &&T : GLBTests) {
+ GlobalLayoutBuilder GLB(T.NumObjects);
+ for (auto &&F : T.Fragments)
+ GLB.addFragment(F);
+
+ std::vector<uint64_t> ComputedLayout;
+ for (auto &&F : GLB.Fragments)
+ ComputedLayout.insert(ComputedLayout.end(), F.begin(), F.end());
+
+ EXPECT_EQ(T.WantLayout, ComputedLayout);
+ }
+}
diff --git a/unittests/Transforms/DebugIR/Makefile b/unittests/Transforms/IPO/Makefile
index 9ace8c3..f807879 100644
--- a/unittests/Transforms/DebugIR/Makefile
+++ b/unittests/Transforms/IPO/Makefile
@@ -1,4 +1,4 @@
-##===- unittests/Transforms/Utils/Makefile -----------------*- Makefile -*-===##
+##===- unittests/Transforms/IPO/Makefile -------------------*- Makefile -*-===##
#
# The LLVM Compiler Infrastructure
#
@@ -8,8 +8,8 @@
##===----------------------------------------------------------------------===##
LEVEL = ../../..
-TESTNAME = DebugIR
-LINK_COMPONENTS := Instrumentation
+TESTNAME = IPO
+LINK_COMPONENTS := IPO
include $(LEVEL)/Makefile.config
include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
diff --git a/unittests/Transforms/Makefile b/unittests/Transforms/Makefile
index d5cca39..3a2cdfc 100644
--- a/unittests/Transforms/Makefile
+++ b/unittests/Transforms/Makefile
@@ -9,7 +9,7 @@
LEVEL = ../..
-PARALLEL_DIRS = DebugIR Utils
+PARALLEL_DIRS = IPO Utils
include $(LEVEL)/Makefile.common
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
index c779979..1d22d5b 100644
--- a/unittests/Transforms/Utils/Cloning.cpp
+++ b/unittests/Transforms/Utils/Cloning.cpp
@@ -13,16 +13,15 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Constant.h"
-#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DIBuilder.h"
+#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Module.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
#include "gtest/gtest.h"
using namespace llvm;