1417 Commits

Author SHA1 Message Date
Jacob Young
3506bc61b7 llvm: update data layout computation to LLVM 17 2023-09-19 09:37:32 -07:00
Jacob Young
cad594372e llvm: update address space definitions to LLVM 17 2023-09-19 09:37:32 -07:00
Jacob Young
05e01301b0 Builder: further constant select cleanup 2023-09-19 09:37:32 -07:00
Andrew Kelley
6a07b7024a LLVM: update backend to LLVM 17
* LLVMConstSelect is removed (see
   https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179)
 * a couple functions use uint64_t instead of int now which means we
   no longer need `@intCast`.

release/17.x branch, commit 8f4dd44097c9ae25dd203d5ac87f3b48f854bba8
2023-09-19 09:37:31 -07:00
Andrew Kelley
62a12e0631 LLVM 17 std lib updates and fixes
* some manual fixes to generated CPU features code. in the future it
   would be nice to make the script do those automatically. I suspect
   the sm_90a thing is a bug in LLVM.
 * add liteos to various target OS switches. I know nothing about this
   OS; someone will need to work specifically on support for this OS
   when the time comes to support it properly in zig.
 * while waiting for the compiler, I went ahead and made more
   conservative choices about when to use `inline` in std/Target.zig
2023-09-19 09:37:31 -07:00
Andrew Kelley
cd8234c3ba update for LLVM 17 new target data
New OSs:
* UEFI
* LiteOS

New ABI:
* OpenHOS

Also update the LLD driver API wrappers.
2023-09-19 09:37:30 -07:00
Andrew Kelley
c970dbdfec LLVM: cache LLVM struct field indexes
This is an optimization to avoid O(N) field index lookups. It's also
nicer in terms of DRY; the only tradeoff is memory usage.
2023-09-18 00:09:30 -07:00
Andrew Kelley
cb6201715a InternPool: prevent anon struct UAF bugs with type safety
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-09-12 20:08:56 -04:00
Jacob Young
c429bb5d2f llvm/cbe: support slice in @prefetch
Closes #16967
2023-08-28 19:04:53 -07:00
Andrew Kelley
ada0010471 compiler: move unions into InternPool
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-08-22 13:54:14 -07:00
Jacob Young
4ac20f69ac Revert "llvm: fix bootstrap"
This reverts commit ea72fea1a4e2bc8309c211308f49f7f2c38507be.
2023-08-20 12:40:34 -07:00
mlugg
7a85ad151d cbe: elide block result allocation for 0-bit types
This logic already existed for the void type, but is also necessary for
other 0-bit types. Without it, we try to alloc a local for a 0-bit type
which gets translated to a local of type `void` which C doesn't like.
2023-08-20 11:58:14 -07:00
Lewis Gaul
387b0ac4f1
Make NaNs quiet by default and other NaN tidy-up (#16826)
* Generalise NaN handling and make std.math.nan() give quiet NaNs

* Address uses of std.math.qnan_* and std.math.nan_* consts

* Comment out failing test due to issues with signalling NaN

* Fix issue in c_builtins.zig where we need qnan_u32
2023-08-18 02:07:49 -04:00
Andrew Kelley
7ef1eb1c27 InternPool: safer enum API
The key changes in this commit are:

```diff
-        names: []const NullTerminatedString,
+        names: NullTerminatedString.Slice,
-        values: []const Index,
+        values: Index.Slice,
```

Which eliminates the slices from `InternPool.Key.EnumType` and replaces
them with structs that contain `start` and `len` indexes. This makes the
lifetime of `EnumType` change from expiring with updates to InternPool,
to expiring when the InternPool is garbage-collected, which is currently
never.

This is gearing up for a larger change I started working on locally
which moves union types into InternPool.

As a bonus, I fixed some unnecessary instances of `@as`.
2023-08-17 18:16:03 -07:00
mlugg
083ee8e0e2
InternPool: preserve indices of builtin types when resolved
Some builtin types have a special InternPool index (e.g.
`.type_info_type`) so that AstGen can refer to them before semantic
analysis. Unfortunately, this previously led to a second index existing
to refer to the type once it was resolved, complicating Sema by having
the concept of an "unresolved" type index.

This change makes Sema modify these InternPool indices in-place to
contain the expanded representation when resolved. The analysis of the
corresponding decls is caught in `Module.semaDecl`, and a field is set
on Sema telling it which index to place struct/union/enum types at. This
system could break if `std.builtin` contained complex decls which
evaluate multiple struct types, but this will be caught by the
assertions in `InternPool.resolveBuiltinType`.

The AstGen result types which were disabled in 6917a8c have been
re-enabled.

Resolves: #16603
2023-08-15 11:45:23 +01:00
Jacob Young
1c5c3f499a cmake: fix auto-detection of various host targets
Closes #16800
2023-08-13 11:26:10 -07:00
Jacob Young
c4848694d2 llvm: enable even without libllvm linked 2023-08-09 05:47:13 -04:00
Jacob Young
3e1dd93bb2 llvm: force strip without libllvm to avoid unimplemented behavior
Also fix deinit bugs.
2023-08-08 23:32:40 -04:00
Jacob Young
53bea0f7e4 llvm: remove dependence on llvm data layout alignment
by just using the zig alignment and letting llvm promote it as desired
2023-08-08 22:09:44 -04:00
Jacob Young
35cd56a369 llvm: fix alias issues 2023-08-08 21:32:50 -04:00
Jacob Young
2bdd180c6f llvm: finish converting globals 2023-08-08 21:32:50 -04:00
Jacob Young
2499d8fb73 Builder: fix enough bugs to pass the behavior tests
without using any information from the LLVM API
2023-08-08 21:32:50 -04:00
Jacob Young
a66cd54f94 llvm: cleanup even more unused LLVM API bindings 2023-08-08 21:32:50 -04:00
Jacob Young
a0cb03ed99 llvm: finish converting instructions 2023-08-08 21:32:50 -04:00
Jacob Young
49cc1bff08 llvm: finish converting intrinsics 2023-08-08 21:32:50 -04:00
Jacob Young
6577f52614 llvm: convert vector reduction intrinsics
Scratch that thing I said about one pass. :)
2023-08-08 21:32:50 -04:00
Jacob Young
e1efd4d3c2 Builder: simplify intrinsic table
This format removes back-references allowing it to be parsed in a single
pass.  It also reduces the number of kinds, simplifying the code.
2023-08-08 21:32:50 -04:00
Jacob Young
5b79f08ee8 llvm: finish converting attributes to use Builder and the C LLVM API 2023-08-08 21:32:50 -04:00
Jacob Young
b63d9745b5 llvm: convert intrinsics to using Builder 2023-08-08 21:32:50 -04:00
Jacob Young
3ebf8ce970 Builder: fix builtin pseudo-instruction dumping 2023-08-08 21:32:50 -04:00
Jacob Young
f938404a45 Builder: fix attribute spacing 2023-08-08 21:32:50 -04:00
Jacob Young
1c7798a3cd
Merge pull request #16705 from antlilja/builder-intrinsics
Implement more intrinsics in new LLVM IR builder API and remove uses of LLVM owns API
2023-08-05 23:05:02 -04:00
Robin Voetter
68f84964b3 llvm: add const addrspace cast 2023-08-05 17:11:57 -07:00
antlilja
e149f1e1de
Use new LLVM IR builder API in bit op lowering 2023-08-06 01:46:57 +02:00
antlilja
86f61a9d26
Implement bitop intrinsics in new LLVM IR builder
* llvm.bitreverse
* llvm.bswap
* llvm.ctpop
* llvm.ctlz
* llvm.cttz
2023-08-06 01:46:57 +02:00
antlilja
2b4ac7c6b3
Use new LLVM builder API in buildFloatOP 2023-08-06 01:46:56 +02:00
antlilja
63dcffdf9f
Implement fp intrinsics in new LLVM IR builder
Intrinsics implemented
* llvm.ceil
* llvm.cos
* llvm.exp
* llvm.exp2
* llvm.fabs
* llvm.floor
* llvm.log
* llvm.log10
* llvm.log2
* llvm.round
* llvm.sin
* llvm.trunc
* llvm.fma
2023-08-06 01:46:51 +02:00
Jacob Young
b8c9d5ae98 cbe: don't emit traps in naked functions
Closes #16680
2023-08-05 16:44:56 -07:00
Jacob Young
9e0a34f329 llvm: fix data layout calculation for experimental llvm targets
Closes #16616
2023-08-01 19:20:22 -07:00
Jacob Young
228c956377 std: finish cleanup up asm
This also required implementing the necessary syntax in the x86_64 backend.
2023-07-31 03:49:21 -04:00
Jacob Young
817fa3af86 std: cleanup asm usage
After fixing some issues with inline assembly in the C backend, the std
cleanups have the side effect of making these functions compatible with
the backend, allowing it to be used on linux without linking libc.
2023-07-31 01:58:10 -04:00
Jacob Young
6f0a613b6f
Merge pull request #16611 from xxxbxxx/packed-struct
codegen: fix various packed struct issues

