|
| 1 | +//===--- NativeCPU.cpp - Implement NativeCPU target feature support -------===// |
| 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 | +// |
| 9 | +// This file implements NativeCPU TargetInfo objects. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "NativeCPU.h" |
| 14 | +#include <llvm/TargetParser/Host.h> |
| 15 | + |
| 16 | +using namespace clang; |
| 17 | +using namespace clang::targets; |
| 18 | + |
| 19 | +static const LangASMap NativeCPUASMap = { |
| 20 | + 0, // Default |
| 21 | + 1, // opencl_global |
| 22 | + 3, // opencl_local |
| 23 | + 4, // opencl_constant |
| 24 | + 0, // opencl_private |
| 25 | + 0, // opencl_generic |
| 26 | + 1, // opencl_global_device |
| 27 | + 1, // opencl_global_host |
| 28 | + 1, // cuda_device |
| 29 | + 4, // cuda_constant |
| 30 | + 3, // cuda_shared |
| 31 | + 1, // sycl_global |
| 32 | + 1, // sycl_global_device |
| 33 | + 1, // sycl_global_host |
| 34 | + 3, // sycl_local |
| 35 | + 0, // sycl_private |
| 36 | + 0, // ptr32_sptr |
| 37 | + 0, // ptr32_uptr |
| 38 | + 0, // ptr64 |
| 39 | + 0, // hlsl_groupshared |
| 40 | + 0, // hlsl_constant |
| 41 | + 20, // wasm_funcref |
| 42 | +}; |
| 43 | + |
| 44 | +NativeCPUTargetInfo::NativeCPUTargetInfo(const llvm::Triple &, |
| 45 | + const TargetOptions &Opts) |
| 46 | + : TargetInfo(llvm::Triple()) { |
| 47 | + AddrSpaceMap = &NativeCPUASMap; |
| 48 | + UseAddrSpaceMapMangling = true; |
| 49 | + HasLegalHalfType = true; |
| 50 | + HasFloat16 = true; |
| 51 | + resetDataLayout("e"); |
| 52 | + |
| 53 | + llvm::Triple HostTriple([&] { |
| 54 | + // Take the default target triple if no other host triple is specified so |
| 55 | + // that system headers work. |
| 56 | + if (Opts.HostTriple.empty()) |
| 57 | + return llvm::sys::getDefaultTargetTriple(); |
| 58 | + |
| 59 | + return Opts.HostTriple; |
| 60 | + }()); |
| 61 | + if (HostTriple.getArch() != llvm::Triple::UnknownArch) { |
| 62 | + HostTarget = AllocateTarget(HostTriple, Opts); |
| 63 | + |
| 64 | + // Copy properties from host target. |
| 65 | + BoolWidth = HostTarget->getBoolWidth(); |
| 66 | + BoolAlign = HostTarget->getBoolAlign(); |
| 67 | + IntWidth = HostTarget->getIntWidth(); |
| 68 | + IntAlign = HostTarget->getIntAlign(); |
| 69 | + HalfWidth = HostTarget->getHalfWidth(); |
| 70 | + HalfAlign = HostTarget->getHalfAlign(); |
| 71 | + FloatWidth = HostTarget->getFloatWidth(); |
| 72 | + FloatAlign = HostTarget->getFloatAlign(); |
| 73 | + DoubleWidth = HostTarget->getDoubleWidth(); |
| 74 | + DoubleAlign = HostTarget->getDoubleAlign(); |
| 75 | + LongWidth = HostTarget->getLongWidth(); |
| 76 | + LongAlign = HostTarget->getLongAlign(); |
| 77 | + LongLongWidth = HostTarget->getLongLongWidth(); |
| 78 | + LongLongAlign = HostTarget->getLongLongAlign(); |
| 79 | + PointerWidth = HostTarget->getPointerWidth(LangAS::Default); |
| 80 | + PointerAlign = HostTarget->getPointerAlign(LangAS::Default); |
| 81 | + MinGlobalAlign = HostTarget->getMinGlobalAlign(/*TypeSize=*/0, |
| 82 | + /*HasNonWeakDef=*/true); |
| 83 | + NewAlign = HostTarget->getNewAlign(); |
| 84 | + DefaultAlignForAttributeAligned = |
| 85 | + HostTarget->getDefaultAlignForAttributeAligned(); |
| 86 | + SizeType = HostTarget->getSizeType(); |
| 87 | + PtrDiffType = HostTarget->getPtrDiffType(LangAS::Default); |
| 88 | + IntMaxType = HostTarget->getIntMaxType(); |
| 89 | + WCharType = HostTarget->getWCharType(); |
| 90 | + WIntType = HostTarget->getWIntType(); |
| 91 | + Char16Type = HostTarget->getChar16Type(); |
| 92 | + Char32Type = HostTarget->getChar32Type(); |
| 93 | + Int64Type = HostTarget->getInt64Type(); |
| 94 | + SigAtomicType = HostTarget->getSigAtomicType(); |
| 95 | + ProcessIDType = HostTarget->getProcessIDType(); |
| 96 | + |
| 97 | + UseBitFieldTypeAlignment = HostTarget->useBitFieldTypeAlignment(); |
| 98 | + UseZeroLengthBitfieldAlignment = |
| 99 | + HostTarget->useZeroLengthBitfieldAlignment(); |
| 100 | + UseExplicitBitFieldAlignment = HostTarget->useExplicitBitFieldAlignment(); |
| 101 | + ZeroLengthBitfieldBoundary = HostTarget->getZeroLengthBitfieldBoundary(); |
| 102 | + |
| 103 | + // This is a bit of a lie, but it controls __GCC_ATOMIC_XXX_LOCK_FREE, and |
| 104 | + // we need those macros to be identical on host and device, because (among |
| 105 | + // other things) they affect which standard library classes are defined, |
| 106 | + // and we need all classes to be defined on both the host and device. |
| 107 | + MaxAtomicInlineWidth = HostTarget->getMaxAtomicInlineWidth(); |
| 108 | + } |
| 109 | +} |
0 commit comments