aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
AgeCommit message (Collapse)Author
2023-08-08llvm: remove dependence on llvm data layout alignmentJacob Young
by just using the zig alignment and letting llvm promote it as desired
2023-08-08llvm: fix alias issuesJacob Young
2023-08-08llvm: finish converting globalsJacob Young
2023-08-08Builder: fix enough bugs to pass the behavior testsJacob Young
without using any information from the LLVM API
2023-08-08llvm: cleanup even more unused LLVM API bindingsJacob Young
2023-08-08llvm: finish converting instructionsJacob Young
2023-08-08llvm: finish converting intrinsicsJacob Young
2023-08-08llvm: convert vector reduction intrinsicsJacob Young
Scratch that thing I said about one pass. :)
2023-08-08llvm: finish converting attributes to use Builder and the C LLVM APIJacob Young
2023-08-08llvm: convert intrinsics to using `Builder`Jacob Young
2023-08-06Use new LLVM IR builder API in bit op loweringantlilja
2023-08-06Use new LLVM builder API in buildFloatOPantlilja
2023-08-01llvm: fix data layout calculation for experimental llvm targetsJacob Young
Closes #16616
2023-07-31std: finish cleanup up asmJacob Young
This also required implementing the necessary syntax in the x86_64 backend.
2023-07-29Merge pull request #16611 from xxxbxxx/packed-structJacob Young
codegen: fix various packed struct issues Closes #16609 Closes #15337
2023-07-29llvm: support read-write output constraints in assemblyJacob Young
Closes #15227
2023-07-29codegen: fix access to byte-aligned nested packed struct elemsXavier Bouchoux
When acessing a packed struct member via a byte aligned ptr (from the optimisation in Sema.structFieldPtrByIndex()) the codegen must apply the parent ptr packed_offset in addition to the field offset itself. resolves https://github.com/ziglang/zig/issues/16609
2023-07-29llvm: partial fix of store undefined to packed result locationXavier Bouchoux
prefer marking too few undefined bits, rather than too many that may overwrite nearby values. partially resolves https://github.com/ziglang/zig/issues/15337
2023-07-28llvm: fix SysV C abi for structs smaller than two eightbytesJacob Young
Closes #16038 Closes #16288
2023-07-27LLVM: always add argument attributes to callsAndrew Kelley
These are needed for correctness. There's no reason to only add them for function pointers. closes #16290
2023-07-26llvm: fix data layout on iosJacob Young
Closes #16549
2023-07-25codegen/llvm: fix memset with vectors smaller than one byteXavier Bouchoux
The special case to take advantage of llvm's intrinsic was generating invalid llvm ir: ``` Invalid bitcast %60 = bitcast <2 x i2> %59 to i8, !dbg !3122 thread 145453 panic: LLVM module verification failed ```
2023-07-23llvm: convert global assemblyJacob Young
2023-07-23llvm: convert inline assemblyJacob Young
Also, implement TODOs from a previous commit.
2023-07-23llvm: fix datalayout generation for more targetsJacob Young
Closes #16482
2023-07-23llvm: convert attributes and non-intrinsic callsJacob Young
2023-07-20llvm: cleanup LLVM IR dumpingJacob Young
2023-07-19llvm: fix various crashesJacob Young
2023-07-19llvm: minor fixesJacob Young
2023-07-19llvm: convert most instructionsJacob Young
2023-07-19llvm: convert cursor positioningJacob Young
2023-07-19llvm: convert basic block creationJacob Young
2023-07-19llvm: finish converting constantsJacob Young
2023-07-19llvm: cleanup management and implement more const functionsJacob Young
2023-07-19llvm: cleanup initJacob Young
2023-07-19llvm: finish converting `lowerValue`Jacob Young
2023-07-19llvm: convert all calls to `constInt`Jacob Young
2023-07-19llvm: remove more usages of `llvm.Type`Jacob Young
2023-07-19llvm: finish converting `lowerType`Jacob Young
2023-07-19llvm: compute data layout without help like a grownup compilerJacob Young
2023-07-19llvm: start tracking more things without relying on the llvm apiJacob Young
2023-07-18compiler: rework inferred error setsAndrew Kelley
* move inferred error sets into InternPool. - they are now represented by pointing directly at the corresponding function body value. * inferred error set working memory is now in Sema and expires after the Sema for the function corresponding to the inferred error set is finished having its body analyzed. * error sets use a InternPool.Index.Slice rather than an actual slice to avoid lifetime issues.
2023-07-18rework generic function callsAndrew Kelley
Abridged summary: * Move `Module.Fn` into `InternPool`. * Delete a lot of confusing and problematic `Sema` logic related to generic function calls. This commit removes `Module.Fn` and replaces it with two new `InternPool.Tag` values: * `func_decl` - corresponding to a function declared in the source code. This one contains line/column numbers, zir_body_inst, etc. * `func_instance` - one for each monomorphization of a generic function. Contains a reference to the `func_decl` from whence the instantiation came, along with the `comptime` parameter values (or types in the case of `anytype`) Since `InternPool` provides deduplication on these values, these fields are now deleted from `Module`: * `monomorphed_func_keys` * `monomorphed_funcs` * `align_stack_fns` Instead of these, Sema logic for generic function instantiation now unconditionally evaluates the function prototype expression for every generic callsite. This is technically required in order for type coercions to work. The previous code had some dubious, probably wrong hacks to make things work, such as `hashUncoerced`. I'm not 100% sure how we were able to eliminate that function and still pass all the behavior tests, but I'm pretty sure things were still broken without doing type coercion for every generic function call argument. After the function prototype is evaluated, it produces a deduplicated `func_instance` `InternPool.Index` which can then be used for the generic function call. Some other nice things made by this simplification are the removal of `comptime_args_fn_inst` and `preallocated_new_func` from `Sema`, and the messy logic associated with them. I have not yet been able to measure the perf of this against master branch. On one hand, it reduces memory usage and pointer chasing of the most heavily used `InternPool` Tag - function bodies - but on the other hand, it does evaluate function prototype expressions more than before. We will soon find out.
2023-07-10add stand alone test to verify bulk-memory featuresLuuk de Gram
This adds a standalone test case to ensure the runtime does not trap when performing a memory.copy or memory.fill instruction while the destination or source address is out-of-bounds and the length is 0.
2023-07-08llvm: add safety-check for Wasm memsetLuuk de Gram
When lowering the `memset` instruction, LLVM will lower it to WebAssembly's `memory.fill` instruction when the bulk-memory feature is enabled. This instruction will trap when the destination address is out-of-bounds. By Zig's semantics, it is valid to have an invalid pointer when the length is 0. To prevent runtimes from trapping, we add a safety-check for slices to only lower to a memset instruction when the length is larger than 0.
2023-07-08llvm: add safety-check for Wasm memcpyLuuk de Gram
When lowering the `memcpy` instruction, LLVM will lower it to WebAssembly's `memory.copy` instruction when the bulk-memory feature is enabled. This instruction will trap when the destination or source pointer is out-of-bounds. By Zig's semantics, it is valid to have an invalid pointer when the length is 0. To prevent runtimes from trapping, we add a safety-check for slices to only lower to a memcpy instruction when the length is larger than 0.
2023-07-01llvm: cast optional null ptr representation to generic address spaceRobin Voetter
The panic handler expects that this value is represented with the generic address space, so cast the global to the generic address- space before caching and returning the value.
2023-06-27Air: store interned values in Air.Inst.Refmlugg
Previously, interned values were represented as AIR instructions using the `interned` tag. Now, the AIR ref directly encodes the InternPool index. The encoding works as follows: * If the ref matches one of the static values, it corresponds to the same InternPool index. * Otherwise, if the MSB is 0, the ref corresponds to an InternPool index. * Otherwise, if the MSB is 1, the ref corresponds to an AIR instruction index (after removing the MSB). Note that since most static InternPool indices are low values (the exceptions being `.none` and `.var_args_param_type`), the first rule is almost a nop.
2023-06-25compiler: start moving safety-checks into backendsAndrew Kelley
This actually used to be how it worked in stage1, and there was this issue to change it: #2649 So this commit is a reversal to that idea. One motivation for that issue was avoiding emitting the panic handler in compilations that do not have any calls to panic. This commit only resolves the panic handler in the event of a safety check function being emitted, so it does not have that flaw. The other reason given in that issue was for optimizations that elide safety checks. It's yet to be determined whether that was a good idea or not; this can get re-explored when we start adding optimization passes to AIR. This commit adds these AIR instructions, which are only emitted if `backendSupportsFeature(.safety_checked_arithmetic)` is true: * add_safe * sub_safe * mul_safe It removes these nonsensical AIR instructions: * addwrap_optimized * subwrap_optimized * mulwrap_optimized The safety-checked arithmetic functions push the burden of invoking the panic handler into the backend. This makes for a messier compiler implementation, but it reduces the amount of AIR instructions emitted by Sema, which reduces time spent in the secondary bottleneck of the compiler. It also generates more compact LLVM IR, reducing time spent in the primary bottleneck of the compiler. Finally, it eliminates 1 stack allocation per safety-check which was being used to store the resulting tuple. These allocations were going to be annoying when combined with suspension points.
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change