Lang Hames | d435ce4 | 2018-09-30 19:12:23 +0000 | [diff] [blame] | 1 | //===----- JITTargetMachineBuilder.cpp - Build TargetMachines for JIT -----===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Lang Hames | d435ce4 | 2018-09-30 19:12:23 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" |
| 10 | |
| 11 | #include "llvm/Support/TargetRegistry.h" |
| 12 | |
| 13 | namespace llvm { |
| 14 | namespace orc { |
| 15 | |
| 16 | JITTargetMachineBuilder::JITTargetMachineBuilder(Triple TT) |
| 17 | : TT(std::move(TT)) { |
| 18 | Options.EmulatedTLS = true; |
| 19 | Options.ExplicitEmulatedTLS = true; |
| 20 | } |
| 21 | |
| 22 | Expected<JITTargetMachineBuilder> JITTargetMachineBuilder::detectHost() { |
| 23 | // FIXME: getProcessTriple is bogus. It returns the host LLVM was compiled on, |
| 24 | // rather than a valid triple for the current process. |
| 25 | return JITTargetMachineBuilder(Triple(sys::getProcessTriple())); |
| 26 | } |
| 27 | |
| 28 | Expected<std::unique_ptr<TargetMachine>> |
| 29 | JITTargetMachineBuilder::createTargetMachine() { |
| 30 | |
| 31 | std::string ErrMsg; |
| 32 | auto *TheTarget = TargetRegistry::lookupTarget(TT.getTriple(), ErrMsg); |
| 33 | if (!TheTarget) |
| 34 | return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()); |
| 35 | |
| 36 | auto *TM = |
| 37 | TheTarget->createTargetMachine(TT.getTriple(), CPU, Features.getString(), |
| 38 | Options, RM, CM, OptLevel, /*JIT*/ true); |
| 39 | if (!TM) |
| 40 | return make_error<StringError>("Could not allocate target machine", |
| 41 | inconvertibleErrorCode()); |
| 42 | |
| 43 | return std::unique_ptr<TargetMachine>(TM); |
| 44 | } |
| 45 | |
| 46 | JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures( |
| 47 | const std::vector<std::string> &FeatureVec) { |
| 48 | for (const auto &F : FeatureVec) |
| 49 | Features.AddFeature(F); |
| 50 | return *this; |
| 51 | } |
| 52 | |
| 53 | } // End namespace orc. |
| 54 | } // End namespace llvm. |