aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
2024-04-06spirv: remove cache usage for constantsRobin Voetter
2024-04-06spirv: id range helperRobin Voetter
This allows us to more sanely allocate a continuous range of result-ids, and avoids a bunch of nasty casting code in a few places. Its currently not used very often, but will be useful in the future.
2024-04-06spirv: implement `@mulWithOverflow`Ali Chraghi
2024-04-06spirv: OpExtInstImport in assemblerAli Chraghi
2024-04-06spirv: implement `@divFloor`, `@floor` and `@mod`Ali Chraghi
2024-04-05spirv: make behavior tests passingAli Chraghi
2024-04-01Merge pull request #19490 from Snektron/spirv-dedupRobin Voetter
spirv: deduplication pass
2024-03-30cbe: fix uncovered bugsJacob Young
2024-03-30cbe: rewrite `CType`Jacob Young
Closes #14904
2024-03-30cbe: fix bugs revealed by an upcoming commitJacob Young
Closes #18023
2024-03-30spirv: clz, ctz for openclRobin Voetter
This instruction seems common in compiler_rt.
2024-03-26compiler: eliminate TypedValuemlugg
The only logic which remained in this file was the Value printing logic. This has been moved into a new `print_value.zig`.
2024-03-26compiler: eliminate most usages of TypedValuemlugg
2024-03-26Zcu.Decl: replace `typedValue` with `valueOrFail`mlugg
Now that the legacy `Value` representation is eliminated, we can begin to phase out the redundant `TypedValue` type.
2024-03-26Zcu: eliminate `Decl.alive` fieldmlugg
Legacy anon decls now have three uses: * Type owner decls * Function owner decls * `@export` and `@extern` Therefore, there are no longer any cases where we wish to explicitly omit legacy anon decls from the binary. This means we can remove the concept of an "alive" vs "dead" `Decl`, which also allows us to remove the separate `anon_work_queue` in `Compilation`.
2024-03-26compiler: eliminate legacy Value representationmlugg
Good riddance! Most of these changes are trivial. There's a fix for a minor bug this exposed in `Value.readFromPackedMemory`, but aside from that, it's all just things like changing `intern` calls to `toIntern`.
2024-03-26Zcu.Decl: remove `ty` fieldmlugg
`Decl` can no longer store un-interned values, so this field is now unnecessary. The type can instead be fetched with the new `typeOf` helper method, which just gets the type of the Decl's `Value`.
2024-03-25Merge pull request #19414 from mlugg/comptime-mutable-memory-yet-againAndrew Kelley
compiler: implement analysis-local comptime-mutable memory
2024-03-25llvm: update current debug location scope when entering debug scopemlugg
This issue was causing debug information to sometimes not function correctly for some local variables, with debuggers simply reporting that the variable does not exist. What was happening was that after an AIR body - and thus debug lexical scope - begins, but before any `dbg_stmt` within it, the `scope` on `self.wip.debug_location` refers to the parent scope, but the `scope` field on the `DILocalVariable` metadata passed to `@llvm.dbg.declare` points, correctly, to the nested scope. I haven't looked into precisely what happens here, but in short, it would appear that LLVM Doesn't Like It (tm). The fix is simple: when we change `self.scope` at the start or end of an AIR body, also modify the scope on `self.wip.debug_location`. This is correct as we always want the debug info for an instruction to be associated with the block it is within, even if the line/column are slightly outdated for any reason.
2024-03-25compiler: implement analysis-local comptime-mutable memorymlugg
This commit changes how we represent comptime-mutable memory (`comptime var`) in the compiler in order to implement the intended behavior that references to such memory can only exist at comptime. It does *not* clean up the representation of mutable values, improve the representation of comptime-known pointers, or fix the many bugs in the comptime pointer access code. These will be future enhancements. Comptime memory lives for the duration of a single Sema, and is not permitted to escape that one analysis, either by becoming runtime-known or by becoming comptime-known to other analyses. These restrictions mean that we can represent comptime allocations not via Decl, but with state local to Sema - specifically, the new `Sema.comptime_allocs` field. All comptime-mutable allocations, as well as any comptime-known const allocs containing references to such memory, live in here. This allows for relatively fast checking of whether a value references any comptime-mtuable memory, since we need only traverse values up to pointers: pointers to Decls can never reference comptime-mutable memory, and pointers into `Sema.comptime_allocs` always do. This change exposed some faulty pointer access logic in `Value.zig`. I've fixed the important cases, but there are some TODOs I've put in which are definitely possible to hit with sufficiently esoteric code. I plan to resolve these by auditing all direct accesses to pointers (most of them ought to use Sema to perform the pointer access!), but for now this is sufficient for all realistic code and to get tests passing. This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema arena for comptime memory mutations, which is possible since comptime memory is now local to the current Sema. This change should allow `Decl` to store only an `InternPool.Index` rather than a full-blown `ty: Type, val: Value`. This commit does not perform this refactor.
2024-03-19Merge pull request #19337 from Snektron/spirv-globalsRobin Voetter
spirv: rework generic global
2024-03-18spirv: fix optional comparisonRobin Voetter
2024-03-18spirv: make generic globals invocation-localRobin Voetter
2024-03-18spirv: add zig-specific ext instRobin Voetter
This may be removed again in the future...
2024-03-18spirv: make IdResult an enumRobin Voetter
2024-03-18spirv: update assembler with new specRobin Voetter
2024-03-18spirv: update spec to SPIRV-Headers/8b246ffRobin Voetter
We need this "unstable" version to get the Zig identifiers.
2024-03-18Merge pull request #19334 from antlilja/llvm-fast-mathVeikka Tuominen
Fix setFloatMode in LLVM backend
2024-03-17cbe: rework StringLiteral to decide between string literal or array ↵kcbanner
initializator syntax This fixes an issue with boostrapping the compiler using MSVC. There is a CircularBuffer with an array of length 65536 initialized to undefined, and because the undefined path of `renderValue` was using `StringLiteral` to render this, the resulting zig2.c would fail to compile using MSVC. The solution was to move the already-existing array initializer path (used in the non-undefined path) into StringLiteral, and make StringLiteral aware of the total length so it could decide between which style of initialization to use. We prefer to use string literals if we can, as this results in the least amount of emitted C source.
2024-03-17Merge pull request #19333 from Vexu/fixesAndrew Kelley
Miscellaneous error fixes
2024-03-17Merge pull request #19323 from jacobly0/rm-fn-type-alignAndrew Kelley
AstGen: disallow alignment on function types
2024-03-17LLVM: Use fast math when requestedantlilja
2024-03-17LLVM: Fix incorrect fast constant in FastMath packed structantlilja
2024-03-17LLVM: Fix reaching unreachable code when emitting fast callantlilja
2024-03-17Revert "spirv: merge `construct(Struct/Vector/Array)` into `constructComposite`"Robin Voetter
This reverts commit eb2d61d02e503f01070c05e2e1fc87e827124d94.
2024-03-17Sema: fix spurious type has no namespace errorVeikka Tuominen
Closes #19232
2024-03-17LLVM lowerDebugType: Lower union types without a layout into an empty namespaceAnton Lilja
2024-03-17AstGen: disallow alignment on function typesJacob Young
A pointer type already has an alignment, so this information does not need to be duplicated on the function type. This already has precedence with addrspace which is already disallowed on function types for this reason. Also fixes `@TypeOf(&func)` to have the correct addrspace and alignment.
2024-03-11std.builtin: make atomic order fields lowercaseTristan Ross
2024-03-11std.builtin: make global linkage fields lowercaseTristan Ross
2024-03-11std.builtin: make container layout fields lowercaseTristan Ross
2024-03-06Fix incorrectly resolved merge conflictsmlugg
To be honest, I can't be bothered to figure out which commits these changes should be in.
2024-03-06compiler: namespace type equivalence based on AST node + capturesmlugg
This implements the accepted proposal #18816. Namespace-owning types (struct, enum, union, opaque) are no longer unique whenever analysed; instead, their identity is determined based on their AST node and the set of values they capture. Reified types (`@Type`) are deduplicated based on the structure of the type created. For instance, if two structs are created by the same reification with identical fields, layout, etc, they will be the same type. This commit does not produce a working compiler; the next commit, adding captures for decl references, is necessary. It felt appropriate to split this up. Resolves: #18816
2024-03-06InternPool: create specialized functions for loading namespace typesmlugg
Namespace types (`struct`, `enum`, `union`, `opaque`) do not use structural equality - equivalence is based on their Decl index (and soon will change to AST node + captures). However, we previously stored all other information in the corresponding `InternPool.Key` anyway. For logical consistency, it makes sense to have the key only be the true key (that is, the Decl index) and to load all other data through another function. This introduces those functions, by the name of `loadStructType` etc. It's a big diff, but most of it is no-brainer changes. In future, it might be nice to eliminate a bunch of the loaded state in favour of accessor functions on the `LoadedXyzType` types (like how we have `LoadedUnionType.size()`), but that can be explored at a later date.
2024-03-02Merge pull request #19152 from antlilja/llvm-broken-debugAndrew Kelley
LLVM: Fail to emit if LLVM encounters broken debug info
2024-03-02Air: replace `.dbg_inline_*` with `.dbg_inline_block`Jacob Young
This prevents the possibility of not emitting a `.dbg_inline_end` instruction and reduces the allocation requirements of the backends. Closes #19093
2024-03-02LLVM: Fail to emit if LLVM encounters broken debug infoantlilja
2024-03-02LLVM: Add enableBrokenDebugInfoCheck and getBrokenDebugInfoantlilja
These functions allows the caller to find out wether the context encounters broken debug info or not.
2024-02-29codegen: handle dbg_var scoping correctly after eliding more ZIR blocksmlugg
Since we now elide more ZIR blocks in AstGen, care must be taken in codegen to introduce lexical scopes for every body, not just `block`s. Also, elide a few unnecessary AIR blocks in Sema.
2024-02-29LLVM Builder: Fix emission of enum debug enumerator info bitcodeantlilja