aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
AgeCommit message (Collapse)Author
2022-04-02stage2 llvm: properly align error union payloadVeikka Tuominen
2022-03-31stage2: handle assembly input namesVeikka Tuominen
2022-03-30CBE: improve support for asm inputsDaniele Cocca
This is not complete support for asm expressions, but allows a few more test cases from test/behavior/asm.zig to pass. Since the non-register inputs are named `input_${n}` they can cause name collisions: I'm wrapping the asm expressions in their own block to prevent that. Contextually, this change also makes test/behavior/asm.zig run for stage2, but skips individual tests for most backends (I only verified the C and LLVM backends successfully run one new test case) and the entire test file for aarch64, where it's running into preexisting shortcomings.
2022-03-29stage2: implement `@intToError` with safetyAndrew Kelley
This commit introduces a new AIR instruction `cmp_lt_errors_len`. It's specific to this use case for two reasons: * The total number of errors is not stable during semantic analysis; it can only be reliably checked when flush() is called. So the backend that is lowering the instruction must emit a relocation of some kind and then populate it during flush(). * The fewer AIR instructions in memory, the better for compiler performance, so we squish complex meanings into AIR tags without hesitation. The instruction is implemented only in the LLVM backend so far. It does this by creating a simple function which is gutted and re-populated with each flush(). AstGen now uses ResultLoc.coerced_ty for `@intToError` and Sema does the coercion.
2022-03-29CBE: fix C output after PR #11302, reenable testsDaniele Cocca
Commit 052079c99455d01312d377d72fa1b8b5c0b22aad surfaced two issues with the generated C code: - renderInt128() contained a seemingly unnecessary assertion to verify that the high 64 bits of the number were nonzero, dating back to 9bf1681990fe87a6b2e5fc644a89f1aece304579. I removed it. - renderValue() didn't have any special handling for undefined structs, falling back to printing "{}" which generated invalid expressions such as "return {}" for functions returning structs, whereas "return (S){}" is the correct form. I changed it accordingly. At the same time I'm reenabling the relevant tests.
2022-03-28stage2: finish debug info for unions in the LLVM backendAndrew Kelley
Sema: * queue full resolution of std.builtin.Type.Error when doing `@typeInfo` for error sets. LLVM backend: * change a TODO comment to a proper explanation of why debug info for structs is left as a fwd decl sometimes. * remove handling of packed unions which does not match the type information or constant generation code. * remove copy+pasted code * fix union debug info not matching the memory layout * remove unnecessary error checks and type casting
2022-03-28stage2: LLVM: (WIP) add union fields debug infoJohn Schmidt
2022-03-28stage2 llvm: fix union init of byRef valuesVeikka Tuominen
2022-03-27LLVM: handle aggregate_init for packed structsAndrew Kelley
2022-03-26stage2: simplify `scalar_ty` for `mul_add` in LLVM backendWilliam Sengir
2022-03-26stage2 LLVM: Adjust to new AIR arithmetic overflow instructionsjoachimschmidt557
2022-03-25sema: use `pl_op` for `@select`John Schmidt
2022-03-25stage2: implement `@select`John Schmidt
2022-03-23stage2 CBE: Improve support for unions and error setsCody Tapscott
This includes various fixes/improvements to the C backend to improve error/union support. It also fixes up our handling of decls, where some decls were not correctly marked alive.
2022-03-22stage2: lazy `@alignOf`Andrew Kelley
Add a `target` parameter to every function that deals with Type and Value.
2022-03-21stage2: align store for vector-to-array bitcast in LLVM backendWilliam Sengir
This was causing a very rare segfault when LLVM would emit `vmovdqa` using an unaligned memory operand on the stack.
2022-03-21stage2: make more instructions vector-compatible in LLVM backendWilliam Sengir
2022-03-21stage2: implement `cmp_vector` for LLVM backendWilliam Sengir
2022-03-21stage2: add AIR instruction `cmp_vector`William Sengir
The existing `cmp_*` instructions get their result type from `lhs`, but vector comparison will always return a vector of bools with only the length derived from its operands. This necessitates the creation of a new AIR instruction.
2022-03-21Merge pull request #11253 from Vexu/pretty-print-valuesAndrew Kelley
stage2: print values with types
2022-03-21stage2 llvm: fix lowerDeclRefValue for function aliasesVeikka Tuominen
2022-03-21stage2: add way to print values with typesVeikka Tuominen
2022-03-20stage2: remove Value.Tag.abi_align_defaultAndrew Kelley
and make Decl alignment & linksection, and struct & union field alignment be scalar values, not Value values. YAGNI
2022-03-19CBE: implement mod, divFloor, divTruncDaniele Cocca
2022-03-19stage2: add dbg_block_{begin,end} instructionVeikka Tuominen
2022-03-18CBE: add support for tuplesDaniele Cocca
Also promote tests that are now passing.
2022-03-17Implement `@byteSwap` for vectorsJohn Schmidt
Make the behavior tests for this a little more primitive to exercise as little extra functionality as possible.
2022-03-17stage2: implement `@reduce`Andrew Kelley
Notably, Value.eql and Value.hash are improved to treat NaN as equal to itself, so that Type/Value can be hash map keys. Likewise float hashing normalizes the float value before computing the hash.
2022-03-17stage2: prevent UB in the LLVM backendAndrew Kelley
* Sema: fix `zirTypeInfo` allocating with the wrong arenas for some stuff. * LLVM: split `airDbgInline` into two functions, one for each AIR tag. - remove the redundant copy to type_map_arena. This is the first thing that lowerDebugType does so this hack was probably just accidentally avoiding UB (which is still present prior to this commit). - don't store an inline fn inst into the di_map for the generic decl. - use a dummy function type for the debug info to avoid whatever UB is happening. - we are now ignoring the function type passed in with the dbg_inline_begin and dbg_inline_end. * behavior tests: prepare the vector tests to be enabled one at a time. Mitigates #11199.
2022-03-16Implement `@mulAdd` for vectorsJohn Schmidt
2022-03-16CBE: better handling of sentineled slices/arraysDaniele Cocca
Adds the sentinel element to the type name to avoid ambiguous declarations, and outputs the sentinel element (if needed) even in what would otherwise be empty arrays.
2022-03-16LLVM: fix slice debug info and functionsAndrew Kelley
with return types that have no runtime bits
2022-03-16LLVM: make the load function copy isByRef=true typesAndrew Kelley
2022-03-16stage2 llvm: keep track of inlined functionsVeikka Tuominen
2022-03-16Sema: emit dbg_func around inline callsVeikka Tuominen
2022-03-16LLVM: fix LLVM assertion when slicingAndrew Kelley
2022-03-16LLVM: implement debug info for structsAndrew Kelley
This involved some significant reworking in order to introduce the concept of "forward declarations" to the system to break dependency loops. The `lowerDebugType` function now takes an `enum { full, fwd }` and is moved from `DeclGen` to `Object` so that it can be called from `flushModule`. `DITypeMap` is now an `ArrayHashMap` instead of a `HashMap` so that we can iterate over the entries in `flushModule` and finalize the forward decl DITypes into full DITypes. `DITypeMap` now stores `AnnotatedDITypePtr` values instead of `*DIType` values. This is an abstraction around a `usize` which assumes the pointers will be at least 2 bytes aligned and uses the least significant bit to store whether it is forward decl or a fully resolved debug info type. `lowerDebugTypeImpl` is extracted out from `lowerDebugType` and it has a mechanism for completing a forward decl DIType to a fully resolved one. The function now contains lowering for struct types. Closes #11095. There is a workaround for struct types which have not had `resolveFieldTypes` called in Sema, even by the time `flushModule` is called. This is a deficiency of Sema that should be addressed, and the workaround removed. I think Sema needs a new mechanism to queue up type resolution work instead of doing it in-line, so that it does not cause false dependency loops. We already have one failing behavior test because of a false dependency loop.
2022-03-16stage2 llvm: fix `@extern`Veikka Tuominen
2022-03-15stage2: Fix panic on initializing comptime fields in tupleCody Tapscott
This resolves https://github.com/ziglang/zig/issues/11159 The problem was that: 1. We were not correctly deleting the field stores after recognizing that an array initializer was a comptime-known value. 2. LLVM was not checking that the final type had no runtime bits, and so would generate an invalid store. This also adds several test cases for related bugs, just to check these in for later work.
2022-03-15CBE: fix output of airMinMax()Daniele Cocca
This was trying to output a ternary operator, but the output was broken by the lack of a '?'.
2022-03-14LLVM: clean up airUnaryOp to call callFloatUnaryAndrew Kelley
and make callFloatUnary support vectors. I tried to make it use getIntrinsic, but that resulted in tripping `assert(id != 0)`.
2022-03-14stage2: fixups for topolarity-comptime-memory-reinterp branchAndrew Kelley
* don't store `has_well_defined_layout` in memory. * remove struct `hasWellDefinedLayout` logic. it's just `layout != .Auto`. This means we only need one implementation, in Type. * fix some of the cases being wrong in `hasWellDefinedLayout`, such as optional pointers. * move `tag_ty_inferred` field into a position that makes it more obvious how the struct layout will be done. Also we don't have a compiler that intelligently moves fields around so this layout is better. * Sema: don't `resolveTypeLayout` in `zirCoerceResultPtr` unless necessary. * Rename `ComptimePtrLoadKit` `target` field to `pointee` to avoid confusion with `target`.
2022-03-14stage2 llvm: Respect container type when lowering parent pointersCody Tapscott
We need to make sure that we bitcast our pointers correctly before we use get_element_ptr to compute the offset for the parent pointer. This also includes a small fix-up for a problem where ptrs to const i64/u64 were not using the correct type in >1-level decl chains (where we call lowerParentPtr recursively)
2022-03-14stage2: Add container_ty/elem_ty to elem_ptr, field_ptr, *_payload_ptr ValuesCody Tapscott
2022-03-15Merge pull request #11167 from mitchellh/codegen-arraysAndrew Kelley
stage2: codegen of arrays should use type length, not value length
2022-03-15stage2: add debug info for globals in the LLVM backendWilliam Sengir
LLVM backend: generate DIGlobalVariable's for non-function globals and rename linkage names when exporting functions and globals. zig_llvm.cpp: add some wrappers to convert a handful of DI classes into DINode's since DIGlobalVariable is not a DIScope like the others. zig_llvm.cpp: add some wrappers to allow replacing the LinkageName of DISubprogram and DIGlobalVariable. zig_llvm.cpp: fix DI class mixup causing nonsense reinterpret_cast. The end result is that GDB is now usable since you now no longer need to manually cast every global nor fully qualify every export.
2022-03-14stage2: LLVM codegen of arrays should use type length, not value lengthMitchell Hashimoto
It is possible for the value length to be longer than the type because we allow in-memory coercing of types such as `[5:0]u8` to `[5]u8`. In such a case, the value length is 6 but the type length if 5. The `.repeated` value type already got this right, so this is extending similar logic out to `.aggregate` and `.bytes`. Both scenarios are tested in behavior tests. Fixes #11165
2022-03-14Merge pull request #11143 from jmc-88/cbeAndrew Kelley
CBE: Implement popCount, byteSwap, bitReverse for ints <= 128 bits
2022-03-14CBE: split {clz,ctz,mod,popCount,byteSwap,bitReverse} by typeDaniele Cocca
This also surfaces the fact that clz, ctz and popCount didn't actually support 128 bit integers, despite what was claimed by 226fcd7c709ec664c5d883042cf7beb3026f66cb. This was partially hidden by the fact that the test code for popCount only exercised 128 bit integers in a comptime context. This commit duplicates that test case for runtime ints too.
2022-03-14stage2: rework Value storage of structs and arraysAndrew Kelley
Now they both use `Value.Tag.aggregate`. Additionally the LLVM backend now has implemented lowering of tuple values.