Closes #16609
Closes #15337
2023-07-29 23:49:14 -04:00
Jacob Young
dc8a80a191 llvm: support read-write output constraints in assembly
Closes #15227
2023-07-29 09:49:04 -07:00
Xavier Bouchoux
8c367ef99a codegen: fix access to byte-aligned nested packed struct elems
When acessing a packed struct member via a byte aligned ptr (from the optimisation in Sema.structFieldPtrByIndex())
the codegen must apply the parent ptr packed_offset in addition to the field offset itself.

resolves https://github.com/ziglang/zig/issues/16609
2023-07-29 18:16:13 +02:00
Xavier Bouchoux
46abf20454 llvm: partial fix of store undefined to packed result location
prefer marking too few undefined bits, rather than too many that may overwrite nearby values.
partially resolves https://github.com/ziglang/zig/issues/15337
2023-07-29 11:56:27 +02:00
Jacob Young
125b453c58 llvm: fix SysV C abi for structs smaller than two eightbytes
Closes #16038
Closes #16288
2023-07-28 19:27:08 -04:00
Andrew Kelley
0f21d3d4d1 LLVM: always add argument attributes to calls
These are needed for correctness. There's no reason to only add them for
function pointers.

closes #16290
2023-07-27 00:49:25 -07:00
Jacob Young
f9717f87f5 llvm: fix data layout on ios
Closes #16549
2023-07-26 16:49:32 -07:00
Andrew Kelley
6cee98eb30 frontend: forbid packed and extern tuples 2023-07-25 21:45:33 -07:00
Xavier Bouchoux
5ab1854602 codegen/llvm: fix memset with vectors smaller than one byte
The special case to take advantage of llvm's intrinsic
was generating invalid llvm ir:

```
Invalid bitcast
  %60 = bitcast <2 x i2> %59 to i8, !dbg !3122
thread 145453 panic: LLVM module verification failed
```
2023-07-25 18:14:10 -07:00