JITTargetMachineBuilderTest.cpp 1.4 KB

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