aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
AgeCommit message (Collapse)Author
2022-07-21LLVM: fix lowering of structs with underaligned fieldsAndrew Kelley
When lowering a struct type to an LLVM struct type, keep track of whether there are any underaligned fields. If so, then make it a packed llvm struct. This works because we already insert manual padding bytes regardless. We could unconditionally use an LLVM packed struct; the reason we bother checking for underaligned fields is that it is a conservative choice, in case LLVM handles packed structs less optimally. A future improvement could simplify this code by unconditionally using packed LLVM structs and then make sure measure perf is unaffected. closes #12190
2022-07-20stage2 llvm: fix handling of pointer fields in packed structsVeikka Tuominen
2022-07-19LLVM: change commentary on isByRefAndrew Kelley
This branch originally started out as a potential workaround to address #11450. It did not solve that problem, however, it did end up fixing #11498!
2022-07-19LLVM: lower all error unions as byref=trueAndrew Kelley
Same reasoning as previous commit.
2022-07-19LLVM: lower all structs as byref=trueAndrew Kelley
Same reasoning as previous commit.
2022-07-19LLVM: lower optional types as byref=trueAndrew Kelley
This is a possible workaround for https://github.com/llvm/llvm-project/issues/56585 On my computer it makes stage3-release go from false positive compilation errors on the behavior tests to "segmentation fault". Is this forwards progress or backwards progress? I have no idea. See #11450
2022-07-19stage2: Change optional non-null field to i8Cody Tapscott
This is a workaround for https://github.com/llvm/llvm-project/issues/56585 which causes writes to i1 in memory to be optimized to an incorrect value. Unfortunately, this does not save users from running into this bug with u1 in their own types. However, this does seem to be enough to get the behavior tests working. This resolves #11450 on my machine.
2022-07-14LLVM: disable the ABI size safety checkAndrew Kelley
There are many more instances of this check being tripped that we need to fix before we can enable this.
2022-07-14LLVM: fix ABI size of optional and error union typesAndrew Kelley
Previously, the Zig ABI size and LLVM ABI size of these types disagreed sometimes. This code also corrects the logging messages to not trigger LLVM assertions.
2022-07-14Revert "stage2 llvm: Use unpacked struct for unions and arrays"Andrew Kelley
This reverts commit 2eaef84ebe968224b0cf25206abf12ea1c5e0f5a. Here is a motivating example: ```zig const E = union(enum) { A: [9]u8, B: u64, }; ``` ```llvm %test2.E = type { { i64, [1 x i8] }, i1, [6 x i8] } ``` ``` error(codegen): when lowering test2.E, Zig ABI size = 16 but LLVM ABI size = 24 ```
2022-07-14LLVM: add padding to optional types when loweringAndrew Kelley
If the LLVM ABI size does not agree with the Zig ABI size.
2022-07-14LLVM: insert debug logging when LLVM ABI size is wrongAndrew Kelley
2022-07-13LLVM: implement signext/zeroext attributesAndrew Kelley
For calling convention ABI purposes, integer attributes and return values need to have an LLVM attribute signext or zeroext added sometimes. This commit implements that logic. It also implements a proof-of-concept of moving the F16T type from being a compiler_rt hack to being how the compiler lowers f16 in functions that need to match certain calling conventions. Closes #12054
2022-07-12LLVM: always add some clobbers for some architecturesAndrew Kelley
For some targets, Clang unconditionally adds some clobbers to all inline assembly. While this is probably not strictly necessary, if we don't follow Clang's lead here then we may risk tripping LLVM bugs since anything not used by Clang tends to be buggy and regress often.
2022-07-12LLVM: broaden aarch64-windows f16 debug variable workaroundAndrew Kelley
LLVM does not properly handle debug info for f16 on the aarch64-windows target, causing "fatal error: unknown codeview register H1". The previous workaround checked only for f16 but was still vulnerable if a type was a byval struct or tuple which had an f16 field in it. Now I have filed an upstream issue (see https://github.com/llvm/llvm-project/issues/56484) and broadened the workaround to always skip debug values for this target.
2022-07-12stage2 llvm: Use unpacked struct for unions and arraysCody Tapscott
Our lowerings for various LLVM types assume that we can anticipate the alignment/layout that LLVM will generate. Among other things, this requires that we keep the alignment of our lowered LLVM types synchronized with their expected alignment in Zig. - Arrays were using packed struct types, which is seems to be incorrect since array elements are supposed to be self-aligned. - Unions were using packed struct types for their payload, which causes layout divergence between what stage2 expects and what LLVM generates Consider this lowered union type: ```llvm %Value = type { <{ i64, [8 x i8] }>, i1, [7 x i8] } ; 24 bytes, align(1) %ErrorUnion = type { %Value, i16 } ; 26 bytes, align(2) ``` Zig expects Value to be align(8) and, by extension, for ErrorUnion to be size 32.
2022-07-10stage2: Lower libcalls on Windows x86-64 correctlyCody Tapscott
This change is the Zig counterpart to https://reviews.llvm.org/D110413 Same as the prior commit, but for stage2
2022-07-07Merge remote-tracking branch 'origin/master' into llvm14Andrew Kelley
2022-07-07LLVM: more robust implementation of C ABI for multiple_llvm_intsAndrew Kelley
The previous code here was potentially more optimal for some cases, however, I never tested the perf, so it might not actually matter. This code handles more cases. We can go back and re-evaluate that other implementation if it seems worthwhile in the future.
2022-07-07LLVM: handle byref combined with multiple_llvm_intsAndrew Kelley
2022-07-05CLI: add support for -fno-builtinAndrew Kelley
2022-07-03update build scripts to LLD and LLVM 14 librariesAndrew Kelley
2022-07-03LLVM: update lowering of saturating shift-leftAndrew Kelley
LLVM 14 makes it so that a RHS of saturating shift left produces a poison value if the value is greater than the number of bits of the LHS. Zig now emits code that will check if this is the case and select a saturated LHS value in such case, matching Zig semantics.
2022-07-03LLVM: update inline asm to LLVM14 semanticsAndrew Kelley
This is the equivalent of d19290e603833a197bc8bfc8315561ec77291225 applied to stage2 instead of stage1.
2022-07-01stage1: update to LLVM 14 APIAndrew Kelley
2022-06-30LLVM: be sure to never pass align(0) attributeAndrew Kelley
This can happen with pointers to zero-bit types. This commit fixes an LLVM assertion being tripped.
2022-06-30LLVM: use unnamed struct llvm type for unions when necessaryAndrew Kelley
The constant value lowering for unions was missing a check for whether the payload was itself an unnamed struct. Lowerings of other types already handle this case. closes #11971
2022-06-30Merge pull request #11942 from Vexu/stage2-compile-errorsAndrew Kelley
Move passing stage1 compile error tests to stage2
2022-06-30Merge pull request #11967 from ziglang/runtime-float-negationAndrew Kelley
stage2: lower float negation explicitly + modify hash/eql logic for floats
2022-06-30LLVM: lower float negation with xor a constantAndrew Kelley
Rather than a compiler-rt call in the case that LLVM does not support lowering the fneg instruction.
2022-06-30stage2 llvm: ensure `@tagName` functions are uniqueVeikka Tuominen
2022-06-30stage2: lower float negation explicitlyAndrew Kelley
Rather than lowering float negation as `0.0 - x`. * Add AIR instruction for float negation. * Add compiler-rt functions for f128, f80 negation closes #11853
2022-06-30LLVM: fix lowering of untagged union typesAndrew Kelley
The LLVM backend was calculating the amount of padding solely based on the payload size. However, in the case where there is no union tag, this fails to take into account alignment. Closes #11857
2022-06-27LLVM: fix invalid IR on `@returnAddress` of wasm/bpfAndrew Kelley
see #11946
2022-06-27LLVM: support calls to varargs functionsAndrew Kelley
closes #11944
2022-06-12stage2: fix some inline asm incompatibilities with stage1Andrew Kelley
2022-06-11stage2: make `error{}` the same size as `anyerror`Veikka Tuominen
Having `error{}` be a zero bit type causes issues when it interracts with empty inferred error sets which are the same size as `anyerror`.
2022-06-11stage2: improve debugging toolsVeikka Tuominen
llvm: dump failed module when -femit-llvm-ir set print_air: * print fully qualified name * use Type.fmt and Value.fmtValue, fmtDebug is useless TypedValue * handle anon structs and tuples * fix bugs
2022-06-11Merge pull request #11835 from ziglang/stage2-behaviorAndrew Kelley
stage2: fix handling of aggregates with mixed comptime-only fields
2022-06-09stage2: fix handling of aggregates with mixed comptime-only fieldsAndrew Kelley
2022-06-09introduce std.debug.TraceAndrew Kelley
And use it to debug a LazySrcLoc in stage2 that is set to a bogus value. The actual fix in this commit is: ```diff - try sema.emitBackwardBranch(&child_block, call_src); + try sema.emitBackwardBranch(block, call_src); ```
2022-06-07stage2: better codegen for byte-aligned packed struct fieldsAndrew Kelley
* Sema: handle overaligned packed struct field pointers * LLVM: handle byte-aligned packed struct field pointers
2022-06-07stage2 llvm: fix float/int conversion compiler-rt callsVeikka Tuominen
2022-06-07stage2: implement asm with multiple outputsVeikka Tuominen
2022-06-07LLVM: handle extern function name collisionsAndrew Kelley
Zig allows multiple extern functions with the same name, and the backends have to handle this possibility. For LLVM, we keep a sparse map of collisions, and then resolve them in flushModule(). This introduces some technical debt that will have to be resolved when adding incremental compilation support to the LLVM backend.
2022-06-05stage2: implement the new "try" ZIR/AIR instructionAndrew Kelley
Implements semantic analysis for the new try/try_inline ZIR instruction. Adds the new try/try_ptr AIR instructions and implements them for the LLVM backend. Fixes not calling rvalue() for tryExpr in AstGen. This is part of an effort to implement #11772.
2022-06-03stage2: ignore asm inputs named `_`Veikka Tuominen
This is a hacky solution but the entire asm syntax is supposed to be reworked anyways.
2022-06-01LLVM: convert two ArrayLists into a MultiArrayListAndrew Kelley
2022-05-31LLVM: add target-cpu and target-features fn attributesAndrew Kelley
2022-05-31LLVM: pass slices as ptr/len comboAndrew Kelley
LLVM optimization passes handle this better, and it allows Zig to specify pointer parameter attributes such as readonly, nonnull, noalias, and alignment. closes #561