aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/spirv.zig
AgeCommit message (Collapse)Author
2023-09-23spirv: fix source line numbersRobin Voetter
2023-09-23spirv: enable passing testsRobin Voetter
2023-09-23spirv: constant elem ptrRobin Voetter
2023-09-23spirv: air sliceRobin Voetter
2023-09-23spirv: air wrap_errunion_payloadRobin Voetter
2023-09-23spirv: air unwrap_errunion_payloadRobin Voetter
2023-09-23spirv: air is_err, is_non_errRobin Voetter
2023-09-23spirv: generate module initializerRobin Voetter
2023-09-23spirv: air array_elem_val using hackRobin Voetter
SPIR-V doesn't support true element indexing, so we probably need to switch over to isByRef like in llvm for this to work properly. Currently a temporary is used, which at least seems to work.
2023-09-23spirv: air aggregate_init for arrayRobin Voetter
2023-09-23spirv: air array_to_sliceRobin Voetter
2023-09-23spirv: air sub_with_overflowRobin Voetter
2023-09-23spirv: air union_initRobin Voetter
2023-09-23spirv: air set_union_tag + improve load()/store()Robin Voetter
2023-09-23spirv: air struct_field_ptr for unionsRobin Voetter
2023-09-23spirv: air struct_field_val for unionsRobin Voetter
2023-09-23spirv: add names to globals and initializersRobin Voetter
2023-09-23spirv: emit OpLogical(Not)Equal for comparing boolsRobin Voetter
2023-09-23spirv: emit OpNot for arithmetic notRobin Voetter
2023-09-23spirv: fix store of undefRobin Voetter
2023-09-23spirv: fix type_map use-after-realloc issuesRobin Voetter
2023-09-23spirv: make construct(Struct|Array) use the Function storage classRobin Voetter
2023-09-23spirv: always emit unsigned integersRobin Voetter
This is required for SPIR-V in Kernel mode. The Intel implementation just didn't care about this fact.
2023-09-23spirv: fixesRobin Voetter
2023-09-23spirv: remove indirect constant loweringRobin Voetter
It is stupid and I hate it.
2023-09-23spirv: put global var initializers in functionsRobin Voetter
2023-09-23spirv: lower union initialization at runtimeRobin Voetter
2023-09-23spirv: lower struct aggregate initialization at runtimeRobin Voetter
2023-09-23spirv: lower array aggregate at runtimeRobin Voetter
2023-09-23spirv: lower opt constantsRobin Voetter
2023-09-23spirv: lower ptr constantsRobin Voetter
2023-09-23spirv: lower enum_tag constantsRobin Voetter
2023-09-23spirv: assign type names to (error) unionsRobin Voetter
2023-09-23spirv: construct error union at runtimeRobin Voetter
2023-09-23spirv: add type_map to map AIR types to SPIR-V typesRobin Voetter
This will help us both to make the implementation a little more efficient by caching emission for certain types like structs, and also allow us to attach extra information about types that we can use while lowering without performing a search over the entire type tree for some property.
2023-09-23spirv: disable failing testsRobin Voetter
2023-09-21compiler: move struct types into InternPool properAndrew Kelley
Structs were previously using `SegmentedList` to be given indexes, but were not actually backed by the InternPool arrays. After this, the only remaining uses of `SegmentedList` in the compiler are `Module.Decl` and `Module.Namespace`. Once those last two are migrated to become backed by InternPool arrays as well, we can introduce state serialization via writing these arrays to disk all at once. Unfortunately there are a lot of source code locations that touch the struct type API, so this commit is still work-in-progress. Once I get it compiling and passing the test suite, I can provide some interesting data points such as how it affected the InternPool memory size and performance comparison against master branch. I also couldn't resist migrating over a bunch of alignment API over to use the log2 Alignment type rather than a mismash of u32 and u64 byte units with 0 meaning something implicitly different and special at every location. Turns out you can do all the math you need directly on the log2 representation of alignments.
2023-09-12InternPool: prevent anon struct UAF bugs with type safetyAndrew Kelley
Instead of using actual slices for InternPool.Key.AnonStructType, this commit changes to use Slice types instead, which store a long-lived index rather than a pointer. This is a follow-up to 7ef1eb1c27754cb0349fdc10db1f02ff2dddd99b.
2023-08-22compiler: move unions into InternPoolAndrew Kelley
There are a couple concepts here worth understanding: Key.UnionType - This type is available *before* resolving the union's fields. The enum tag type, number of fields, and field names, field types, and field alignments are not available with this. InternPool.UnionType - This one can be obtained from the above type with `InternPool.loadUnionType` which asserts that the union's enum tag type has been resolved. This one has all the information available. Additionally: * ZIR: Turn an unused bit into `any_aligned_fields` flag to help semantic analysis know whether a union has explicit alignment on any fields (usually not). * Sema: delete `resolveTypeRequiresComptime` which had the same type signature and near-duplicate logic to `typeRequiresComptime`. - Make opaque types not report comptime-only (this was inconsistent between the two implementations of this function). * Implement accepted proposal #12556 which is a breaking change.
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-01spirv: fix up todos & errors from intern pool changesRobin Voetter
This replaces the implementation of constant() which one that is directly based on the intern pool rather than the Zig type tag too.
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
2023-06-23spirv: fix a few conflicts caused by intern-poolAli Chraghi
2023-06-20Type: delete legacy allocation functionsJacob Young
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19compiler: rename "@XToY" to "@YFromX", zig fmt: rewrite themEric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-17mem: rename align*Generic to mem.align*Motiejus Jakštys
Anecdote 1: The generic version is way more popular than the non-generic one in Zig codebase: git grep -w alignForward | wc -l 56 git grep -w alignForwardGeneric | wc -l 149 git grep -w alignBackward | wc -l 6 git grep -w alignBackwardGeneric | wc -l 15 Anecdote 2: In my project (turbonss) that does much arithmetic and alignment I exclusively use the Generic functions. Anecdote 3: we used only the Generic versions in the Macho Man's linker workshop.
2023-06-10compiler: eliminate Decl.value_arena and Sema.perm_arenaAndrew Kelley
The main motivation for this commit is eliminating Decl.value_arena. Everything else is dominoes. Decl.name used to be stored in the GPA, now it is stored in InternPool. It ended up being simpler to migrate other strings to be interned as well, such as struct field names, union field names, and a few others. This ended up requiring a big diff, sorry about that. But the changes are pretty nice, we finally start to take advantage of InternPool's existence. global_error_set and error_name_list are simplified. Now it is a single ArrayHashMap(NullTerminatedString, void) and the index is the error tag value. Module.tmp_hack_arena is re-introduced (it was removed in eeff407941560ce8eb5b737b2436dfa93cfd3a0c) in order to deal with comptime_args, optimized_order, and struct and union fields. After structs and unions get moved into InternPool properly, tmp_hack_arena can be deleted again.
2023-06-10InternPool: remove memoized_declAndrew Kelley
This is neither a type nor a value. Simplifies `addStrLit` as well as the many places that switch on `InternPool.Key`. This is a partial revert of bec29b9e498e08202679aa29a45dab2a06a69a1e.