52 lines · cpp
1//===----------- CoreAPIsTest.cpp - Unit tests for Core ORC APIs ----------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"10#include "OrcTestCommon.h"11 12using namespace llvm;13using namespace llvm::orc;14 15namespace {16 17TEST(ExecutionUtilsTest, JITTargetMachineBuilder) {18 // Tests basic API usage.19 // Bails out on error, as it is valid to run this test without any targets20 // built.21 22 // Make sure LLVM has been initialized.23 OrcNativeTarget::initialize();24 25 auto JTMB = cantFail(JITTargetMachineBuilder::detectHost());26 27 // Test API by performing a bunch of no-ops.28 JTMB.setCPU("");29 JTMB.setRelocationModel(std::nullopt);30 JTMB.setCodeModel(std::nullopt);31 JTMB.setCodeGenOptLevel(CodeGenOptLevel::None);32 JTMB.addFeatures(std::vector<std::string>());33 SubtargetFeatures &STF = JTMB.getFeatures();34 (void)STF;35 TargetOptions &TO = JTMB.getOptions();36 (void)TO;37 Triple &TT = JTMB.getTargetTriple();38 (void)TT;39 40 auto TM = JTMB.createTargetMachine();41 42 if (!TM)43 consumeError(TM.takeError());44 else {45 EXPECT_NE(TM.get(), nullptr)46 << "JITTargetMachineBuilder should return a non-null TargetMachine "47 "on success";48 }49}50 51} // namespace52