aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
2023-05-11spirv: fix use-after-realloc in resolveType()Robin Voetter
The pointer to a slot in a hash map was fetched before a recursive call. If the hash map's size changed during the recursive call, this would write to an invalid pointer. The solution is to use an index instead of a pointer. Note that care must be taken that resolved types (from the type_cahce) must not be accessed, as they might be incomplete during this operation.
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-05-10cbe: use `Assignment` in `airSplat`Jacob Young
2023-05-06cbe: fix typosJacob Young
2023-04-28C backend: take advantage of Assignment abstraction in airMemsetAndrew Kelley
2023-04-28C backend: fix ptr comparison of array ptrs when one is null-terminatedAndrew Kelley
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-04-28C backend: fix memset for structs and arraysAndrew Kelley
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-26Merge pull request #15452 from mlugg/zig-cbe-optAndrew Kelley
CBE: minor optimizations to output source
2023-04-26Merge pull request #15278 from ziglang/memcpy-memsetAndrew Kelley
change semantics of `@memcpy` and `@memset`
2023-04-26CBE: minor optimizations to output sourcemlugg
2023-04-25C backend: fix lowering comparison when array ptr meets ptrAndrew Kelley
Pointer comparisons were triggering `-Wcompare-distinct-pointer-types` before this fix, which adds `(void*)` casts if the lhs type and rhs type do not match pointer sizeness.
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-25C backend: use ++ instead of += for airMemsetAndrew Kelley
It does the same thing but has fewer bytes in the output.
2023-04-25C backend: fix memset for loop loweringAndrew Kelley
Previously, this code casted the array pointer to u8 pointer, but I removed that in a different commit. This commit restores the cast, but instead of hard-coding u8, it uses the destination element pointer, since memset now supports arbitrary element types.
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-25C backend: implement new memcpy and inttoptr semanticsAndrew Kelley
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-25cbe: fix mutability issues with builtin test_functionsJacob Young
2023-04-25cbe: implement @externJacob Young
2023-04-25cbe: remove unused arenaJacob Young
2023-04-21cbe: fix local aliasing issues in atomic opsJacob Young
2023-04-21zig.h: fix float negationJacob Young
2023-04-21cbe: implement 128-bit atomics supportJacob Young
* Disable 128-bit atomics for x86_64 generic (currently also baseline) because they require heavy abi agreement to correctly lower. ** This is a breaking change ** * Enable 128-bit atomics for aarch64 in Sema since it just works.
2023-04-21cbe: fix atomic float min/maxJacob Young
These need `zig_atomic`, unlike int min/max.
2023-04-21cbe: fix float casts involving f16Jacob Young
Fixes bugs with a previous fix to the f16 abi on x86 darwin.
2023-04-21cbe: fix remaining aarch64 issuesJacob Young
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-21cbe: enable CI for std testsJacob Young
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-20Begin integrating new liveness analysis into remaining backendsmlugg
2023-04-20cbe: integrate new Liveness behaviourmlugg
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-20Liveness: control flow analysismlugg
This is a partial rewrite of Liveness, so has some other notable changes: - A proper multi-pass system to prevent code duplication - Better logging - Minor bugfixes
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-13add c_char typeAndrew Kelley
closes #875
2023-04-09spirv: Do not generate the Alignment attribute on pointers for nowRobin Voetter
It seems that some implementations may have problems with these right now, like Intel and Rusticl. In theory, these attributes should be superficial on the pointer type, as alignment guarantees are also added via the alignment option of the OpLoad and OpStore instructions. Therefore, get rid of them for now.
2023-04-09spirv: allow global, constant address spacesRobin Voetter
These should actually just work fine in SPIR-V. They are mapped to CrossWorkgroup and UniformConstant respectively.
2023-04-09spirv: deny global OpVariable in inline asmRobin Voetter
This feature requires to be integrated with the mechanism that orders the global variables, and that is not yet in place.
2023-04-09spirv: deny OpEntryPoint in asmRobin Voetter
Kernels should be exported by marking the kernel using callconv(.Kernel) and exporting it as a regular function.
2023-04-09spirv: export functions with .Kernel callconv as entry pointRobin Voetter
Exported functions which have the .Kernel calling convention are now exported as entry point. This also works with @export.