aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
AgeCommit message (Collapse)Author
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-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-19stage2: add dbg_block_{begin,end} instructionVeikka Tuominen
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-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-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-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.
2022-03-14LLVM: fix int_to_float signedness detectionAndrew Kelley
It was checking if the result (float) type was a signed int rather than checking the operand (integer) type.
2022-03-14LLVM: fix debug info for local varsAndrew Kelley
Previously we incorrectly used the pointer type as the debug info type.
2022-03-13stage2: add debug info for locals in the LLVM backendAndrew Kelley
Adds 2 new AIR instructions: * dbg_var_ptr * dbg_var_val Sema no longer emits dbg_stmt AIR instructions when strip=true. LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on the element type is problematic. LLVM backend: fixed alloca instructions improperly getting debug location annotated, causing chaotic debug info behavior. zig_llvm.cpp: fixed incorrect bindings for a function that should use unsigned integers for line and column. A bunch of C test cases regressed because the new dbg_var AIR instructions caused their operands to be alive, exposing latent bugs. Mostly it's just a problem that the C backend lowers mutable and const slices to the same C type, so we need to represent that in the C backend instead of printing two duplicate typedefs.
2022-03-12stage2 llvm: do not use getIntrinsic for airFrameAddressVeikka Tuominen
getIntrinsic gets the return type wrong so we have to add the function manually
2022-03-11LLVM: use hasRuntimeBitsIgnoreComptime instead of hasRuntimeBitsAndrew Kelley
LLVM codegen doesn't care whether types are comptime or not. Comptime types aren't supposed to make it to codegen anyway.
2022-03-11LLVM: fix debug info for pointers to voidAndrew Kelley
2022-03-11stage2: implement `@shuffle` at runtimeVeikka Tuominen
2022-03-11stage2: passing threadlocal tests for x86_64-linuxAndrew Kelley
* use the real start code for LLVM backend with x86_64-linux - there is still a check for zig_backend after initializing the TLS area to skip some stuff. * introduce new AIR instructions and implement them for the LLVM backend. They are the same as `call` except with a modifier. - call_always_tail - call_never_tail - call_never_inline * LLVM backend calls hasRuntimeBitsIgnoringComptime in more places to avoid unnecessarily depending on comptimeOnly being resolved for some types. * LLVM backend: remove duplicate code for setting linkage and value name. The canonical place for this is in `updateDeclExports`. * LLVM backend: do some assembly template massaging to make `%%` rendered as `%`. More hacks will be needed to make inline assembly catch up with stage1.
2022-03-10stage2 llvm: implement lowerParentPtr for int_{u,i}64Veikka Tuominen
2022-03-09Sema: implement pointer to tuple to pointer to array coercionAndrew Kelley
This involved an LLVM backend fix for the aggregate_init instruction.
2022-03-08LLVM: fix memory leak of debug type namesAndrew Kelley
This required adjusting `Type.nameAlloc` to be used with a general-purpose allocator and added `Type.nameAllocArena` for the arena use case (avoids allocation sometimes).
2022-03-08LLVM: add debug info for opaque, vector, and tuplesAndrew Kelley
Also fix UAF of Type memory in the di_type_map.
2022-03-08LLVM: no longer store args into alloca instructionsAndrew Kelley
Previously, we did this so that we could insert a debug variable declaration intrinsic on the alloca. But there is a dbg.value intrinsic for declaring variables that are values.