aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/TargetInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-20[clang][RISCV] Fix crash on VLS calling convention (#145489)Brandon Wu1-0/+7
This patch handle struct of fixed vector and struct of array of fixed vector correctly for VLS calling convention in EmitFunctionProlog, EmitFunctionEpilog and EmitCall. stack on: https://github.com/llvm/llvm-project/pull/147173
2025-06-18[clang] Use TargetInfo to determine device kernel calling convention (#144728)Nick Sarnie1-12/+15
We should abstract this logic away to `TargetInfo`. See https://github.com/llvm/llvm-project/pull/137882 for more information. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-06-05[clang] Simplify device kernel attributes (#137882)Nick Sarnie1-1/+1
We have multiple different attributes in clang representing device kernels for specific targets/languages. Refactor them into one attribute with different spellings to make it more easily scalable for new languages/targets. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-05-20[clang][AArch64] Move initialization of ptrauth-* function attrs (#140277)Anatoly Trosinenko1-0/+29
Move the initialization of ptrauth-* function attributes near the initialization of branch protection attributes. The semantics of these groups of attributes partially overlaps, so handle both groups in getDefaultFunctionAttributes() and setTargetAttributes() functions to prevent getting them out of sync. This fixes C++ TLS wrappers.
2025-05-09clang: Remove dest LangAS argument from performAddrSpaceCast (#138866)Matt Arsenault1-3/+3
It isn't used and is redundant with the result pointer type argument. A more reasonable API would only have LangAS parameters, or IR parameters, not both. Not all values have a meaningful value for this. I'm also not sure why we have this at all, it's not overridden by any targets and further simplification is possible.
2025-04-08[Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (#115821)Aniket Lal1-0/+6
This feature is currently not supported in the compiler. To facilitate this we emit a stub version of each kernel function body with different name mangling scheme, and replaces the respective kernel call-sites appropriately. Fixes https://github.com/llvm/llvm-project/issues/60313 D120566 was an earlier attempt made to upstream a solution for this issue. --------- Co-authored-by: anikelal <anikelal@amd.com>
2024-08-09[Arm][AArch64][Clang] Respect function's branch protection attributes. (#101978)Daniel Kiss1-4/+28
Default attributes assigned to all functions according to the command line parameters. Some functions might have their own attributes and we need to set or remove attributes accordingly. Tests are updated to test this scenarios too.
2024-07-12[NFC][Clang] Move set functions out BranchProtectionInfo. (#98451)Daniel Kiss1-0/+22
To reduce build times move them to TargetCodeGenInfo. Refactor of #98329
2023-11-11[clang] Replace uses of CreatePointerBitCastOrAddrSpaceCast (NFC) (#68277)Youngsuk Kim1-1/+1
With opaque pointers, `CreatePointerBitCastOrAddrSpaceCast` can be replaced with `CreateAddrSpaceCast`. Replace or remove uses of `CreatePointerBitCastOrAddrSpaceCast`. Opaque pointer cleanup effort.
2023-06-17[clang][CodeGen] Break up TargetInfo.cpp [8/8]Sergei Barannikov1-12599/+8
This commit breaks up CodeGen/TargetInfo.cpp into a set of *.cpp files, one file per target. There are no functional changes, mostly just code moving. Non-code-moving changes are: * A virtual destructor has been added to DefaultABIInfo to pin the vtable to a cpp file. * A few methods of ABIInfo and DefaultABIInfo were split into declaration + definition in order to reduce the number of transitive includes. * Several functions that used to be static have been placed in clang::CodeGen namespace so that they can be accessed from other cpp files. RFC: https://discourse.llvm.org/t/rfc-splitting-clangs-targetinfo-cpp/69883 Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148094
2023-06-17[clang][CodeGen] Break up TargetInfo.cpp [7/8]Sergei Barannikov1-123/+288
Wrap calls to XXXTargetCodeGenInfo constructors into factory functions. This allows moving implementations of TargetCodeGenInfo to dedicated cpp files without a change. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D150215
2023-06-16[clang] Replace use of Type::getPointerTo() (NFC)Youngsuk Kim1-3/+4
Partial progress towards replacing in-tree uses of `Type::getPointerTo()`. This needs to be done before deprecating the API. Reviewed By: nikic, barannikov88 Differential Revision: https://reviews.llvm.org/D152321
2023-06-13[MS] Fix passing aligned records by value in some casesReid Kleckner1-3/+15
It's not exactly clear what the meaning of TypeInfo::AlignRequirement is, so go directly to the ASTRecordLayout for records and check the required alignment there. Compare that number with the stack alignment value of 4. This fixes cases when the alignment attribute does not appear directly on the record [1], or when the attribute on the record is underaligned [2]. [1]: `struct Foo { int __declspec(align(16)) x; };` [2]: `struct __declspec(align(1)) Bar { int x; };` Fixes https://llvm.org/pr63257 Differential Revision: https://reviews.llvm.org/D152752
2023-06-12[Clang] Remove uses of PointerType::getWithSamePointeeType (NFC)Nikita Popov1-4/+4
No longer relevant with opaque pointers.
2023-06-04[clang][CodeGen] Break up TargetInfo.cpp [6/8]Sergei Barannikov1-5/+8
Make `qualifyWindowsLibrary` and `addStackProbeTargetAttributes` protected members of `TargetCodeGenInfo`. These are helper functions used by `getDependentLibraryOption` and `setTargetAttributes` methods when targeting Windows. The change will allow these functions to be reused after splitting `TargetInfo.cpp`. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D150178
2023-05-19[clang][CodeGen] Break up TargetInfo.cpp [5/8]Sergei Barannikov1-7/+6
Make `occupiesMoreThan` a protected member of `SwiftABIInfo`. This method is only used by implementations of `SwiftABIInfo`. Making it protected will allow to use it after the implementations are moved to dedicated cpp files. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148093
2023-05-19[clang][CodeGen] Break up TargetInfo.cpp [4/8]Sergei Barannikov1-21/+7
Remove `getABIInfo` overrides returning references to target-specific implementations of `ABIInfo`. The methods may be convenient, but they are only used in one place and prevent from `ABIInfo` implementations from being put into anonymous namespaces in different cpp files. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148092
2023-05-19[clang][CodeGen] Break up TargetInfo.cpp [3/8]Sergei Barannikov1-5/+5
Don't derive from `DefaultTargetCodeGenInfo`. This class is going to stay in `TargetInfo.cpp`, whereas its derivants are going to be moved to separate translation units. Just derive from the base `TargetCodeGenInfo` class instead. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148091
2023-05-19[clang][CodeGen] Break up TargetInfo.cpp [2/8]Sergei Barannikov1-95/+93
Move `ABIKind` enums out of `*ABIInfo` classes to break the dependency between `getTargetCodeGenInfo` and the classes. This will allow to move the classes to different cpp files. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148090
2023-05-19[clang][CodeGen] Break up TargetInfo.cpp [1/8]Sergei Barannikov1-2/+10
`CCState` is a helper class originally used by the x86 implementation but has since been abused by other implementations. Remove this dependency by implementing customized versions of the class for implementations that need such functionality. Reviewed By: efriedma, MaskRay Differential Revision: https://reviews.llvm.org/D148089
2023-05-19Change -fsanitize=function to place two words before the function entryFangrui Song1-18/+0
The current implementation of -fsanitize=function places two words (the prolog signature and the RTTI proxy) at the function entry, which makes the feature incompatible with Intel Indirect Branch Tracking (IBT) that needs an ENDBR instruction at the function entry. To allow the combination, move the two words before the function entry, similar to -fsanitize=kcfi. Armv8.5 Branch Target Identification (BTI) has a similar requirement. Note: for IBT and BTI, whether a function gets a marker instruction at the entry generally cannot be assumed (it can be disabled by a function attribute or stronger LTO optimizations). It is extremely unlikely for two words preceding a function entry to be inaccessible. One way to achieve this is by ensuring that a function is aligned at a page boundary and making the preceding page unmapped or unreadable. This is not reasonable for application or library code. (Think: the first text section has crt* code not instrumented by -fsanitize=function.) We use 0xc105cafe for all targets. .long 0xc105cafe disassembles to invalid instructions on all architectures I have tested, except Power where it is `lfs 8, -13570(5)` (Load Floating-Point with a weird offset, unlikely to be used in real code). --- For the removed function in AsmPrinter.cpp, remove an assert: `mdconst::extract` already asserts non-nullness. For compiler-rt/test/ubsan/TestCases/TypeCheck/Function/function.cpp, when the function doesn't have prolog/epilog (-O1 and above), after moving the two words, the address of the function equals the address of ret instruction, so symbolizing the function will additionally get a non-zero column number. Adjust the test to allow an optional column number. ``` .long 3238382334 .long .L__llvm_rtti_proxy-_Z1fv _Z1fv: // symbolizing here retrieves the line table entry from the second .loc .file 0 ... .loc 0 1 0 .cfi_startproc .loc 0 2 1 prologue_end retq ``` Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D148665
2023-05-16Migrate {starts,ends}with_insensitive to {starts,ends}_with_insensitive (NFC)Kazu Hirata1-1/+1
This patch migrates uses of StringRef::{starts,ends}with_insensitive to StringRef::{starts,ends}_with_insensitive so that we can use names similar to those used in std::string_view. Note that the llvm/ directory has migrated in commit 6c3ea866e93003e16fc55d3b5cedd3bc371d1fde. I'll post a separate patch to deprecate StringRef::{starts,ends}with_insensitive. Differential Revision: https://reviews.llvm.org/D150506
2023-05-15[clang] Fix emitVoidPtrVAArg for non-zero default alloca address spaceJessica Clarke1-2/+4
Indirect arguments are passed on the stack and so va_arg should use the default alloca address space, not hard-code 0, for pointers to those. The only in-tree target with a non-zero default alloca address space is AMDGPU, but that does not support variadic arguments, so we cannot test this upstream. However, downstream in CHERI LLVM (and Morello LLVM, a further fork of that) we have targets that do both and so require this change. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D132247
2023-04-29Revert "[RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to ↵Craig Topper1-1/+1
Support/RISCVISAInfo.h." This reverts commit ee9cbe3548cded885c6409d6dd8a616b515a06d3. I've been told this cauess a namespace clash in lld.
2023-04-29[RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to Support/RISCVISAInfo.h.Craig Topper1-1/+1
RISCVTargetParser.h has a dependency on a tablegen generated file. Using RISCVISAInfo.h instead avoids this dependency. We just need this constant somewhere visible to the frontend and backend and I'm trying to avoid adding a header just for it.
2023-04-28[RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 ↵Craig Topper1-0/+26
arm_sve_vector_bits. This allows the user to set the size of the scalable vector so they can be used in structs and as the type of global variables. This works by representing the type as a fixed vector instead of a scalable vector in IR. Conversions to and from scalable vectors are made where necessary like function arguments/returns and intrinsics. This features has been requested here https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/176 I know arm_sve_vector_bits is used by the Eigen library so this could be used to port Eigen to RVV. This patch adds a new preprocessor define `__riscv_v_fixed_vlen` that is set when -mrvv_vector_bits is passed on the command line. The code is largely based on the AArch64 code. A lot of code was copy/pasted and then modiied to RVV. There may be some opportunities for sharing. This first patch only supports the LMUL=1 types. Additional changes will be needed to support other LMULs. I have also not supported mask vectors. Differential Revision: https://reviews.llvm.org/D145088
2023-04-27[RISCV] Remove support for attribute interrupt("user").Craig Topper1-1/+0
This was part of the N extension which didn't make it version 1.12 of the privilege specification. Reviewed By: kito-cheng Differential Revision: https://reviews.llvm.org/D149314
2023-04-21[OpenMP][AMDGPU] Refactor setting uniform work group size attributeDominik Adamski1-4/+1
Work group size attribute was set in Clang specific class. That's why we cannot reuse this code in Flang. If we move setting of this attribute to OpenMPIRBuilder, then we can reuse this code in Flang and Clang. Function createOffloadEntry from OpenMPIRBuilder is already used by Clang (via OpenMPIRBuilder::createOffloadEntriesAndInfoMetadata function). Differential Revision: https://reviews.llvm.org/D148525 Reviewed By: jdoerfert
2023-04-17[NFC][clang] Fix coverity static analyzer concerns about AUTO_CAUSES_COPYManna, Soumi1-1/+1
Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance. 1. [NFC] Fix auto keyword use without an & causes the copy of an object of type SimpleRegistryEntry in clang::getAttributePluginInstances() 2. [NFC] Fix auto keyword use without an & causes the copy of an object of type tuple in CheckStmtInlineAttr<clang::NoInlineAttr, 2>(clang::Sema &, clang::Stmt const *, clang::Stmt const *, clang::AttributeCommonInfo const &) 3. [NFC] Fix auto keyword use without an & causes the copy of an object of type QualType in <unnamed>::SystemZTargetCodeGenInfo::isVectorTypeBased(clang::Type const *, bool) 4. [NFC] Fix auto keyword use without an & causes the copy of an object of type Policy in <unnamed>::RISCVIntrinsicManagerImpl::InitIntrinsicList() 5. [NFC] Fix auto keyword use without an & causes the copy of an object of type pair in checkUndefinedButUsed(clang::Sema &) Reviewed By: tahonermann Differential Revision: <https://reviews.llvm.org/D147543>
2023-03-28[clang][PowerPC] Remove remaining Darwin supportDavid Tenty1-1/+1
POWER Darwin support in the backend has been removed for some time: https://discourse.llvm.org/t/rfc-remove-darwin-support-from-power-backends but Clang still has the TargetInfo and other remnants lying around. This patch does some cleanup and removes those and other related frontend support still remaining. We adjust any tests using the triple to either remove the test if unneeded or switch to another Power triple. Reviewed By: MaskRay, nemanjai Differential Revision: https://reviews.llvm.org/D146459
2023-03-28[Clang][DebugInfo][AMDGPU] Emit zero size bitfields in the debug info to ↵Juan Manuel MARTINEZ CAAMAÑO1-0/+5
delimit bitfields in different allocation units. Consider the following sturctures when targetting: struct foo { int space[4]; char a : 8; char b : 8; char x : 8; char y : 8; }; struct bar { int space[4]; char a : 8; char b : 8; char : 0; char x : 8; char y : 8; }; Even if both structs have the same layout in memory, they are handled differenlty by the AMDGPU ABI. With the following code: // clang --target=amdgcn-amd-amdhsa -g -O1 example.c -S char use_foo(struct foo f) { return f.y; } char use_bar(struct bar b) { return b.y; } For use_foo, the 'y' field is passed in v4 ; v_ashrrev_i32_e32 v0, 24, v4 ; s_setpc_b64 s[30:31] For use_bar, the 'y' field is passed in v5 ; v_bfe_i32 v0, v5, 8, 8 ; s_setpc_b64 s[30:31] To make this distinction, we record a single 0-size bitfield for every member that is preceded by it. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D144870
2023-03-27[RISCV] Replace RISCV -> RISC-V in comments. NFCCraig Topper1-1/+1
To be consistent with RISC-V branding guidelines https://riscv.org/about/risc-v-branding-guidelines/ Think we should be using RISC-V where possible. More patches will follow. Reviewed By: asb Differential Revision: https://reviews.llvm.org/D146449
2023-03-26[clang][RISCV] Fix ABI lowering for _Float16 for FP ABIsAlex Bradbury1-4/+3
For trivial cases (`_Float16` as a standalone argument), it was previously correctly lowered to half. But the logic for catching cases involving structs was gated off, as at the time that logic was written the ABI for half was unclear. This patch fixes that and adds a release note. Differential Revision: https://reviews.llvm.org/D145074
2023-03-24[NVPTX] Introduce attribute to mark kernels without a language modeJoseph Huber1-0/+5
We may want to be able to mark certain regions as kernels even without being in an accepted CUDA or OpenCL language mode. This patch introduces a new attribute limited to `nvptx` targets called `nvptx_kernel` which will perform the same metadata action as the existing CUDA ones. This closely mimics the behaviour of the `amdgpu_kernel` attribute. This allows for making executable NVPTX device images without using an existing offloading language model. I was unsure how to do this, I could potentially re-use all the CUDA attributes and just replace the `CUDA` language requirement with an `NVPTX` architecture requirement. Also I don't know if I should add more than just this attribute. Reviewed By: tra Differential Revision: https://reviews.llvm.org/D140226
2023-03-20[LLVM][OHOS] Clang toolchain and targetsPavel Kosov1-2/+6
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/+4
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-16clang: Use ptrmask for pointer alignmentMatt Arsenault1-10/+6
Avoid using ptrtoint/inttoptr.
2023-03-16Emit const globals with constexpr destructor as constant LLVM valuesHans Wennborg1-1/+1
This follows 2b4fa53 which made Clang not emit destructor calls for such objects. However, they would still not get emitted as constants since CodeGenModule::isTypeConstant() returns false if the destructor is constexpr. This change adds a param to make isTypeConstant() ignore the dtor, allowing the caller to check it instead. Fixes Issue #61212 Differential revision: https://reviews.llvm.org/D145369
2023-03-14Revert "[LLVM][OHOS] Clang toolchain and targets"Daniel Thornburgh1-6/+2
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-2/+6
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-13[Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.Joshua Cranmer1-0/+75
Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D141008
2023-02-21[Driver][FreeBSD] Correct driver behavior if a triple is provided without a ↵Brad Smith1-3/+1
version While looking at other usage of getOSMajorVersion() I noticed if a version number is not included in the FreeBSD triple it won't include the --hash-style=both linker option or not disable the use of .init_array. Without a version should be the latest. FreeBSD 8 and 9 are no longer supported. So simplify things with the version handling as well. Reviewed By: dim Differential Revision: https://reviews.llvm.org/D144341
2023-02-17[WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+5
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122215
2023-02-07[NFC][TargetParser] Remove llvm/ADT/Triple.hArchibald Elliott1-1/+1
I also ran `git clang-format` to get the headers in the right order for the new location, which has changed the order of other headers in two files.
2023-02-05Revert "[clang][WebAssembly] Initial support for reference type externref in ↵Vitaly Buka1-5/+0
clang" Very likely breaks stage 3 of msan build bot. Good: 764c88a50ac76a2df2d051a0eb5badc6867aabb6 https://lab.llvm.org/buildbot/#/builders/74/builds/17058 Looks unrelated: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c Bad: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c https://lab.llvm.org/buildbot/#/builders/74/builds/17059 This reverts commit eb66833d19573df97034a81279eda31b8d19815b.
2023-01-31[clang][WebAssembly] Initial support for reference type externref in clangPaulo Matos1-0/+5
This patch introduces a new type __externref_t that denotes a WebAssembly opaque reference type. It also implements builtin __builtin_wasm_ref_null_extern(), that returns a null value of __externref_t. This lays the ground work for further builtins and reference types. Differential Revision: https://reviews.llvm.org/D122215
2023-01-30clang/OpenCL: Apply default attributes to enqueued blocksMatt Arsenault1-8/+12
This was missing important environment context, like denormal-fp-math and target-features. Curiously this seems to be losing nounwind. Note this only fixes the actual invoke kernel. The invoke function is already setting the default attribute set for internal functions. However that is still buggy since it's not applying any use function attributes (it's also missing uniform-work-group-size). There seem to be too many different functions for setting attributes with inconsistent behavior. The Function overload of addDefaultFunctionAttributes seems to miss the target-cpu and target-features. The AttrBuilder one seems to miss optnone (but that seems to be disallowed on blocks anyway). Neither one calls setTargetAttributes, when it probably should. uniform-work-group-size is also set through AMDGPU code when it should be emitting generically as a language property. I also noticed update_cc_test_checks for attributes seem to not connect the captured attribute variables to the attributes at the end (although I think the numbers happen to work out correctly).
2023-01-30clang/OpenCL: Fix not setting convergent on block invoke kernelsMatt Arsenault1-0/+2
Yet another example how convergent not being the default is dangerous and backwards.
2023-01-30clang/OpenCL: Don't use a Function for the block typeMatt Arsenault1-13/+22
The AMDGPU value for this is not really a function. Currently we're emitting IR that isn't true to what will eventually be emitted.
2023-01-28Use llvm::bit_ceil (NFC)Kazu Hirata1-4/+2
Note that: std::has_single_bit(X) ? X : llvm::NextPowerOf2(X); is equivalent to: std::bit_ceil(X) even for input 0.