llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
Lang Hames 04756ee526 [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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@343423 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-30 19:12:23 +00:00

56 lines
1.8 KiB
C++

//===----- JITTargetMachineBuilder.cpp - Build TargetMachines for JIT -----===//
//
// 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 "llvm/Support/TargetRegistry.h"
namespace llvm {
namespace orc {
JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT)
: TT(std::move(TT)) {
Options.EmulatedTLS = true;
Options.ExplicitEmulatedTLS = true;
}
Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() {
// FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on,
// rather than a valid triple for the current process.
return JITTargetMachineBuilder(Triple(sys::getProcessTriple()));
}
Expected<std::unique_ptr<TargetMachine>>
JITTargetMachineBuilder::createTargetMachine() {
std::string ErrMsg;
auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg);
if (!TheTarget)
return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
auto *TM =
TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(),
Options, RM, CM, OptLevel, /*JIT*/ true);
if (!TM)
return make_error<StringError>("Could not allocate target machine",
inconvertibleErrorCode());
return std::unique_ptr<TargetMachine>(TM);
}
JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
const std::vector<std::string> &FeatureVec) {
for (const auto &F : FeatureVec)
Features.AddFeature(F);
return *this;
}
} // End namespace orc.
} // End namespace llvm.