aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/TargetInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
10 days[clang] Set correct CXXABI for UEFI (#150115)Prabhu Rajasekaran1-1/+1
The target triple x86_64-uefi must be assumed to have Microsft ABI by default. Fixes: https://github.com/llvm/llvm-project/issues/150113
2025-07-09[Clang] Respect MS layout attributes during CUDA/HIP device compilation ↵Yaxun (Sam) Liu1-1/+8
(#146620) This patch fixes an issue where Microsoft-specific layout attributes, such as __declspec(empty_bases), were ignored during CUDA/HIP device compilation on a Windows host. This caused a critical memory layout mismatch between host and device objects, breaking libraries that rely on these attributes for ABI compatibility. The fix introduces a centralized hasMicrosoftRecordLayout() check within the TargetInfo class. This check is aware of the auxiliary (host) target and is set during TargetInfo::adjust if the host uses a Microsoft ABI. The empty_bases, layout_version, and msvc::no_unique_address attributes now use this centralized flag, ensuring device code respects them and maintains layout consistency with the host. Fixes: https://github.com/llvm/llvm-project/issues/146047
2025-06-15[clang] Use StringRef in range-based for loops (NFC) (#144242)Kazu Hirata1-2/+1
When we iterate over std::vector<std::string>, we can directly assign each element to StringRef. We do not need to go through separate statements.
2025-06-04[HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (#138530)Nathan Gauër1-0/+2
This variable attribute is used in HLSL to add Vulkan specific builtins in a shader. The attribute is documented here: https://github.com/microsoft/hlsl-specs/blob/17727e88fd1cb09013cb3a144110826af05f4dd5/proposals/0011-inline-spirv.md Those variable, even if marked as `static` are externally initialized by the pipeline/driver/GPU. This is handled by moving them to a specific address space `hlsl_input`, also added by this commit. The design for input variables in Clang can be found here: https://github.com/llvm/wg-hlsl/blob/355771361ef69259fef39a65caef8bff9cb4046d/proposals/0019-spirv-input-builtin.md Co-authored-by: Justin Bogner <mail@justinbogner.com>
2025-06-02[AArch64] Add missing Neon Types (#126945)Tomas Matheson1-1/+1
The AAPCS64 adds a number of vector types to the C unconditionally: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#11appendix-support-for-advanced-simd-extensions The equivalent SVE types are already available in clang: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#12appendix-support-for-scalable-vectors __mfp8 is defined in the ACLE https://arm-software.github.io/acle/main/acle.html#data-types --------- Co-authored-by: David Green <david.green@arm.com>
2025-04-10[HLSL][SPIR-V] Add hlsl_private address space for SPIR-V (#133464)Nathan Gauër1-0/+2
This is an alternative to https://github.com/llvm/llvm-project/pull/122103 In SPIR-V, private global variables have the Private storage class. This PR adds a new address space which allows frontend to emit variable with this storage class when targeting this backend. This is covered in this proposal: llvm/wg-hlsl@4c9e11a This PR will cause addrspacecast to show up in several cases, like class member functions or assignment. Those will have to be handled in the backend later on, particularly to fixup pointer storage classes in some functions. Before this change, global variable were emitted with the 'Function' storage class, which was wrong.
2025-02-20[ARM,AArch64] Fix ABI bugs with over-sized bitfields (#126774)Oliver Stannard1-0/+1
This fixes two bugs in the ABI for over-sized bitfields for ARM and AArch64: The container type picked for an over-sized bitfield already contributes to the alignment of the structure, but it should also contribute to the "unadjusted alignment" which is used by the ARM and AArch64 PCS. AAPCS64 defines the bitfield layout algorithm for over-sized bitfields as picking a container which is the fundamental integer data type with the largest size less than or equal to the bit-field width. Since AAPCS64 has a 128-bit integer fundamental data type, we need to consider Int128 as a container type for AArch64.
2025-01-15[HLSL] Make bool in hlsl i32 (#122977)Sarah Spall1-0/+1
make a bool's memory representation i32 in hlsl add new test fix broken test Closes #122932
2024-12-02Revert "[SPIR-V] Fixup storage class for global private (#116636)" (#118312)Nathan Gauër1-1/+0
This reverts commit aa7fe1c10e5d6d0d3aacdb345fed995de413e142.
2024-12-02[SPIR-V] Fixup storage class for global private (#116636)Nathan Gauër1-0/+1
Adds a new address spaces: `hlsl_private`. Variables with such address space will be emitted with a `Private` storage class. This is useful for variables global to a SPIR-V module, since up to now, they were still emitted with a `Function` storage class, which is wrong. --------- Signed-off-by: Nathan Gauër <brioche@google.com>
2024-10-28Remove support for RenderScript (#112916)Aaron Ballman1-1/+0
See https://discourse.llvm.org/t/rfc-deprecate-and-eventually-remove-renderscript-support/81284 for the RFC
2024-10-21[clang][AVR] Fix basic type size/alignment values to match avr-gcc. (#111290)Alex Rønne Petersen1-0/+2
Closes #102172
2024-09-26[clang][RISCV] Introduce command line options for RISC-V Zicfilp CFIMing-Yi Lai1-0/+16
This patch enables the following command line flags for RISC-V targets: + `-fcf-protection=branch` turns on forward-edge control-flow integrity conditioning + `-mcf-branch-label-scheme=unlabeled|func-sig` selects the label scheme used in the forward-edge CFI conditioning
2024-07-11Revert "[NFC][Clang] Move functions of BranchProtectionInfo out of line" ↵Daniel Kiss1-22/+0
(#98437) Reverts llvm/llvm-project#98329
2024-07-11[NFC][Clang] Move functions of BranchProtectionInfo out of line (#98329)Daniel Kiss1-0/+22
Also let's add const to the setFnAttributes.
2024-05-02[HLSL] Cleanup TargetInfo handling (#90694)Chris B1-0/+10
We had some odd places where we set target behaviors. We were setting the long size in target-specific code, but it should be language-based. We were not setting the Half float type semantics correctly, and instead were overriding the query in the AST context. This change it moves existing code to the right places in the Target so that as we continue working on target and language feature they are controlled in the right places. It also fixes a bug where the size of `half` was computed incorrectly when native half types are not supported.
2024-03-29[clang] TargetInfo hook for unaligned bitfields (#65742)Nathan Sidwell1-0/+1
Promote ARM & AArch64's HasUnaligned to TargetInfo and set for all targets.
2024-03-15[AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (#65996)Ahmed Bougacha1-0/+4
This defines the basic set of pointer authentication clang builtins (provided in a new header, ptrauth.h), with diagnostics and IRGen support. The availability of the builtins is gated on a new flag, `-fptrauth-intrinsics`. Note that this only includes the basic intrinsics, and notably excludes `ptrauth_sign_constant`, `ptrauth_type_discriminator`, and `ptrauth_string_discriminator`, which need extra logic to be fully supported. This also introduces clang/docs/PointerAuthentication.rst, which describes the ptrauth model in general, in addition to these builtins. Co-Authored-By: Akira Hatanaka <ahatanaka@apple.com> Co-Authored-By: John McCall <rjmccall@apple.com>
2024-02-16Revert "[AArch64] Add soft-float ABI (#74460)" (#82032)Prabhuk1-1/+0
This reverts commit 9cc98e336980f00cbafcbed8841344e6ac472bdc. Issue: https://github.com/ClangBuiltLinux/linux/issues/1997
2024-02-15[AArch64] Add soft-float ABI (#74460)ostannard1-0/+1
This adds support for the AArch64 soft-float ABI. The specification for this ABI was added by https://github.com/ARM-software/abi-aa/pull/232. Because all existing AArch64 hardware has floating-point hardware, we expect this to be a niche option, only used for embedded systems on R-profile systems. We are going to document that SysV-like systems should only ever use the base (hard-float) PCS variant: https://github.com/ARM-software/abi-aa/pull/233. For that reason, I've not added an option to select the ABI independently of the FPU hardware, instead the new ABI is enabled iff the target architecture does not have an FPU. For testing, I have run this through an ABI fuzzer, but since this is the first implementation it can only test for internal consistency (callers and callees agree on the PCS), not for conformance to the ABI spec.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-5/+5
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-06-16Fix diag for read-only target featuresYaxun (Sam) Liu1-2/+0
Currently the diag is emitted even when there is no target feature specified on command line for OpenMP. This is because the function to initialize feature map is also used with cached feature string. The fix is to only diag when the feature map is initialized with feature strings from command line options. Reviewed by: Joseph Huber, Matt Arsenault, Johannes Doerfert Differential Revision: https://reviews.llvm.org/D153123
2023-06-14[HIP] emit macro `__HIP_NO_IMAGE_SUPPORT`Yaxun (Sam) Liu1-0/+2
HIP texture/image support is optional as some devices do not have image instructions. A macro __HIP_NO_IMAGE_SUPPORT is defined for device not supporting images (https://github.com/ROCm-Developer-Tools/HIP/blob/d0448aa4c4dd0f4b29ccf6a663b7f5ad9f5183e0/docs/reference/kernel_language.md?plain=1#L426 ) Currently the macro is defined by HIP header based on predefined macros for GPU, e.g __gfx*__ , which is error prone. This patch let clang emit the predefined macro. Reviewed by: Matt Arsenault, Artem Belevich Differential Revision: https://reviews.llvm.org/D151349
2023-05-27[Clang][BFloat16] Upgrade __bf16 to arithmetic type, change mangling, and ↵M. Zeeshan Siddiqui1-0/+1
extend excess precision support Pursuant to discussions at https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033/22, this commit enhances the handling of the __bf16 type in Clang. - Firstly, it upgrades __bf16 from a storage-only type to an arithmetic type. - Secondly, it changes the mangling of __bf16 to DF16b on all architectures except ARM. This change has been made in accordance with the finalization of the mangling for the std::bfloat16_t type, as discussed at https://github.com/itanium-cxx-abi/cxx-abi/pull/147. - Finally, this commit extends the existing excess precision support to the __bf16 type. This applies to hardware architectures that do not natively support bfloat16 arithmetic. Appropriate tests have been added to verify the effects of these changes and ensure no regressions in other areas of the compiler. Reviewed By: rjmccall, pengfei, zahiraam Differential Revision: https://reviews.llvm.org/D150913
2023-04-24Fix file info comment; NFCAaron Ballman1-1/+1
There is no TargetInfoImpl class any longer.
2023-03-20[LLVM][OHOS] Clang toolchain and targetsPavel Kosov1-1/+2
Add a clang part of OpenHarmony target Related LLVM part: D138202 ~~~ Huawei RRI, OS Lab Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D145227
2023-03-17[clang][WebAssembly] Initial support for reference type funcref in clangPaulo Matos1-0/+1
This is the funcref counterpart to 890146b. We introduce a new attribute that marks a function pointer as a funcref. It also implements builtin __builtin_wasm_ref_null_func(), that returns a null funcref value. Differential Revision: https://reviews.llvm.org/D128440
2023-03-14Revert "[LLVM][OHOS] Clang toolchain and targets"Daniel Thornburgh1-2/+1
This change had tests that break whenever LLVM_ENABLE_LINKER_BUILD_ID is set, as is the case in the Fuchsia target. This reverts commits: f81317a54586dbcef0c14cf512a0770e8ecaab3d 72474afa27570a0a1307f3260f0187b703aa6d84
2023-03-14[LLVM][OHOS] Clang toolchain and targetsPavel Kosov1-1/+2
Add a clang part of OpenHarmony target Related LLVM part: D138202 ~~~ Huawei RRI, OS Lab Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D145227
2023-02-10Move SIMD alignment calculation to LLVM FrontendDominik Adamski1-1/+0
Currently default simd alignment is defined by Clang specific TargetInfo class. This class cannot be reused for LLVM Flang. That's why default simd alignment calculation has been moved to OMPIRBuilder which is common for Flang and Clang. Previous attempt: https://reviews.llvm.org/D138496 was wrong because the default alignment depended on the number of built LLVM targets. If we wanted to calculate the default alignment for PPC and we hadn't specified PPC LLVM target to build, then we would get 0 as the alignment because OMPIRBuilder couldn't create PPCTargetMachine object and it returned 0 as the default value. If PPC LLVM target had been built earlier, then OMPIRBuilder could have created PPCTargetMachine object and it would have returned 128. Differential Revision: https://reviews.llvm.org/D141910 Reviewed By: jdoerfert
2023-02-07[NFC][TargetParser] Remove llvm/Support/TargetParser.hArchibald Elliott1-1/+1
2023-01-31Revert "[OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend"Argyrios Kyrtzidis1-0/+1
Causes clang build failures, see https://reviews.llvm.org/D141910#4089465 for details. This reverts commit ca446037af019d1aa01b1352a30a18df33038359.
2023-01-26[OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM FrontendDominik Adamski1-1/+0
Currently default simd alignment is defined by Clang specific TargetInfo class. This class cannot be reused for LLVM Flang. That's why default simd alignment calculation has been moved to OMPIRBuilder which is common for Flang and Clang. Previous attempt: https://reviews.llvm.org/D138496 was wrong because the default alignment depended on the number of built LLVM targets. If we wanted to calculate the default alignment for PPC and we hadn't specified PPC LLVM target to build, then we would get 0 as the alignment because OMPIRBuilder couldn't create PPCTargetMachine object and it returned 0 as the default value. If PPC LLVM target had been built earlier, then OMPIRBuilder could have created PPCTargetMachine object and it would have returned 128. Differential Revision: https://reviews.llvm.org/D141910 Reviewed By: jdoerfert
2023-01-13Revert "[OpenMP][OMPIRBuilder] Move SIMD alignment calculation to LLVM Frontend"Dominik Adamski1-0/+1
This reverts commit ed01de67433174d3157e9d239d59dd465d52c6a5.
2023-01-13[OpenMP][OMPIRBuilder] Move SIMD alignment calculation to LLVM FrontendDominik Adamski1-1/+0
Currently default simd alignment is specified by Clang specific TargetInfo class. This class cannot be reused for LLVM Flang. If we move the default alignment field into TargetMachine class then we can create TargetMachine objects and query them to find SIMD alignment. Scope of changes: 1) Added information about maximal allowed SIMD alignment to TargetMachine classes. 2) Removed getSimdDefaultAlign function from Clang TargetInfo class. 3) Refactored createTargetMachine function. Reviewed By: jsjodin Differential Revision: https://reviews.llvm.org/D138496
2022-12-20[Clang] Prepare for llvm::Optional becoming std::optional.Benjamin Kramer1-1/+1
The needed tweaks are mostly trivial, the one nasty bit is Clang's usage of OptionalStorage. To keep this working old Optional stays around as clang::CustomizableOptional, with the default Storage removed. Optional<File/DirectoryEntryRef> is replaced with a typedef. I tested this with GCC 7.5, the oldest supported GCC I had around. Differential Revision: https://reviews.llvm.org/D140332
2022-12-16[ASTContext] Avoid duplicating address space map. NFCIAlex Richardson1-0/+27
ASTContext was holding onto a pointer to the Clang->LLVM address space map which is stored inside TargetInfo. Instead of doing this, we can forward to TargetInfo instead. This change will allow us to eventually remove getTargetAddressSpace() from ASTContext and only have this information in TargetInfo. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138316
2022-12-01[clang] Avoid duplicating ProgramAddressSpace in TargetInfo. NFCIAlex Richardson1-2/+0
This value was added to clang/Basic in D111566, but is only used during codegen, where we can use the LLVM IR DataLayout instead. I noticed this because the downstream CHERI targets would have to also set this value for AArch64/RISC-V/MIPS. Instead of duplicating more information between LLVM IR and Clang, this patch moves getTargetAddressSpace(QualType T) to CodeGenTypes, where we can consult the DataLayout. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138296
2022-10-26Extend the C++03 definition of POD to include defaulted functionsDavid Blaikie1-0/+4
The AST/conditionally-trivial-smfs tests look a bit questionable, but are consistent with GCC's POD-ness, at least as far as packing is concerned: https://godbolt.org/z/36nqPMbKM (questionable because it looks like the type would be non-copyable, so how could it be pod? But the calling convention/pass by value seems to work correctly (local testing verifies that this behavior is preserved even with this patch: https://godbolt.org/z/3Pa89zsv6 )) Differential Revision: https://reviews.llvm.org/D119051
2022-10-01[Clang] Move ParsedTargetAttr to TargetInfo.hDavid Green1-1/+0
This moves the struct, as it is now parsed by TargetInfo, so avoiding some includes of AST in Basic.
2022-10-01[Clang][AArch64] Support AArch64 target(..) attribute formats.David Green1-0/+45
This adds support under AArch64 for the target("..") attributes. The current parsing is very X86-shaped, this patch attempts to bring it line with the GCC implementation from https://gcc.gnu.org/onlinedocs/gcc/AArch64-Function-Attributes.html#AArch64-Function-Attributes. The supported formats are: - "arch=<arch>" strings, that specify the architecture features for a function as per the -march=arch+feature option. - "cpu=<cpu>" strings, that specify the target-cpu and any implied atributes as per the -mcpu=cpu+feature option. - "tune=<cpu>" strings, that specify the tune-cpu cpu for a function as per -mtune. - "+<feature>", "+no<feature>" enables/disables the specific feature, for compatibility with GCC target attributes. - "<feature>", "no-<feature>" enabled/disables the specific feature, for backward compatibility with previous releases. To do this, the parsing of target attributes has been moved into TargetInfo to give the target the opportunity to override the existing parsing. The only non-aarch64 change should be a minor alteration to the error message, specifying using "CPU" to describe the cpu, not "architecture", and the DuplicateArch/Tune from ParsedTargetAttr have been combined into a single option. Differential Revision: https://reviews.llvm.org/D133848
2022-09-29[Clang][Arm] Convert -fallow-half-arguments-and-returns to a target option. NFCDavid Green1-0/+1
This cc1 option -fallow-half-arguments-and-returns allows __fp16 to be passed by argument and returned, without giving an error. It is currently always enabled for Arm and AArch64, by forcing the option in the driver. This means any cc1 tests (especially those needing arm_neon.h) need to specify the option too, to prevent the error from being emitted. This changes it to a target option instead, set to true for Arm and AArch64. This allows the option to be removed. Previously it was implied by -fnative_half_arguments_and_returns, which is set for certain languages like open_cl, renderscript and hlsl, so that option now too controls the errors. There were are few other non-arm uses of -fallow-half-arguments-and-returns but I believe they were unnecessary. The strictfp_builtins.c tests were converted from __fp16 to _Float16 to avoid the issues. Differential Revision: https://reviews.llvm.org/D133885
2022-09-25[Clang] Improve diagnostics about the invalid target feature.wangliushuai1-2/+7
Clang with debug builds will crash when run with empty target feature input. And the warning message is a little bit confusing. This patch adds an empty check and a new diagnostic to illustrate where goes wrong. Reviewed By: MaskRay, aaron.ballman Differential Revision: https://reviews.llvm.org/D133563
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-2/+2
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2022-08-03[SystemZ] Make 128 bit integers be aligned to 8 bytes.Jonas Paulsson1-0/+1
The SystemZ ABI says that 128 bit integers should be aligned to only 8 bytes. Reviewed By: Ulrich Weigand, Nikita Popov Differential Revision: https://reviews.llvm.org/D130900
2022-07-12[PS4/PS5] NFC: Use preferred predicate in a triple checkPaul Robinson1-1/+1
Also add a test to verify this difference in the PS4/PS5 ABIs, now that we have identified it.
2022-06-17[Clang] Allow 'Complex float __attribute__((mode(HC)))'Jolanta Jensen1-1/+3
Adding half float to types that can be represented by __attribute__((mode(xx))). Original implementation authored by George Steed. Differential Revision: https://reviews.llvm.org/D126479
2022-06-09clang: Introduce -fexperimental-max-bitint-widthMatthias Gehre1-0/+6
This splits of the introduction of -fexperimental-max-bitint-width from https://reviews.llvm.org/D122234 because that PR is still blocked on discussions on the backend side. I was asked [0] to upstream at least the flag. [0] https://github.com/llvm/llvm-project/commit/09854f2af3b914b616f29cb640bede3a27cf7c4e#commitcomment-75116619 Differential Revision: https://reviews.llvm.org/D127287
2022-04-22[Clang] Fix the guaranteed alignment of memory returned by malloc/new on OpenBSDMark Kettenis1-3/+3
The guaranteed alignment is 16 bytes on OpenBSD.
2022-02-14[X86][MS] Add 80bit long double support for WindowsPhoebe Wang1-0/+14
MSVC currently doesn't support 80 bits long double. But ICC does support it on Windows. Besides, there're also some users asked for this feature. We can find the discussions from stackoverflow, msdn etc. Given Clang has already support `-mlong-double-80`, extending it to support for Windows seems worthwhile. Reviewed By: rnk, erichkeane Differential Revision: https://reviews.llvm.org/D115441