aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
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-09spirv: emit interface variables for entry pointsRobin Voetter
Also actually implement generating the OpEntryPoint instructions.
2023-04-09spirv: add decl dependencies for functions alsoRobin Voetter
Entry points need to be attributed with a complete list of global variables that they use. To that end, the global dependencies mechanism is extended to also allow functions - when flushing the module, the list of dependencies is examined to generate this list of global variable result-ids.
2023-04-09spirv: temporarily emit test kernelsRobin Voetter
SPIR-V cannot represent function pointers without extensions that no vendor implements. For the time being, generate a test kernel for each error, so that we can at least run SOME tests. In the future we may be able to emulate function pointers in some way, but that is not today.
2023-04-09spirv: implement error set and error unionsRobin Voetter
Implements lowering types and constants for error sets and error unions.
2023-04-09spirv: improve linking globalsRobin Voetter
SPIR-V globals must be emitted in order, so that any declaration precedes usage. Zig, however, generates globals in random order. To this end we keep for each global a list of dependencies and perform a topological sort when flushing the module.
2023-04-09spirv: overhaul constant loweringRobin Voetter
Lowering constants is currently not really compatible with unions. In this commit, constant lowering is drastically overhauled: instead of playing nice and generating SPIR-V constant representations for everything directly, we're just going to treat globals as an untyped bag of bytes ( or rather, SPIR-V 32-bit words), which we cast to the desired type at usage. This is similar to how Rust generates constants in its LLVm backend.
2023-04-09spirv: union types/constantsRobin Voetter
Implements lowering union types and constants in the SPIR-V backend.
2023-04-09spirv: optional constantsRobin Voetter
Implements lowering optional constants in the SPIR-V backend.
2023-04-09spirv: improve genConstant usageRobin Voetter
This little wrapper function allocates a result-id for us, so that we don't have to do that.
2023-04-09spirv: slice constantsRobin Voetter
Implements lowering slice constants in the SPIR-V backend
2023-04-09spirv: string literalsRobin Voetter
Implements lowering string literal constants in the SPIR-V backend
2023-04-09spirv: optional typesRobin Voetter
Implements lowering optional types in the SPIR-V backend.
2023-04-09spirv: generic global pointersRobin Voetter
Similar to function locals, taking the address of a global that does not have an explicit address space assigned to it should result in a generic pointer, not a global pointer. Also similar to function locals, they cannot be generated into the generic storage class, and so are generated into the global storage class and then cast to a generic pointer, using OpSpecConstantOp. Note that using OpSpecConstantOp results is only allowed by a hand full of other OpSpecConstant instructions - which is why we generate constant structs using OpSpecConstantComposite: These may use OpVariable and OpSpecConstantOp results, while OpConstantComposite may not.
2023-04-09spirv: initial decl_ref pointer generationRobin Voetter
Starts lowering decl_ref Pointer constants.
2023-04-09spirv: generate code directly in updateFunc/updateDeclRobin Voetter
This cloneAir/cloneLiveness idea used to ignore Zig's internals has proven buggy. Instead, just generate the code directly from updateFunc and updateDecl as the other backends do, but pretend that Zig is not an incremental compiler. The SPIR-V backend will for the time being not support this.
2023-04-09spirv: start lowering non-function declsRobin Voetter
Start to lower decls which are not functions. These generate an OpVariable instruction by which they can be used later on.
2023-04-09spirv: convert bools on load/storeRobin Voetter
Bools have a different immediate representation and memory representation - which means that they must be converted every time a bool is loaded from or stored into memory.
2023-04-09spirv: make locals generic pointersRobin Voetter
Taking the address of a local variable should result in a generic pointer - too much code breaks if we do not do this. We cannot lower locals into the generic storage class directly though, so instead, lower the variables into the Function storage class implicitly, and convert the pointer to a generic pointer. Also Correct OpInboundsAccessChain generation (we only need the one index).
2023-04-09spirv: introduce type/value representationsRobin Voetter
There are two main ways in which a value can be stored: "Direct", as it will be operated on as an immediate value, and "indirect", as it is stored in memory. Some types need a different representation here: Bools, for example, are opaque in SPIR-V, and so these need to have a different representation in memory. The bool operations are not easily interchangable with integer operations, though, so they need to be OpTypeBool as immediate value.
2023-04-09spirv: more fixes and improvementsRobin Voetter
- Formatting. - Improve `decorate` helper function to generate a decoration for a result-id. - Reorder some functions in a more logical way
2023-04-09spirv: make IdResultType and IdRef weak aliases of IdResultRobin Voetter
Previously they were strong aliases, but as these types are used quite intermittendly it resulted in a lot of toRef() calls. Removing them improves readability a bit.
2023-04-09spirv: some fixes and improvementsRobin Voetter
- Adds the Int8. Int16, Int64 and GenericPointer capabilities. TODO: This should integrate with the feature system. - Default some struct fields of SPIR-V types so that we dont need to type them all the time. - Store struct field name's in SPIR-V types, and generate the OpMemberName decoration if they are non-null. - Also add the field names to the actual SPIR-V types. - Generate OpName for functions.
2023-04-09spirv: switch_br loweringRobin Voetter
Implements lowering switch statements in the SPIR-V backend.
2023-04-09spirv: left shiftRobin Voetter
Implements the AIR left_shift operation for the SPIR-V backend.
2023-04-09spirv: struct field ptr index, ptr elem ptrRobin Voetter
Implements the ptr_elem_ptr and struct_field_ptr_index_* AIR instructions for the SPIR-V backend.
2023-04-09spirv: div, rem, intcast, some strange integer maskingRobin Voetter
Implements the div-family and intcast AIR instructions, and starts implementing a mechanism for masking the value of 'strange' integers before they are used in an operation that does not hold under modulo.
2023-04-09spirv: (some) array and struct constantsRobin Voetter
Starts implementing constant lowering for some array and struct constants. In particular, TODO are packed structs.
2023-04-09spirv: enum values, struct_field_val, ret_ptr, ret_loadRobin Voetter
Implements lowering for enum constants, as well as the struct_field_val, ret_ptr, and ret_load AIR instructions.
2023-04-09spirv: add_with_overflowRobin Voetter
Implements lowering for the add_with_overflow AIR instructions. Also implements a helper function, simpleStructType, to quickly generate a SPIR-V structure type without having to do the whole allocation dance.
2023-04-09spirv: slice operationsRobin Voetter
This commit adds support for SPIR-V code generation for the following AIR instructions: - slice_ptr - slice_len - slice_elem_ptr - slice_elem_val
2023-04-09spirv: add liveness checksRobin Voetter
When a result of a pure instruction is not used, it also does not need to be generated. The other backends already implement these checks, they were ignored in SPIR-V up until now. New instructions added in the future should have these be implemented from the start.
2023-04-09spirv: slice typesRobin Voetter
Implements type lowering for slices.
2023-04-09spirv: array, structs, bitcast, callRobin Voetter
Implements type lowering for arrays and structs, and implements instruction lowering for bitcast and call. Bitcast currently naively maps to the OpBitcast instruction - this is only valid for some primitive types, and should be improved to work with composites.
2023-04-09spirv: emit OpName for some primitive typesRobin Voetter
OpName instructions assign a debug name to a type. Some basic types - bool, void, ints, and floats are given a debug name this way. TODO is to extend this to the other types.
2023-04-09spirv: improve storage efficiency for integer and float typesRobin Voetter
In practice there are only a few variations of these types allowed, so it kind-of makes sense to write them all out. Because the types are hashed this does not actually save all that many bytes in the long run, though. Perhaps some of these types should be pre-registered?
2023-04-09spirv: make Type.Ref strongerRobin Voetter
Making Type.Ref an unbounded enum rather than a simple integer ensures that we don't accidently confuse this token for another type.
2023-04-09spirv: enum typeRobin Voetter
This gives the spir-v backend the power to emit enum types. These are simply lowered to their backing integer type.
2023-04-09spirv: allow more calling conventionsRobin Voetter
This allows the Zig calling convention and makes way for a Kernel calling convention in the future. Any future checks on calling conventions should be placed in Sema.zig.
2023-04-07cbe: assert there are no unfreed localsJacob Young
Also fix the many revealed bugs.
2023-04-07Liveness: defer deaths of externally-scoped instructions in loop bodiesmlugg
2023-04-05Merge remote-tracking branch 'origin/master' into llvm16Andrew Kelley
2023-04-05compiler_rt: attempt to fix f16 abi on mac with llvm 16Jacob Young
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-21CBE: implement aggregateInit() for array of array case.Xavier Bouchoux
fixes `error(compilation): clang failed with stderr: error: array type 'uint32_t[10]' (aka 'unsigned int[10]') is not assignable`
2023-03-21llvm: fix lowering packed union initiated to zero-bit valueVeikka Tuominen
Closes #14980