[ORC] Extract and tidy up JITTargetMachineBuilder, add unit test.
(1) Adds comments for the API.
(2) Removes the setArch method: This is redundant: the setArchStr method on the
triple should be used instead.
(3) Turns EmulatedTLS on by default. This matches EngineBuilder's behavior.
llvm-svn: 343423
diff --git a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
index 3a47bfa..8b0d5fc 100644
--- a/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
+++ b/llvm/unittests/ExecutionEngine/Orc/CMakeLists.txt
@@ -14,6 +14,7 @@
CoreAPIsTest.cpp
IndirectionUtilsTest.cpp
GlobalMappingLayerTest.cpp
+ JITTargetMachineBuilderTest.cpp
LazyCallThroughAndReexportsTest.cpp
LazyEmittingLayerTest.cpp
LegacyAPIInteropTest.cpp
diff --git a/llvm/unittests/ExecutionEngine/Orc/JITTargetMachineBuilderTest.cpp b/llvm/unittests/ExecutionEngine/Orc/JITTargetMachineBuilderTest.cpp
new file mode 100644
index 0000000..f978a90
--- /dev/null
+++ b/llvm/unittests/ExecutionEngine/Orc/JITTargetMachineBuilderTest.cpp
@@ -0,0 +1,52 @@
+//===----------- CoreAPIsTest.cpp - Unit tests for Core ORC APIs ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
+#include "OrcTestCommon.h"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+namespace {
+
+TEST(ExecutionUtilsTest, JITTargetMachineBuilder) {
+ // Tests basic API usage.
+ // Bails out on error, as it is valid to run this test without any targets
+ // built.
+
+ // Make sure LLVM has been initialized.
+ OrcNativeTarget::initialize();
+
+ auto JTMB = cantFail(JITTargetMachineBuilder::detectHost());
+
+ // Test API by performing a bunch of no-ops.
+ JTMB.setCPU("");
+ JTMB.setRelocationModel(None);
+ JTMB.setCodeModel(None);
+ JTMB.setCodeGenOptLevel(CodeGenOpt::None);
+ JTMB.addFeatures(std::vector<std::string>());
+ SubtargetFeatures &STF = JTMB.getFeatures();
+ (void)STF;
+ TargetOptions &TO = JTMB.getOptions();
+ (void)TO;
+ Triple &TT = JTMB.getTargetTriple();
+ (void)TT;
+
+ auto TM = JTMB.createTargetMachine();
+
+ if (!TM)
+ consumeError(TM.takeError());
+ else {
+ EXPECT_NE(TM.get(), nullptr)
+ << "JITTargetMachineBuilder should return a non-null TargetMachine "
+ "on success";
+ }
+}
+
+} // namespace
diff --git a/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp
index 7caaa76..c3c5703 100644
--- a/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp
@@ -1,5 +1,5 @@
#include "OrcTestCommon.h"
-#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
+#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LazyReexports.h"
#include "gtest/gtest.h"