brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 27f8855 Raw
74 lines · cpp
1//===-- llvm/unittests/Target/TargetMachineOptionsTest.cpp ----------2//-----===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9///10/// \file11/// This file contains unit tests for the opaque structure describing options12/// for TargetMachine creation via the C API.13///14//===----------------------------------------------------------------------===//15 16#include "llvm-c/Core.h"17#include "llvm-c/TargetMachine.h"18#include "llvm/Config/llvm-config.h"19#include "gtest/gtest.h"20 21namespace llvm {22 23TEST(TargetMachineCTest, TargetMachineOptions) {24  auto *Options = LLVMCreateTargetMachineOptions();25 26  LLVMTargetMachineOptionsSetCPU(Options, "cortex-a53");27  LLVMTargetMachineOptionsSetFeatures(Options, "+neon");28  LLVMTargetMachineOptionsSetABI(Options, "aapcs");29  LLVMTargetMachineOptionsSetCodeGenOptLevel(Options, LLVMCodeGenLevelNone);30  LLVMTargetMachineOptionsSetRelocMode(Options, LLVMRelocStatic);31  LLVMTargetMachineOptionsSetCodeModel(Options, LLVMCodeModelKernel);32 33  LLVMDisposeTargetMachineOptions(Options);34}35 36TEST(TargetMachineCTest, TargetMachineCreation) {37  LLVMInitializeAllTargets();38  LLVMInitializeAllTargetInfos();39  LLVMInitializeAllTargetMCs();40 41  // Get the default target to keep the test as generic as possible. This may42  // not be a target for which we can generate code; in that case we give up.43 44  auto *Triple = LLVMGetDefaultTargetTriple();45  if (strlen(Triple) == 0) {46    LLVMDisposeMessage(Triple);47    GTEST_SKIP();48  }49 50  LLVMTargetRef Target = nullptr;51  char *Error = nullptr;52  if (LLVMGetTargetFromTriple(Triple, &Target, &Error))53    FAIL() << "Failed to create target from default triple (" << Triple54           << "): " << Error;55 56  ASSERT_NE(Target, nullptr);57 58  if (!LLVMTargetHasTargetMachine(Target))59    GTEST_SKIP() << "Default target doesn't support code generation";60 61  // We don't know which target we're creating a machine for, so don't set any62  // non-default options; they might cause fatal errors.63 64  auto *Options = LLVMCreateTargetMachineOptions();65  auto *TM = LLVMCreateTargetMachineWithOptions(Target, Triple, Options);66  ASSERT_NE(TM, nullptr);67 68  LLVMDisposeMessage(Triple);69  LLVMDisposeTargetMachineOptions(Options);70  LLVMDisposeTargetMachine(TM);71}72 73} // namespace llvm74