summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
AgeCommit message (Collapse)Author
2022-04-20Look through calls to std::addressof to compute pointer alignment.Eli Friedman
This is sort of a followup to D37310; that basically fixed the same issue, but then the libstdc++ implementation of <atomic> changed. Re-fix the the issue in essentially the same way: look through the addressof operation to find the alignment of the underlying object. Differential Revision: https://reviews.llvm.org/D123950
2022-04-13Fix Werror build issue from 6f20744b7ff875Erich Keane
2022-04-13Add support for ignored bitfield conditional codegen.Erich Keane
Currently we emit an error in just about every case of conditionals with a 'non simple' branch if treated as an LValue. This patch adds support for the special case where this is an 'ignored' lvalue, which permits the side effects from happening. It also splits up the emit for conditional LValue in a way that should be usable to handle simple assignment expressions in similar situations. Differential Revision: https://reviews.llvm.org/D123680
2022-04-08[Clang][Fortify] drop inline decls when redeclaredserge-sans-paille
When an inline builtin declaration is shadowed by an actual declaration, we must reference the actual declaration, even if it's not the last, following GCC behavior. This fixes #54715 Differential Revision: https://reviews.llvm.org/D123308
2022-03-23[CGExpr] Perform bitcast unconditionallyNikita Popov
The way the check is written is not compatible with opaque pointers -- while we don't need to change the IR pointer type, we do need to change the element type stored in the Address.
2022-03-23Reapply [CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()Nikita Popov
This requires some adjustment in caller code, because there was a confusion regarding the meaning of the PtrTy argument: This argument is the type of the pointer being loaded, not the addresses being loaded from. Reapply after fixing the specified pointer type for one call in 47eb4f7dcd845878b16a53dadd765195b9c24b6e, where the used type is important for determining alignment.
2022-03-23Revert "[CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()"Nikita Popov
This reverts commit 767ec883e37510a247ea5695921876ef67cf5b3f. This results in a some incorrect alignments which are not covered by existing tests.
2022-03-22[CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()Nikita Popov
This requires some adjustment in caller code, because there was a confusion regarding the meaning of the PtrTy argument: This argument is the type of the pointer being loaded, not the addresses being loaded from.
2022-03-17[CodeGen] Avoid some pointer element type accessesNikita Popov
2022-03-16[Clang] Allow "ext_vector_type" applied to BooleansSimon Moll
This is the `ext_vector_type` alternative to D81083. This patch extends Clang to allow 'bool' as a valid vector element type (attribute ext_vector_type) in C/C++. This is intended as the canonical type for SIMD masks and facilitates clean vector intrinsic declarations. Vectors of i1 are supported on IR level and below down to many SIMD ISAs, such as AVX512, ARM SVE (fixed vector length) and the VE target (NEC SX-Aurora TSUBASA). The RFC on cfe-dev: https://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D88905
2022-03-02[NFC][Clang][OpaquePtr] Remove the call to Address::deprecated inAkira Hatanaka
CreatePointerBitCastOrAddrSpaceCast Differential Revision: https://reviews.llvm.org/D120757
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-16[CGBuilder] Assert that CreateAddrSpaceCast does not change element typeNikita Popov
Address space casts in general may change the element type, but don't allow it in the method working on Address, so we can preserve the element type. CreatePointerBitCastOrAddrSpaceCast() still needs to be addressed.
2022-02-14Extend the `uwtable` attribute with unwind table kindMomchil Velikov
We have the `clang -cc1` command-line option `-funwind-tables=1|2` and the codegen option `VALUE_CODEGENOPT(UnwindTables, 2, 0) ///< Unwind tables (1) or asynchronous unwind tables (2)`. However, this is encoded in LLVM IR by the presence or the absence of the `uwtable` attribute, i.e. we lose the information whether to generate want just some unwind tables or asynchronous unwind tables. Asynchronous unwind tables take more space in the runtime image, I'd estimate something like 80-90% more, as the difference is adding roughly the same number of CFI directives as for prologues, only a bit simpler (e.g. `.cfi_offset reg, off` vs. `.cfi_restore reg`). Or even more, if you consider tail duplication of epilogue blocks. Asynchronous unwind tables could also restrict code generation to having only a finite number of frame pointer adjustments (an example of *not* having a finite number of `SP` adjustments is on AArch64 when untagging the stack (MTE) in some cases the compiler can modify `SP` in a loop). Having the CFI precise up to an instruction generally also means one cannot bundle together CFI instructions once the prologue is done, they need to be interspersed with ordinary instructions, which means extra `DW_CFA_advance_loc` commands, further increasing the unwind tables size. That is to say, async unwind tables impose a non-negligible overhead, yet for the most common use cases (like C++ exceptions), they are not even needed. This patch extends the `uwtable` attribute with an optional value: - `uwtable` (default to `async`) - `uwtable(sync)`, synchronous unwind tables - `uwtable(async)`, asynchronous (instruction precise) unwind tables Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D114543
2022-02-14[CGBuilder] Remove CreateBitCast() methodNikita Popov
Use CreateElementBitCast() instead, or don't work on Address where not necessary.
2022-02-11[Clang][OpaquePtr] Remove deprecated Address constructor callsWeverything
Remove most calls to deprcated Address constructor in CGExpr.cpp Differential Revision: https://reviews.llvm.org/D119496
2022-02-07[MatrixBuilder] Remove unnecessary IRBuilder template (NFC)Nikita Popov
IRBuilderBase exists specifically to avoid the need for this.
2022-01-27[NFC][Clang][OpaquePtr] Move away from deprecated Address constructor in ↵Arthur Eubanks
CreateTempAlloca() Specify the Address element type, which is the bitcast destination type. (the whole bitcast won't be needed after opaque pointers)
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-10[CodeGen] Avoid some pointer element type accessesNikita Popov
Possibly this is sufficient to fix PR53089.
2022-01-10Use a sorted array instead of a map to store AttrBuilder string attributesSerge Guelton
Using and std::map<SmallString, SmallString> for target dependent attributes is inefficient: it makes its constructor slightly heavier, and involves extra allocation for each new string attribute. Storing the attribute key/value as strings implies extra allocation/copy step. Use a sorted vector instead. Given the low number of attributes generally involved, this is cheaper, as showcased by https://llvm-compile-time-tracker.com/compare.php?from=5de322295f4ade692dc4f1823ae4450ad3c48af2&to=05bc480bf641a9e3b466619af43a2d123ee3f71d&stat=instructions Differential Revision: https://reviews.llvm.org/D116599
2022-01-08[CGExpr] Use castAs<> instead of getAs<> to avoid dereference of nullptrSimon Pilgrim
This will assert the cast is correct instead of returning nullptr
2021-12-23[CodeGen] Avoid pointer element type access when creating LValueNikita Popov
This required fixing two places that were passing the pointer type rather than the expected pointee type to the method.
2021-12-21[CodeGen] Accept Address in CreateLaunderInvariantGroupNikita Popov
Add an overload that accepts and returns an Address, as we generally just want to replace the pointer with a laundered one, while retaining remaining information.
2021-12-21[CodeGen] Avoid some pointer element type accessesNikita Popov
This avoids some pointer element type accesses when compiling C++ code.
2021-12-16[CodeGen] Avoid more pointer element type accessesNikita Popov
2021-12-15[CodeGen] Avoid some pointer element type accessesNikita Popov
2021-12-15[CodeGen] Pass element type to EmitCheckedInBoundsGEP()Nikita Popov
Same as for other GEP creation methods.
2021-12-15[CodeGen] Avoid some deprecated Address constructorsNikita Popov
Some of these are on the critical path towards making something minimal work with opaque pointers.
2021-12-15[CodeGen] Avoid some pointer element type accessesNikita Popov
2021-12-15[CodeGen] Store ElementType in AddressNikita Popov
Explicitly track the pointer element type in Address, rather than deriving it from the pointer type, which will no longer be possible with opaque pointers. This just adds the basic facility, for now everything is still going through the deprecated constructors. I had to adjust one place in the LValue implementation to satisfy the new assertions: Global registers are represented as a MetadataAsValue, which does not have a pointer type. We should avoid using Address in this case. This implements a part of D103465. Differential Revision: https://reviews.llvm.org/D115725
2021-11-10[CFE][Codegen] Make sure to maintain the contiguity of all the static allocashsmahesha
at the start of the entry block, which in turn would aid better code transformation/optimization. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D110257
2021-11-07[clang] Use llvm::reverse. NFCI.Benjamin Kramer
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-12[CFE][Codegen] Remove CodeGenFunction::InitTempAlloca()hsmahesha
Sequel patch to https://reviews.llvm.org/D111316 Finally, remove the defintion of CodeGenFunction::InitTempAlloca(). Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D111324
2021-10-04Update inline builtin handling to honor gnu inline attributeserge-sans-paille
Per the GCC info page: If the function is declared 'extern', then this definition of the function is used only for inlining. In no case is the function compiled as a standalone function, not even if you take its address explicitly. Such an address becomes an external reference, as if you had only declared the function, and had not defined it. Respect that behavior for inline builtins: keep the original definition, and generate a copy of the declaration suffixed by '.inline' that's only referenced in direct call. This fixes holes in c3717b6858d32d64514a187ede1a77be8ba4e542. Differential Revision: https://reviews.llvm.org/D111009
2021-10-03Fixed warnings in LLVM produced by -Wbitwise-instead-of-logicalDávid Bolvanský
2021-09-28DebugInfo: Use sugared function type when emitting function declarations for ↵David Blaikie
call sites Otherwise we're losing type information for these functions.
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-09[APInt] Normalize naming on keep constructors / predicate methods.Chris Lattner
This renames the primary methods for creating a zero value to `getZero` instead of `getNullValue` and renames predicates like `isAllOnesValue` to simply `isAllOnes`. This achieves two things: 1) This starts standardizing predicates across the LLVM codebase, following (in this case) ConstantInt. The word "Value" doesn't convey anything of merit, and is missing in some of the other things. 2) Calling an integer "null" doesn't make any sense. The original sin here is mine and I've regretted it for years. This moves us to calling it "zero" instead, which is correct! APInt is widely used and I don't think anyone is keen to take massive source breakage on anything so core, at least not all in one go. As such, this doesn't actually delete any entrypoints, it "soft deprecates" them with a comment. Included in this patch are changes to a bunch of the codebase, but there are more. We should normalize SelectionDAG and other APIs as well, which would make the API change more mechanical. Differential Revision: https://reviews.llvm.org/D109483
2021-08-23[clang][CodeGen] GetDefaultAlignTempAlloca uses preferred alignmentAndy Wingo
This function was defaulting to use the ABI alignment for the LLVM type. Here we change to use the preferred alignment. This will allow unification with GetTempAlloca, which if alignment isn't specified, uses the preferred alignment. Differential Revision: https://reviews.llvm.org/D108450
2021-08-17[NFC] More get/removeAttribute() cleanupArthur Eubanks
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-13[Clang][Codegen] Do not annotate thunk's this/return types with ↵Roman Lebedev
align/deref/nonnull attrs As it was discovered in post-commit feedback for 0aa0458f1429372038ca6a4edc7e94c96cd9a753, we handle thunks incorrectly, and end up annotating their this/return with attributes that are valid for their callees, not for thunks themselves. While it would be good to fix this properly, and keep annotating them on thunks, i've tried doing that in https://reviews.llvm.org/D100388 with little success, and the patch is stuck for a month now. So for now, as a stopgap measure, subj.
2021-05-07[SEH] Fix regression with SEH in noexpect functionsOlivier Goffart
Commit 5baea0560160a693b19022c5d0ba637b6b46b2d8 set the CurCodeDecl because it was needed to pass the assert in CodeGenFunction::EmitLValueForLambdaField, But this was not right to do as CodeGenFunction::FinishFunction passes it to EmitEndEHSpec and cause corruption of the EHStack. Revert the part of the commit that changes the CurCodeDecl, and instead adjust the assert to check for a null CurCodeDecl. Differential Revision: https://reviews.llvm.org/D102027
2021-04-26BPF: emit debuginfo for Function of DeclRefExpr if requestedYonghong Song
Commit e3d8ee35e4ad ("reland "[DebugInfo] Support to emit debugInfo for extern variables"") added support to emit debugInfo for extern variables if requested by the target. Currently, only BPF target enables this feature by default. As BPF ecosystem grows, callback function started to get support, e.g., recently bpf_for_each_map_elem() is introduced (https://lwn.net/Articles/846504/) with a callback function as an argument. In the future we may have something like below as a demonstration of use case : extern int do_work(int); long bpf_helper(void *callback_fn, void *callback_ctx, ...); long prog_main() { struct { ... } ctx = { ... }; return bpf_helper(&do_work, &ctx, ...); } Basically bpf helper may have a callback function and the callback function is defined in another file or in the kernel. In this case, we would like to know the debuginfo types for do_work(), so the verifier can proper verify the safety of bpf_helper() call. For the following example, extern int do_work(int); long bpf_helper(void *callback_fn); long prog() { return bpf_helper(&do_work); } Currently, there is no debuginfo generated for extern function do_work(). In the IR, we have, ... define dso_local i64 @prog() local_unnamed_addr #0 !dbg !7 { entry: %call = tail call i64 @bpf_helper(i8* bitcast (i32 (i32)* @do_work to i8*)) #2, !dbg !11 ret i64 %call, !dbg !12 } ... declare dso_local i32 @do_work(i32) #1 ... This patch added support for the above callback function use case, and the generated IR looks like below: ... declare !dbg !17 dso_local i32 @do_work(i32) #1 ... !17 = !DISubprogram(name: "do_work", scope: !1, file: !1, line: 1, type: !18, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) !18 = !DISubroutineType(types: !19) !19 = !{!20, !20} !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) The TargetInfo.allowDebugInfoForExternalVar is renamed to TargetInfo.allowDebugInfoForExternalRef as now it guards both extern variable and extern function debuginfo generation. Differential Revision: https://reviews.llvm.org/D100567
2021-04-26[SYCL] Implement SYCL address space attributes handlingAlexey Bader
Default address space (applies when no explicit address space was specified) maps to generic (4) address space. Added SYCL named address spaces `sycl_global`, `sycl_local` and `sycl_private` defined as sub-sets of the default address space. Static variables without address space now reside in global address space when compile for SPIR target, unless they have an explicit address space qualifier in source code. Differential Revision: https://reviews.llvm.org/D89909
2021-04-15Implemented [[clang::musttail]] attribute for guaranteed tail calls.Joshua Haberman
This is a Clang-only change and depends on the existing "musttail" support already implemented in LLVM. The [[clang::musttail]] attribute goes on a return statement, not a function definition. There are several constraints that the user must follow when using [[clang::musttail]], and these constraints are verified by Sema. Tail calls are supported on regular function calls, calls through a function pointer, member function calls, and even pointer to member. Future work would be to throw a warning if a users tries to pass a pointer or reference to a local variable through a musttail call. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D99517