aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
AgeCommit message (Collapse)Author
2023-06-10stage2: implement intTagType logicAndrew Kelley
This commit changes a lot of `*const Module` to `*Module` to make it work, since accessing the integer tag type of an enum might need to mutate the InternPool by adding a new integer type into it. An alternate strategy would be to pre-heat the InternPool with the integer tag type when creating an enum type, which would make it so that intTagType could accept a const Module instead of a mutable one, asserting that the InternPool already had the integer tag type.
2023-06-10stage2: bug fixes related to Type/Value/InternPoolAndrew Kelley
2023-06-10Replace uses of Value.zero, Value.one, Value.negative_onemlugg
This is a bit nasty, mainly because Type.onePossibleValue is now errorable, which is a quite viral change.
2023-06-10wip: progress towards compiling testsmlugg
2023-06-10stage2: move integer values to InternPoolAndrew Kelley
2023-06-10LLVM backend: update integer constant lowering for InternPoolAndrew Kelley
2023-06-10InternPool: add a slice encodingAndrew Kelley
This uses the data field to reference its pointer field type, which allows for efficient and infallible access of a slice type's pointer type.
2023-06-10stage2: migrate many pointer types to the InternPoolAndrew Kelley
2023-06-10stage2: move undef, unreach, null values to InternPoolAndrew Kelley
2023-06-10stage2: move many Type encodings to InternPoolAndrew Kelley
Notably, `vector`. Additionally, all alternate encodings of `pointer`, `optional`, and `array`.
2023-06-10Type.isSlice: make it InternPool awareAndrew Kelley
2023-06-10stage2: move most simple values to InternPoolAndrew Kelley
2023-06-10stage2: move most simple types to InternPoolAndrew Kelley
2023-06-10stage2: move float types to InternPoolAndrew Kelley
2023-06-10InternPool: implement isSinglePointerAndrew Kelley
2023-06-10stage2: add `interned` AIR tagAndrew Kelley
This required additionally passing the `InternPool` into some AIR methods. Also, implement `Type.isNoReturn` for interned types.
2023-06-10stage2: start the InternPool transitionAndrew Kelley
Instead of doing everything at once which is a hopelessly large task, this introduces a piecemeal transition that can be done in small increments at a time. This is a minimal changeset that keeps the compiler compiling. It only uses the InternPool for a small set of types. Behavior tests are not passing. Air.Inst.Ref and Zir.Inst.Ref are separated into different enums but compile-time verified to have the same fields in the same order. The large set of changes is mainly to deal with the fact that most Type and Value methods now require a Module to be passed in, so that the InternPool object can be accessed.
2023-06-06llvm: stop generating FPU code if there is no FPUDavid Gonzalez Martin
Fixes https://github.com/ziglang/zig/issues/14465 For aarch64, LLVM was crashing because Zig commands it to generate FPU code even when there is no FPU present. This commit implements the necessary checks to avoid this undesired situation and aarch64 can be compiled again with no FPU.
2023-05-26std.Target adjustmentsVeikka Tuominen
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi * double isn't always 8 bits * AVR uses 1-byte alignment for everything in GCC
2023-05-25llvm: fix vector type in vector_store_elemVeikka Tuominen
Closes #15848
2023-05-23Merge pull request #15235 from Vexu/safetyVeikka Tuominen
add runtime safety for noreturn function returning
2023-05-22llvm: also generate metadata for extern global variablesTw
Signed-off-by: Tw <tw19881113@gmail.com>
2023-05-16add runtime safety for noreturn function returningVeikka Tuominen
Closes #15221
2023-05-12Optimize access of array member in a structure.shwqf
2023-05-11Merge pull request #15639 from jacobly0/signed-modAndrew Kelley
llvm/cbe: fix signed `@mod`/`@divFloor` computations
2023-05-10llvm: fix `@max`/`@min` of unsupported float typesJacob Young
Closes #15611
2023-05-10llvm/cbe: fix signed `@mod`/`@divFloor` computationsJacob Young
Closes #15636
2023-04-28LLVM backend: optimize memset with comptime-known elementAndrew Kelley
When the element is comptime-known, we can check if it has a repeated byte representation. In this case, `@memset` can be lowered with the LLVM intrinsic rather than with a loop.
2023-04-28llvm backend: fix memset with byref element valueAndrew Kelley
2023-04-28llvm backend: fix lowering of memsetAndrew Kelley
The bitcast of ABI size 1 elements was problematic for some types.
2023-04-25Sema: fix memcpy alias safety incorrect mathAndrew Kelley
Previously it was not multiplying by the element ABI size. Now, it uses ptr_add instructions which do math based on the element type.
2023-04-25stage2: introduce store_safe AIR instructionAndrew Kelley
store: The value to store may be undefined, in which case the destination memory region has undefined bytes after this instruction is evaluated. In such case ignoring this instruction is legal lowering. store_safe: Same as `store`, except if the value to store is undefined, the memory region should be filled with 0xaa bytes, and any other safety metadata such as Valgrind integrations should be notified of this memory region being undefined.
2023-04-25LLVM backend: support non-byte-sized memsetAndrew Kelley
Also introduce memset_safe AIR tag and support it in C backend and LLVM backend.
2023-04-25update `@memcpy` to require equal src and dest lensAndrew Kelley
* Sema: upgrade operands to array pointers if possible when emitting AIR. * Implement safety checks for length mismatch and aliasing. * AIR: make ptrtoint support slice operands. Implement in LLVM backend. * C backend: implement new `@memset` semantics. `@memcpy` is not done yet.
2023-04-25change semantics of `@memcpy` and `@memset`Andrew Kelley
Now they use slices or array pointers with any element type instead of requiring byte pointers. This is a breaking enhancement to the language. The safety check for overlapping pointers will be implemented in a future commit. closes #14040
2023-04-21cbe: fix issues with atomic floatsJacob Young
Since the Zig language documentation claims support for `.Min` and `.Max` in `@atomicRmw` with floats, allow in Sema and implement for both the llvm and C backends.
2023-04-21Merge pull request #15355 from mlugg/feat/liveness-control-flowAndrew Kelley
Liveness: control flow analysis and other goodies
2023-04-20fixes to the previous commitAndrew Kelley
* CompileStep: Avoid calling producesPdbFile() to determine whether the option should be respected. If the user asks for it, put it on the command line and let the Zig CLI deal with it appropriately. * Make the namespace of `std.dwarf.Format.dwarf32` no longer have a redundant "dwarf" in it. * Add `zig cc` integration for `-gdwarf32` and `-gdwarf64`. * Toss in a bonus bug fix for `-gdwarf-2`, `-gdwarf-3`, etc. * Avoid using default init values for struct fields unnecessarily. * Add missing cache hash addition for the new option.
2023-04-20Expose an option for producing 64-bit DWARF formatDavid Gonzalez Martin
This commit enables producing 64-bit DWARF format for Zig executables that are produced through the LLVM backend. This is achieved by exposing both command-line flags and CompileStep flags. The production of the 64-bit format only affects binaries that use the DWARF format and it is disabled on MacOS due to it being problematic. This commit, despite generating the interface for the Zig user to be able to tell the compile which format is wanted, is just implemented for the LLVM backend, so clang and the self-hosted backends will need this to be implemented in a future commit. This is an effort to work around #7962, since the emission of the 64-bit format automatically produces 64-bit relocations. Further investigation will be needed to make DWARF 32-bit format to emit bigger relocations when needed and not make the linker angry.
2023-04-20Liveness: avoid emitting unused instructions or marking their operands as usedmlugg
Backends want to avoid emitting unused instructions which do not have side effects: to that end, they all have `Liveness.isUnused` checks for many instructions. However, checking this in the backends avoids a lot of potential optimizations. For instance, if a nested field is loaded, then the first field access would still be emitted, since its result is used by the next access (which is then unreferenced). To elide more instructions, Liveness can track this data instead. For operands which do not have to be lowered (i.e. are not side effecting and are not something special like `arg), Liveness can ignore their operand usages, and push the unused information further up, potentially marking many more instructions as unreferenced. In doing this, I also uncovered a bug in the LLVM backend relating to discarding the result of `@cVaArg`, which this change fixes. A behaviour test has been added to cover it.
2023-04-20llvm: emit metadata for exported global variables (#15349)Tw
* llvm: emit metadata for global variable One use case is to genearte BTF information from global variable's metadata. Signed-off-by: Tw <weii.tan>
2023-04-09amdgpu,nvptx: unify kernel calling conventionsRobin Voetter
AmdgpuKernel and NvptxKernel are unified into a Kernel calling convention. There is really no reason for these to be separate; no backend is allowed to emit the calling convention of the other. This is in the same spirit as the .Interrupt calling convention lowering to different LLVM calling conventions, and opens the way for SPIR-V kernels to be exported using the Kernel calling convention.
2023-04-05Merge remote-tracking branch 'origin/master' into llvm16Andrew Kelley
2023-04-02Sema: defer stores to inferred allocsJacob Young
This lets us generate the store with knowledge of the type to be stored. Therefore, we can avoid generating garbage Air with stores through pointers to comptime-only types which backends cannot lower. Closes #13410 Closes #15122
2023-03-30new builtins: @workItemId, @workGroupId, @workGroupSizeRobin Voetter
* @workItemId returns the index of the work item in a work group for a dimension. * @workGroupId returns the index of the work group in the kernel dispatch for a dimension. * @workGroupSize returns the size of the work group for a dimension. These builtins are mainly useful for GPU backends. They are currently only implemented for the AMDGCN LLVM backend.
2023-03-30llvm/bpf: disable llvm builtins for bpf targetTw
As bpf program has no global section for constant values (especially strings), so use llvm's builtins (like memcpy, memset, etc) will lead to compilation failure (something like this: A call to built-in function 'memcpy' is not supported.) Signed-off-by: Tw <tw19881113@gmail.com>
2023-03-30llvm: fix crashes when loading a struct fieldJacob Young
The result of buildStructGEP is not always a GEP (sorry), so we can't use getGEPResultElementType on it. Closes #14641
2023-03-28Sema: fix empty slice pointer valueJacob Young
We just checked that inst_child_ty was effectively a zero-bit type, so it is certainly not the non-zero alignment we are looking for. Closes #15085
2023-03-21llvm: fix lowering packed union initiated to zero-bit valueVeikka Tuominen
Closes #14980
2023-03-17Merge remote-tracking branch 'origin/master' into llvm16Andrew Kelley