summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprScalar.cpp
AgeCommit message (Collapse)Author
2022-03-09[clang] ScalarExprEmitter::VisitCastExpr - use castAs<> instead of getAs<> ↵Simon Pilgrim
to avoid dereference of nullptr The pointers are always dereferenced, so assert the cast is correct instead of returning nullptr
2022-02-23[clang] Remove Address::deprecated() from CGClass.cppArthur Eubanks
2022-02-17[CodeGen] Rename deprecated Address constructorNikita Popov
To make uses of the deprecated constructor easier to spot, and to ensure that no new uses are introduced, rename it to Address::deprecated(). While doing the rename, I've filled in element types in cases where it was relatively obvious, but we're still left with 135 calls to the deprecated constructor.
2022-02-13Refactor nested if else with ternary operator in CGExprScalar.cppphyBrackets
Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D119364
2022-02-11[clang] VisitCastExpr - use cast<> instead of dyn_cast<> to avoid ↵Simon Pilgrim
dereference of nullptr The pointer is always dereferenced, so assert the cast is correct (which it should be as we just created that ScalableVectorType) instead of returning nullptr
2022-02-07[MatrixBuilder] Remove unnecessary IRBuilder template (NFC)Nikita Popov
IRBuilderBase exists specifically to avoid the need for this.
2022-01-25[clang] Remove some getPointerElementType() usesNikita Popov
Same cases where the call can be removed in a straightforward way.
2021-12-16[CodeGen] Avoid more pointer element type accessesNikita Popov
2021-12-16[CodeGen] use saturating FP casts when compiling with ↵Sanjay Patel
"no-strict-float-cast-overflow" We got an unintended consequence of the optimizer getting smarter when compiling in a non-standard mode, and there's no good way to inhibit those optimizations at a later stage. The test is based on an example linked from D92270. We allow the "no-strict-float-cast-overflow" exception to normal C cast rules to preserve legacy code that does not expect overflowing casts from FP to int to produce UB. See D46236 for details. Differential Revision: https://reviews.llvm.org/D115804
2021-12-16[CodeGen] Avoid more pointer element type accessesNikita Popov
2021-12-15[CodeGen] Pass element type to EmitCheckedInBoundsGEP()Nikita Popov
Same as for other GEP creation methods.
2021-10-14PR52183: Don't emit code for a void-typed constant expression.Richard Smith
This is unnecessary in general, and wrong when the expression invokes a consteval function.
2021-10-12[clang] p0388 conversion to incomplete arrayNathan Sidwell
This implements the new implicit conversion sequence to an incomplete (unbounded) array type. It is mostly Richard Smith's work, updated to trunk, testcases added and a few bugs fixed found in such testing. It is not a complete implementation of p0388. Differential Revision: https://reviews.llvm.org/D102645
2021-10-04[APInt] Stop using soft-deprecated constructors and methods in clang. NFC.Jay Foad
Stop using APInt constructors and methods that were soft-deprecated in D109483. This fixes all the uses I found in clang. Differential Revision: https://reviews.llvm.org/D110808
2021-09-29[OpenCL] Fix as_type3 invalid store creationSven van Haastregt
With -fpreserve-vec3-type enabled, a cast was not created when converting from a non-vec3 type to a vec3 type, even though a conversion to vec3 was performed. This resulted in creation of invalid store instructions. Differential Revision: https://reviews.llvm.org/D108470
2021-09-22[Matrix] Emit assumption that matrix indices are valid.Florian Hahn
The matrix extension requires the indices for matrix subscript expression to be valid and it is UB otherwise. extract/insertelement produce poison if the index is invalid, which limits the optimizer to not be bale to scalarize load/extract pairs for example, which causes very suboptimal code to be generated when using matrix subscript expressions with variable indices for large matrixes. This patch updates IRGen to emit assumes to for index expression to convey the information that the index must be valid. This also adjusts the order in which operations are emitted slightly, so indices & assumes are added before the load of the matrix value. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D102478
2021-09-06[Clang] Add __ibm128 type to represent ppc_fp128Qiu Chaofan
Currently, we have no front-end type for ppc_fp128 type in IR. PowerPC target generates ppc_fp128 type from long double now, but there's option (-mabi=(ieee|ibm)longdouble) to control it and we're going to do transition from IBM extended double-double ppc_fp128 to IEEE fp128 in the future. This patch adds type __ibm128 which always represents ppc_fp128 in IR, as what GCC did for that type. Without this type in Clang, compilation will fail if compiling against future version of libstdcxx (which uses __ibm128 in headers). Although all operations in backend for __ibm128 is done by software, only PowerPC enables support for it. There's something not implemented in this commit, which can be done in future ones: - Literal suffix for __ibm128 type. w/W is suitable as GCC documented. - __attribute__((mode(IF))) should be for __ibm128. - Complex __ibm128 type. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D93377
2021-09-04[clang] NFC: Fix trivial typo in comments and documentKazuaki Ishizaki
`the the` -> `the` Reviewed By: xgupta Differential Revision: https://reviews.llvm.org/D77470
2021-08-19[OpenCL] Fix as_type(vec3) invalid store creationSven van Haastregt
With -fpreserve-vec3-type enabled, a cast was not created when converting from a vec3 type to a non-vec3 type, even though a conversion to vec4 was performed. This resulted in creation of invalid store instructions. Differential Revision: https://reviews.llvm.org/D107963
2021-08-04[clang][AArch64][SVE] Avoid going through memory for fixed/scalable ↵Bradley Smith
predicate casts For fixed SVE types, predicates are represented using vectors of i8, where as for scalable types they are represented using vectors of i1. We can avoid going through memory for casts between these by bitcasting the i1 scalable vectors to/from a scalable i8 vector of matching size, which can then use the existing vector insert/extract logic. Differential Revision: https://reviews.llvm.org/D106860
2021-07-28[clang] NFC: change uses of `Expr->getValueKind` into `is?Value`Matheus Izvekov
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D100733
2021-07-17[OpaquePtr] Remove uses of CreateGEP() without element typeNikita Popov
Remove uses of to-be-deprecated API. In cases where the correct element type was not immediately obvious to me, fall back to explicit getPointerElementType().
2021-07-17[OpaquePtr] Remove uses of CreateInBoundsGEP() without element typeNikita Popov
Remove uses of to-be-deprecated API. Unfortunately this one mostly just makes the use of getPointerElementType() explicit, as the correct type to use wasn't immediately available (deriving it from QualType is left as an excercise to the reader).
2021-07-01[clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST castJun Ma
This change fixes the crash that PRValue cannot be handled by EmitLValue. Differential Revision: https://reviews.llvm.org/D105097
2021-06-09[clang] NFC: Rename rvalue to prvalueMatheus Izvekov
This renames the expression value categories from rvalue to prvalue, keeping nomenclature consistent with C++11 onwards. C++ has the most complicated taxonomy here, and every other language only uses a subset of it, so it's less confusing to use the C++ names consistently, and mentally remap to the C names when working on that context (prvalue -> rvalue, no xvalues, etc). Renames: * VK_RValue -> VK_PRValue * Expr::isRValue -> Expr::isPRValue * SK_QualificationConversionRValue -> SK_QualificationConversionPRValue * JSON AST Dumper Expression nodes value category: "rvalue" -> "prvalue" Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D103720
2021-05-27Reimplement __builtin_unique_stable_name-Erich Keane
The original version of this was reverted, and @rjmcall provided some advice to architect a new solution. This is that solution. This implements a builtin to provide a unique name that is stable across compilations of this TU for the purposes of implementing the library component of the unnamed kernel feature of SYCL. It does this by running the Itanium mangler with a few modifications. Because it is somewhat common to wrap non-kernel-related lambdas in macros that aren't present on the device (such as for logging), this uniquely generates an ID for all lambdas involved in the naming of a kernel. It uses the lambda-mangling number to do this, except replaces this with its own number (starting at 10000 for readabililty reasons) for lambdas used to name a kernel. Additionally, this implements itself as constexpr with a slight catch: if a name would be invalidated by the use of this lambda in a later kernel invocation, it is diagnosed as an error (see the Sema tests). Differential Revision: https://reviews.llvm.org/D103112
2021-05-03[Matrix] Remove bitcast when casting between matrices of the same sizeSaurabh Jha
In matrix type casts, we were doing bitcast when the matrices had the same size. This was incorrect and this patch fixes that. Also added some new CodeGen tests for signed <-> usigned conversions Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D101754
2021-05-01[HIP] Fix device lib selectionYaxun (Sam) Liu
Choose optimized device lib bitcode by fp options for performance. Reviewed by: Artem Belevich, Fangrui Song Differential Revision: https://reviews.llvm.org/D101654
2021-04-22[Matrix] Support #pragma clang fpHamza Mahfooz
From https://bugs.llvm.org/show_bug.cgi?id=49739: Currently, `#pragma clang fp` are ignored for matrix types. For the code below, the `contract` fast-math flag should be added to the generated call to `llvm.matrix.multiply` and `fadd` ``` typedef float fx2x2_t __attribute__((matrix_type(2, 2))); void foo(fx2x2_t &A, fx2x2_t &C, fx2x2_t &B) { #pragma clang fp contract(fast) C = A*B + C; } ``` Reviewed By: fhahn, mibintc Differential Revision: https://reviews.llvm.org/D100834
2021-04-10[Matrix] Implement C-style explicit type conversions for matrix types.Saurabh Jha
This implements C-style type conversions for matrix types, as specified in clang/docs/MatrixTypes.rst. Fixes PR47141. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D99037
2021-04-07[clang] Move int <-> float scalar conversion to a separate functionSaurabh Jha
As prelude to this patch https://reviews.llvm.org/D99037, we want to move the int-float conversion into a separate function that can be reused by matrix cast Differential Revision: https://reviews.llvm.org/D100051
2021-04-06Don't directly dereference getAs<> casts to avoid potential null ↵Simon Pilgrim
dereferences. NFCI. Replace with castAs<> which asserts the cast is valid. Fixes a number of static analyzer warnings.
2021-03-12[clang] Use Constant::getAllOnesValue helper. NFCI.Simon Pilgrim
Avoid -1ULL which MSVC tends to complain about
2021-03-11void cast to suppress -Wunused-variable in non-asserts buildDavid Blaikie
2021-03-11[Matrix] Add support for matrix-by-scalar division.Florian Hahn
This patch extends the matrix spec to allow matrix-by-scalar division. Originally support for `/` was left out to avoid ambiguity for the matrix-matrix version of `/`, which could either be elementwise or specified as matrix multiplication M1 * (1/M2). For the matrix-scalar version, no ambiguity exists; `*` is also an elementwise operation in that case. Matrix-by-scalar division is commonly supported by systems including Matlab, Mathematica or NumPy. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D97857
2021-01-12[Fixed Point] Add codegen for conversion between fixed-point and floating point.Bevin Hansson
The patch adds the required methods to FixedPointBuilder for converting between fixed-point and floating point, and uses them from Clang. This depends on D54749. Reviewed By: leonardchan Differential Revision: https://reviews.llvm.org/D86632
2021-01-05[Coverage] Add support for Branch Coverage in LLVM Source-Based Code CoverageAlan Phipps
This is an enhancement to LLVM Source-Based Code Coverage in clang to track how many times individual branch-generating conditions are taken (evaluate to TRUE) and not taken (evaluate to FALSE). Individual conditions may comprise larger boolean expressions using boolean logical operators. This functionality is very similar to what is supported by GCOV except that it is very closely anchored to the ASTs. Differential Revision: https://reviews.llvm.org/D84467
2020-12-30Use unary CreateShuffleVector if possibleJuneyoung Lee
As mentioned in D93793, there are quite a few places where unary `IRBuilder::CreateShuffleVector(X, Mask)` can be used instead of `IRBuilder::CreateShuffleVector(X, Undef, Mask)`. Let's update them. Actually, it would have been more natural if the patches were made in this order: (1) let them use unary CreateShuffleVector first (2) update IRBuilder::CreateShuffleVector to use poison as a placeholder value (D93793) The order is swapped, but in terms of correctness it is still fine. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D93923
2020-12-16[clang][AArch64][SVE] Avoid going through memory for VLAT <-> VLST castsJoe Ellis
This change makes use of the llvm.vector.extract intrinsic to avoid going through memory when performing bitcasts between vector-length agnostic types and vector-length specific types. Depends on D91362 Reviewed By: c-rhodes Differential Revision: https://reviews.llvm.org/D92761
2020-12-08[FPEnv] Correct constrained metadata in fp16-ops-strict.cKevin P. Neal
This test shows we're in some cases not getting strictfp information from the AST. Correct that. Differential Revision: https://reviews.llvm.org/D92596
2020-12-08UBSAN: emit distinctive trapsTim Northover
Sometimes people get minimal crash reports after a UBSAN incident. This change tags each trap with an integer representing the kind of failure encountered, which can aid in tracking down the root cause of the problem.
2020-11-06[FPEnv] Use strictfp metadata in casting nodesKevin P. Neal
The strictfp metadata was added to the casting AST nodes in D85960, but we aren't using that metadata yet. This patch adds that support. In order to avoid lots of ad-hoc passing around of the strictfp bits I updated the IRBuilder when moving from a function that has the Expr* to a function that lacks it. I believe we should switch to this pattern to keep the strictfp support from being overly invasive. For the purpose of testing that we're picking up the right metadata, I also made my tests use a pragma to make the AST's strictfp metadata not match the global strictfp metadata. This exposes issues that we need to deal with in subsequent patches, and I believe this is the right method for most all of our clang strictfp tests. Differential Revision: https://reviews.llvm.org/D88913
2020-11-02[darwin] add support for __isPlatformVersionAtLeast check for if (@available)Alex Lorenz
The __isPlatformVersionAtLeast routine is an implementation of `if (@available)` check that uses the _availability_version_check API on Darwin that's supported on macOS 10.15, iOS 13, tvOS 13 and watchOS 6. Differential Revision: https://reviews.llvm.org/D90367
2020-10-13[Fixed Point] Add fixed-point to floating point cast types and consteval.Bevin Hansson
Reviewed By: leonardchan Differential Revision: https://reviews.llvm.org/D86631
2020-09-23[PowerPC] Implement the 128-bit vec_[all|any]_[eq | ne | lt | gt | le | ge] ↵Amy Kwan
builtins in Clang/LLVM This patch implements the vec_[all|any]_[eq | ne | lt | gt | le | ge] builtins for vector signed/unsigned __int128. Differential Revision: https://reviews.llvm.org/D87910
2020-08-28Reland "[CodeGen][AArch64] Support arm_sve_vector_bits attribute"Cullen Rhodes
This relands D85743 with a fix for test CodeGen/attr-arm-sve-vector-bits-call.c that disables the new pass manager with '-fno-experimental-new-pass-manager'. Test was failing due to IR differences with the new pass manager which broke the Fuchsia builder [1]. Reverted in 2e7041f. [1] http://lab.llvm.org:8011/builders/fuchsia-x86_64-linux/builds/10375 Original summary: This patch implements codegen for the 'arm_sve_vector_bits' type attribute, defined by the Arm C Language Extensions (ACLE) for SVE [1]. The purpose of this attribute is to define vector-length-specific (VLS) versions of existing vector-length-agnostic (VLA) types. VLSTs are represented as VectorType in the AST and fixed-length vectors in the IR everywhere except in function args/return. Implemented in this patch is codegen support for the following: * Implicit casting between VLA <-> VLS types. * Coercion of VLS types in function args/return. * Mangling of VLS types. Casting is handled by the CK_BitCast operation, which has been extended to support the two new vector kinds for fixed-length SVE predicate and data vectors, where the cast is implemented through memory rather than a bitcast which is unsupported. Implementing this as a normal bitcast would require relaxing checks in LLVM to allow bitcasting between scalable and fixed types. Another option was adding target-specific intrinsics, although codegen support would need to be added for these intrinsics. Given this, casting through memory seemed like the best approach as it's supported today and existing optimisations may remove unnecessary loads/stores, although there is room for improvement here. Coercion of VLSTs in function args/return from fixed to scalable is implemented through the AArch64 ABI in TargetInfo. The VLA and VLS types are defined by the ACLE to map to the same machine-level SVE vectors. VLS types are mangled in the same way as: __SVE_VLS<typename, unsigned> where the first argument is the underlying variable-length type and the second argument is the SVE vector length in bits. For example: #if __ARM_FEATURE_SVE_BITS==512 // Mangled as 9__SVE_VLSIu11__SVInt32_tLj512EE typedef svint32_t vec __attribute__((arm_sve_vector_bits(512))); // Mangled as 9__SVE_VLSIu10__SVBool_tLj512EE typedef svbool_t pred __attribute__((arm_sve_vector_bits(512))); #endif The latest ACLE specification (00bet5) does not contain details of this mangling scheme, it will be specified in the next revision. The mangling scheme is otherwise defined in the appendices to the Procedure Call Standard for the Arm Architecture, see [2] for more information. [1] https://developer.arm.com/documentation/100987/latest [2] https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-c-mangling Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D85743
2020-08-27Add an unsigned shift base sanitizerJF Bastien
It's not undefined behavior for an unsigned left shift to overflow (i.e. to shift bits out), but it has been the source of bugs and exploits in certain codebases in the past. As we do in other parts of UBSan, this patch adds a dynamic checker which acts beyond UBSan and checks other sources of errors. The option is enabled as part of -fsanitize=integer. The flag is named: -fsanitize=unsigned-shift-base This matches shift-base and shift-exponent flags. <rdar://problem/46129047> Differential Revision: https://reviews.llvm.org/D86000
2020-08-27Revert "[CodeGen][AArch64] Support arm_sve_vector_bits attribute"Cullen Rhodes
Test CodeGen/attr-arm-sve-vector-bits-call.c is failing on some builders [1][2]. Reverting whilst I investigate. [1] http://lab.llvm.org:8011/builders/fuchsia-x86_64-linux/builds/10375 [2] https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-linux-x64/b8870800848452818112 This reverts commit 42587345a3afc52c03c6e6095db773358a1b03e9.
2020-08-27[CodeGen][AArch64] Support arm_sve_vector_bits attributeCullen Rhodes
This patch implements codegen for the 'arm_sve_vector_bits' type attribute, defined by the Arm C Language Extensions (ACLE) for SVE [1]. The purpose of this attribute is to define vector-length-specific (VLS) versions of existing vector-length-agnostic (VLA) types. VLSTs are represented as VectorType in the AST and fixed-length vectors in the IR everywhere except in function args/return. Implemented in this patch is codegen support for the following: * Implicit casting between VLA <-> VLS types. * Coercion of VLS types in function args/return. * Mangling of VLS types. Casting is handled by the CK_BitCast operation, which has been extended to support the two new vector kinds for fixed-length SVE predicate and data vectors, where the cast is implemented through memory rather than a bitcast which is unsupported. Implementing this as a normal bitcast would require relaxing checks in LLVM to allow bitcasting between scalable and fixed types. Another option was adding target-specific intrinsics, although codegen support would need to be added for these intrinsics. Given this, casting through memory seemed like the best approach as it's supported today and existing optimisations may remove unnecessary loads/stores, although there is room for improvement here. Coercion of VLSTs in function args/return from fixed to scalable is implemented through the AArch64 ABI in TargetInfo. The VLA and VLS types are defined by the ACLE to map to the same machine-level SVE vectors. VLS types are mangled in the same way as: __SVE_VLS<typename, unsigned> where the first argument is the underlying variable-length type and the second argument is the SVE vector length in bits. For example: #if __ARM_FEATURE_SVE_BITS==512 // Mangled as 9__SVE_VLSIu11__SVInt32_tLj512EE typedef svint32_t vec __attribute__((arm_sve_vector_bits(512))); // Mangled as 9__SVE_VLSIu10__SVBool_tLj512EE typedef svbool_t pred __attribute__((arm_sve_vector_bits(512))); #endif The latest ACLE specification (00bet5) does not contain details of this mangling scheme, it will be specified in the next revision. The mangling scheme is otherwise defined in the appendices to the Procedure Call Standard for the Arm Architecture, see [2] for more information. [1] https://developer.arm.com/documentation/100987/latest [2] https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-c-mangling Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D85743
2020-08-26[SVE] Remove calls to VectorType::getNumElements from clangChristopher Tetreault
Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D82582